sanjanarampurkottur01 commented on code in PR #220:
URL: https://github.com/apache/commons-dbutils/pull/220#discussion_r1402115817
##########
src/test/java/org/apache/commons/dbutils/MockResultSet.java:
##########
@@ -265,64 +266,77 @@ protected String getString(final int columnIndex) throws
SQLException {
}
@Override
- public Object invoke(final Object proxy, final Method method, final
Object[] args) throws Throwable {
+ 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") || methodName.equals("close")) {
-
- } else if (methodName.equals("getBoolean")) {
- return this.getBoolean(columnIndex(args));
-
- } else if (methodName.equals("getByte")) {
- return this.getByte(columnIndex(args));
-
- } else if (methodName.equals("getDouble")) {
- return this.getDouble(columnIndex(args));
-
- } else if (methodName.equals("getFloat")) {
- return this.getFloat(columnIndex(args));
-
- } else if (methodName.equals("getInt")) {
- return this.getInt(columnIndex(args));
-
- } else if (methodName.equals("getLong")) {
- return this.getLong(columnIndex(args));
-
- } else if (methodName.equals("getObject")) {
- return this.getObject(columnIndex(args));
-
- } else if (methodName.equals("getShort")) {
- return this.getShort(columnIndex(args));
-
- } else if (methodName.equals("getString")) {
- return this.getString(columnIndex(args));
-
- } else if (methodName.equals("wasNull")) {
- return this.wasNull();
+ 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 (isNonColumnMethod(methodName)) {
+ return handleNonColumnMethod(methodName, proxy, args);
+ }
+ throw new UnsupportedOperationException("Unsupported method: " +
methodName);
+ }
- } else if (methodName.equals("isLast")) {
- return this.isLast();
+ private boolean isColumnMethod(String methodName) {
+ return methodName.startsWith("get") || methodName.equals("wasNull");
+ }
- } else if (methodName.equals("hashCode")) {
- return Integer.valueOf(System.identityHashCode(proxy));
+ private Object handleColumnMethod(String methodName, final Object[] args)
throws SQLException {
+ switch (methodName) {
+ case "getBoolean":
+ return this.getBoolean(columnIndex(args));
+ case "getByte":
+ return this.getByte(columnIndex(args));
+ case "getDouble":
+ return this.getDouble(columnIndex(args));
+ case "getFloat":
+ return this.getFloat(columnIndex(args));
+ case "getInt":
+ return this.getInt(columnIndex(args));
+ case "getLong":
+ return this.getLong(columnIndex(args));
+ case "getObject":
+ return this.getObject(columnIndex(args));
+ case "getShort":
+ return this.getShort(columnIndex(args));
+ case "getString":
+ return this.getString(columnIndex(args));
+ case "wasNull":
+ return this.wasNull();
+ default:
+ throw new UnsupportedOperationException("Unsupported column
method: " + methodName);
+ }
+ }
- } else if (methodName.equals("toString")) {
- return "MockResultSet " + System.identityHashCode(proxy);
+ private boolean isNonColumnMethod(String methodName) {
+ Set<String> methodNames = Set.of("isLast", "hashCode", "toString",
"equals");
Review Comment:
Modified this as well. Thanks for noticing it. Static field will be a better
choice. Thank you!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]