Issue Details (XML | Word | Printable)

Key: DBUTILS-9
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: Michael Schuerig
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Commons DbUtils

[dbutils] MockResultSet needs to handle equals and hashCode

Created: 20/Oct/04 01:45 AM   Updated: 02/Jan/08 07:29 AM
Return to search
Component/s: None
Affects Version/s: 1.0
Fix Version/s: 1.1

Time Tracking:
Not Specified

Environment:
Operating System: other
Platform: Other

Bugzilla Id: 31786


 Description  « Hide
Please amend MockResultSet#invoke like this in order to handel equals,
hashCode, and toString

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

String methodName = method.getName();

if (methodName.equals("getMetaData")) { //... } else if (methodName.equals("equals")) { return Boolean.valueOf(proxy == args[0]); } else if (methodName.equals("hashCode")) { return Integer.valueOf(System.identityHashCode(proxy)); } else if (methodName.equals("toString")) { return proxy.toString(); }

return null;
}

This addition makes proxies generated by MockResultSet usable in Maps. That
might not look like a big deal, but it is. Among other things, EasyMock keeps
arguments and return values in Maps. With the addition, MockResultSet proxies
can be used with mock objects created by EasyMock.

Michael



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
David Graham added a comment - 01/Nov/04 11:11 AM
I added toString, equals, and hashCode implementations to MockResultSet and
MockResultSetMetaData. A couple things though:
  • return Integer.valueOf(System.identityHashCode(proxy)) does not compile so I
    changed it to return new Integer(System.identityHashCode(proxy))
  • return proxy.toString() causes an infinite loop so I changed it to return
    "MockResultSet " + System.identityHashCode(proxy)