|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2023 the original author or authors. |
|
|
|
* Copyright 2002-2024 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -37,167 +37,168 @@ import static org.mockito.Mockito.mock; |
|
|
|
/** |
|
|
|
/** |
|
|
|
* @author Thomas Risberg |
|
|
|
* @author Thomas Risberg |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class ResultSetWrappingRowSetTests { |
|
|
|
class ResultSetWrappingRowSetTests { |
|
|
|
|
|
|
|
|
|
|
|
private ResultSet resultSet = mock(); |
|
|
|
private final ResultSet resultSet = mock(); |
|
|
|
|
|
|
|
|
|
|
|
private ResultSetWrappingSqlRowSet rowSet = new ResultSetWrappingSqlRowSet(resultSet); |
|
|
|
private final ResultSetWrappingSqlRowSet rowSet = new ResultSetWrappingSqlRowSet(resultSet); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testGetBigDecimalInt() throws Exception { |
|
|
|
void testGetBigDecimalInt() throws Exception { |
|
|
|
Method rset = ResultSet.class.getDeclaredMethod("getBigDecimal", int.class); |
|
|
|
Method rset = ResultSet.class.getDeclaredMethod("getBigDecimal", int.class); |
|
|
|
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getBigDecimal", int.class); |
|
|
|
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getBigDecimal", int.class); |
|
|
|
doTest(rset, rowset, 1, BigDecimal.ONE); |
|
|
|
doTest(rset, rowset, 1, BigDecimal.ONE); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testGetBigDecimalString() throws Exception { |
|
|
|
void testGetBigDecimalString() throws Exception { |
|
|
|
Method rset = ResultSet.class.getDeclaredMethod("getBigDecimal", int.class); |
|
|
|
Method rset = ResultSet.class.getDeclaredMethod("getBigDecimal", int.class); |
|
|
|
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getBigDecimal", String.class); |
|
|
|
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getBigDecimal", String.class); |
|
|
|
doTest(rset, rowset, "test", BigDecimal.ONE); |
|
|
|
doTest(rset, rowset, "test", BigDecimal.ONE); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testGetStringInt() throws Exception { |
|
|
|
void testGetStringInt() throws Exception { |
|
|
|
Method rset = ResultSet.class.getDeclaredMethod("getString", int.class); |
|
|
|
Method rset = ResultSet.class.getDeclaredMethod("getString", int.class); |
|
|
|
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getString", int.class); |
|
|
|
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getString", int.class); |
|
|
|
doTest(rset, rowset, 1, "test"); |
|
|
|
doTest(rset, rowset, 1, "test"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testGetStringString() throws Exception { |
|
|
|
void testGetStringString() throws Exception { |
|
|
|
Method rset = ResultSet.class.getDeclaredMethod("getString", int.class); |
|
|
|
Method rset = ResultSet.class.getDeclaredMethod("getString", int.class); |
|
|
|
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getString", String.class); |
|
|
|
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getString", String.class); |
|
|
|
doTest(rset, rowset, "test", "test"); |
|
|
|
doTest(rset, rowset, "test", "test"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testGetTimestampInt() throws Exception { |
|
|
|
void testGetTimestampInt() throws Exception { |
|
|
|
Method rset = ResultSet.class.getDeclaredMethod("getTimestamp", int.class); |
|
|
|
Method rset = ResultSet.class.getDeclaredMethod("getTimestamp", int.class); |
|
|
|
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getTimestamp", int.class); |
|
|
|
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getTimestamp", int.class); |
|
|
|
doTest(rset, rowset, 1, new Timestamp(1234L)); |
|
|
|
doTest(rset, rowset, 1, new Timestamp(1234L)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testGetTimestampString() throws Exception { |
|
|
|
void testGetTimestampString() throws Exception { |
|
|
|
Method rset = ResultSet.class.getDeclaredMethod("getTimestamp", int.class); |
|
|
|
Method rset = ResultSet.class.getDeclaredMethod("getTimestamp", int.class); |
|
|
|
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getTimestamp", String.class); |
|
|
|
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getTimestamp", String.class); |
|
|
|
doTest(rset, rowset, "test", new Timestamp(1234L)); |
|
|
|
doTest(rset, rowset, "test", new Timestamp(1234L)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testGetDateInt() throws Exception { |
|
|
|
void testGetDateInt() throws Exception { |
|
|
|
Method rset = ResultSet.class.getDeclaredMethod("getDate", int.class); |
|
|
|
Method rset = ResultSet.class.getDeclaredMethod("getDate", int.class); |
|
|
|
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getDate", int.class); |
|
|
|
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getDate", int.class); |
|
|
|
doTest(rset, rowset, 1, new Date(1234L)); |
|
|
|
doTest(rset, rowset, 1, new Date(1234L)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testGetDateString() throws Exception { |
|
|
|
void testGetDateString() throws Exception { |
|
|
|
Method rset = ResultSet.class.getDeclaredMethod("getDate", int.class); |
|
|
|
Method rset = ResultSet.class.getDeclaredMethod("getDate", int.class); |
|
|
|
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getDate", String.class); |
|
|
|
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getDate", String.class); |
|
|
|
doTest(rset, rowset, "test", new Date(1234L)); |
|
|
|
doTest(rset, rowset, "test", new Date(1234L)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testGetTimeInt() throws Exception { |
|
|
|
void testGetTimeInt() throws Exception { |
|
|
|
Method rset = ResultSet.class.getDeclaredMethod("getTime", int.class); |
|
|
|
Method rset = ResultSet.class.getDeclaredMethod("getTime", int.class); |
|
|
|
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getTime", int.class); |
|
|
|
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getTime", int.class); |
|
|
|
doTest(rset, rowset, 1, new Time(1234L)); |
|
|
|
doTest(rset, rowset, 1, new Time(1234L)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testGetTimeString() throws Exception { |
|
|
|
void testGetTimeString() throws Exception { |
|
|
|
Method rset = ResultSet.class.getDeclaredMethod("getTime", int.class); |
|
|
|
Method rset = ResultSet.class.getDeclaredMethod("getTime", int.class); |
|
|
|
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getTime", String.class); |
|
|
|
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getTime", String.class); |
|
|
|
doTest(rset, rowset, "test", new Time(1234L)); |
|
|
|
doTest(rset, rowset, "test", new Time(1234L)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testGetObjectInt() throws Exception { |
|
|
|
void testGetObjectInt() throws Exception { |
|
|
|
Method rset = ResultSet.class.getDeclaredMethod("getObject", int.class); |
|
|
|
Method rset = ResultSet.class.getDeclaredMethod("getObject", int.class); |
|
|
|
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getObject", int.class); |
|
|
|
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getObject", int.class); |
|
|
|
doTest(rset, rowset, 1, new Object()); |
|
|
|
doTest(rset, rowset, 1, new Object()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testGetObjectString() throws Exception { |
|
|
|
void testGetObjectString() throws Exception { |
|
|
|
Method rset = ResultSet.class.getDeclaredMethod("getObject", int.class); |
|
|
|
Method rset = ResultSet.class.getDeclaredMethod("getObject", int.class); |
|
|
|
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getObject", String.class); |
|
|
|
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getObject", String.class); |
|
|
|
doTest(rset, rowset, "test", new Object()); |
|
|
|
doTest(rset, rowset, "test", new Object()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testGetIntInt() throws Exception { |
|
|
|
void testGetIntInt() throws Exception { |
|
|
|
Method rset = ResultSet.class.getDeclaredMethod("getInt", int.class); |
|
|
|
Method rset = ResultSet.class.getDeclaredMethod("getInt", int.class); |
|
|
|
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getInt", int.class); |
|
|
|
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getInt", int.class); |
|
|
|
doTest(rset, rowset, 1, 1); |
|
|
|
doTest(rset, rowset, 1, 1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testGetIntString() throws Exception { |
|
|
|
void testGetIntString() throws Exception { |
|
|
|
Method rset = ResultSet.class.getDeclaredMethod("getInt", int.class); |
|
|
|
Method rset = ResultSet.class.getDeclaredMethod("getInt", int.class); |
|
|
|
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getInt", String.class); |
|
|
|
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getInt", String.class); |
|
|
|
doTest(rset, rowset, "test", 1); |
|
|
|
doTest(rset, rowset, "test", 1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testGetFloatInt() throws Exception { |
|
|
|
void testGetFloatInt() throws Exception { |
|
|
|
Method rset = ResultSet.class.getDeclaredMethod("getFloat", int.class); |
|
|
|
Method rset = ResultSet.class.getDeclaredMethod("getFloat", int.class); |
|
|
|
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getFloat", int.class); |
|
|
|
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getFloat", int.class); |
|
|
|
doTest(rset, rowset, 1, 1.0f); |
|
|
|
doTest(rset, rowset, 1, 1.0f); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testGetFloatString() throws Exception { |
|
|
|
void testGetFloatString() throws Exception { |
|
|
|
Method rset = ResultSet.class.getDeclaredMethod("getFloat", int.class); |
|
|
|
Method rset = ResultSet.class.getDeclaredMethod("getFloat", int.class); |
|
|
|
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getFloat", String.class); |
|
|
|
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getFloat", String.class); |
|
|
|
doTest(rset, rowset, "test", 1.0f); |
|
|
|
doTest(rset, rowset, "test", 1.0f); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testGetDoubleInt() throws Exception { |
|
|
|
void testGetDoubleInt() throws Exception { |
|
|
|
Method rset = ResultSet.class.getDeclaredMethod("getDouble", int.class); |
|
|
|
Method rset = ResultSet.class.getDeclaredMethod("getDouble", int.class); |
|
|
|
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getDouble", int.class); |
|
|
|
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getDouble", int.class); |
|
|
|
doTest(rset, rowset, 1, 1.0d); |
|
|
|
doTest(rset, rowset, 1, 1.0d); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testGetDoubleString() throws Exception { |
|
|
|
void testGetDoubleString() throws Exception { |
|
|
|
Method rset = ResultSet.class.getDeclaredMethod("getDouble", int.class); |
|
|
|
Method rset = ResultSet.class.getDeclaredMethod("getDouble", int.class); |
|
|
|
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getDouble", String.class); |
|
|
|
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getDouble", String.class); |
|
|
|
doTest(rset, rowset, "test", 1.0d); |
|
|
|
doTest(rset, rowset, "test", 1.0d); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testGetLongInt() throws Exception { |
|
|
|
void testGetLongInt() throws Exception { |
|
|
|
Method rset = ResultSet.class.getDeclaredMethod("getLong", int.class); |
|
|
|
Method rset = ResultSet.class.getDeclaredMethod("getLong", int.class); |
|
|
|
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getLong", int.class); |
|
|
|
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getLong", int.class); |
|
|
|
doTest(rset, rowset, 1, 1L); |
|
|
|
doTest(rset, rowset, 1, 1L); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testGetLongString() throws Exception { |
|
|
|
void testGetLongString() throws Exception { |
|
|
|
Method rset = ResultSet.class.getDeclaredMethod("getLong", int.class); |
|
|
|
Method rset = ResultSet.class.getDeclaredMethod("getLong", int.class); |
|
|
|
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getLong", String.class); |
|
|
|
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getLong", String.class); |
|
|
|
doTest(rset, rowset, "test", 1L); |
|
|
|
doTest(rset, rowset, "test", 1L); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testGetBooleanInt() throws Exception { |
|
|
|
void testGetBooleanInt() throws Exception { |
|
|
|
Method rset = ResultSet.class.getDeclaredMethod("getBoolean", int.class); |
|
|
|
Method rset = ResultSet.class.getDeclaredMethod("getBoolean", int.class); |
|
|
|
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getBoolean", int.class); |
|
|
|
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getBoolean", int.class); |
|
|
|
doTest(rset, rowset, 1, true); |
|
|
|
doTest(rset, rowset, 1, true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testGetBooleanString() throws Exception { |
|
|
|
void testGetBooleanString() throws Exception { |
|
|
|
Method rset = ResultSet.class.getDeclaredMethod("getBoolean", int.class); |
|
|
|
Method rset = ResultSet.class.getDeclaredMethod("getBoolean", int.class); |
|
|
|
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getBoolean", String.class); |
|
|
|
Method rowset = ResultSetWrappingSqlRowSet.class.getDeclaredMethod("getBoolean", String.class); |
|
|
|
doTest(rset, rowset, "test", true); |
|
|
|
doTest(rset, rowset, "test", true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void doTest(Method rsetMethod, Method rowsetMethod, Object arg, Object ret) throws Exception { |
|
|
|
private void doTest(Method rsetMethod, Method rowsetMethod, Object arg, Object ret) throws Exception { |
|
|
|
if (arg instanceof String) { |
|
|
|
if (arg instanceof String) { |
|
|
|
given(resultSet.findColumn((String) arg)).willReturn(1); |
|
|
|
given(resultSet.findColumn((String) arg)).willReturn(1); |
|
|
|
@ -207,9 +208,9 @@ public class ResultSetWrappingRowSetTests { |
|
|
|
given(rsetMethod.invoke(resultSet, arg)).willReturn(ret).willThrow(new SQLException("test")); |
|
|
|
given(rsetMethod.invoke(resultSet, arg)).willReturn(ret).willThrow(new SQLException("test")); |
|
|
|
} |
|
|
|
} |
|
|
|
rowsetMethod.invoke(rowSet, arg); |
|
|
|
rowsetMethod.invoke(rowSet, arg); |
|
|
|
assertThatExceptionOfType(InvocationTargetException.class).isThrownBy(() -> |
|
|
|
assertThatExceptionOfType(InvocationTargetException.class) |
|
|
|
rowsetMethod.invoke(rowSet, arg)). |
|
|
|
.isThrownBy(() -> rowsetMethod.invoke(rowSet, arg)) |
|
|
|
satisfies(ex -> assertThat(ex.getTargetException()).isExactlyInstanceOf(InvalidResultSetAccessException.class)); |
|
|
|
.satisfies(ex -> assertThat(ex.getTargetException()).isExactlyInstanceOf(InvalidResultSetAccessException.class)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|