Skip to content

Commit

Permalink
Sort members
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Nov 23, 2023
1 parent c3a913f commit a6cdeab
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 47 deletions.
24 changes: 12 additions & 12 deletions src/test/java/org/apache/commons/dbutils/BaseTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ protected ResultSet createMockResultSet() {
return MockResultSet.create(metaData, rows);
}

public ResultSet getEmptyResultSet() {
return this.emptyResultSet;
}

public ResultSet getResultSet() {
return this.rs;
}

public void setResultSet(ResultSet resultSet) {
this.rs = resultSet;
}

/**
* This is called before each test method so ResultSet will be fresh each time.
*
Expand All @@ -92,18 +104,6 @@ protected void setUp() throws Exception {
emptyResultSet = MockResultSet.create(metaData, null);
}

public ResultSet getResultSet() {
return this.rs;
}

public ResultSet getEmptyResultSet() {
return this.emptyResultSet;
}

public void setResultSet(ResultSet resultSet) {
this.rs = resultSet;
}

// Test which allows Eclipse to be run on full project (avoids no tests found)
// check that the rows are valid for the column definition
public void testCheckDataSizes() {
Expand Down
58 changes: 29 additions & 29 deletions src/test/java/org/apache/commons/dbutils/MockResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
*/
public class MockResultSet implements InvocationHandler {

private static final Set<String> METHOD_NAMES = Set.of("isLast", "hashCode", "toString", "equals");

/**
* Create a {@code MockResultSet} proxy object. This is equivalent to:
*
Expand All @@ -54,8 +56,6 @@ public static ResultSet create(final ResultSetMetaData metaData, final Object[][

private Boolean wasNull = Boolean.FALSE;

private static final Set<String> METHOD_NAMES = Set.of("isLast", "hashCode", "toString", "equals");

/**
* MockResultSet constructor.
*
Expand Down Expand Up @@ -267,33 +267,6 @@ protected String getString(final int columnIndex) throws SQLException {
return obj == null ? null : obj.toString();
}

@Override
public Object invoke(final Object proxy, final Method method, final Object[] args)
throws Throwable {

final String methodName = method.getName();
if (methodName.equals("getMetaData")) {
return this.getMetaData();
}
if (methodName.equals("next")) {
return this.next();
}
if (methodName.equals("previous")) {
// Handle previous method
} else if (methodName.equals("close")) {
// Handle close method
} else if (isColumnMethod(methodName)) {
return handleColumnMethod(methodName, args);
} else if (METHOD_NAMES.contains(methodName)) {
return handleNonColumnMethod(methodName, proxy, args);
}
throw new UnsupportedOperationException("Unsupported method: " + methodName);
}

private boolean isColumnMethod(String methodName) {
return methodName.startsWith("get") || methodName.equals("wasNull");
}

private Object handleColumnMethod(String methodName, final Object[] args) throws SQLException {
switch (methodName) {
case "getBoolean":
Expand Down Expand Up @@ -336,6 +309,33 @@ private Object handleNonColumnMethod(String methodName, Object proxy, Object[] a
}
}

@Override
public Object invoke(final Object proxy, final Method method, final Object[] args)
throws Throwable {

final String methodName = method.getName();
if (methodName.equals("getMetaData")) {
return this.getMetaData();
}
if (methodName.equals("next")) {
return this.next();
}
if (methodName.equals("previous")) {
// Handle previous method
} else if (methodName.equals("close")) {
// Handle close method
} else if (isColumnMethod(methodName)) {
return handleColumnMethod(methodName, args);
} else if (METHOD_NAMES.contains(methodName)) {
return handleNonColumnMethod(methodName, proxy, args);
}
throw new UnsupportedOperationException("Unsupported method: " + methodName);
}

private boolean isColumnMethod(String methodName) {
return methodName.startsWith("get") || methodName.equals("wasNull");
}

/**
* @throws SQLException
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ public AbstractTestColumnHandler(final ColumnHandler<T> handler, final Class<?>
this.matchingType = matchingType;
}

public ResultSet getResultSet() {
return this.rs;
}

public ColumnHandler<T> getColumnHandler() {
return this.handler;
}
Expand All @@ -49,6 +45,10 @@ public Class<?> getMatchingType() {
return this.matchingType;
}

public ResultSet getResultSet() {
return this.rs;
}

@Test
public abstract void testApplyType() throws Exception;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ public void setObject(final Object value) throws SQLException {
*/
public class SqlNullCheckedResultSetTest extends BaseTestCase {

private static ResultSet rs;

private static void assertArrayEquals(final byte[] expected, final byte[] actual) {
if (expected == actual) {
return;
Expand All @@ -227,9 +229,7 @@ private static void assertArrayEquals(final byte[] expected, final byte[] actual
assertEquals("Array not equal at index " + i, expectedItem, actualItem);
}
}

private SqlNullCheckedResultSet rs2;
private static ResultSet rs;

/**
* Sets up instance variables required by this test case.
Expand Down

0 comments on commit a6cdeab

Please sign in to comment.