From: Steve F. <sm...@us...> - 2002-11-05 16:27:32
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory usw-pr-cvs1:/tmp/cvs-serv4441/src/core/com/mockobjects/dynamic Modified Files: Mock.java Log Message: Added equals method that handles the other object being a proxy Index: Mock.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Mock.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- Mock.java 5 Nov 2002 16:04:32 -0000 1.8 +++ Mock.java 5 Nov 2002 16:27:29 -0000 1.9 @@ -265,6 +265,21 @@ methods.order(preceding_method, subsequent_method); } + + /** + * @see java.lang.Object#equals(java.lang.Object) + * This version will unpack the inovaction handler if the + * other object is a proxy. + */ + public boolean equals(Object obj) { + try { + return equals(Proxy.getInvocationHandler(obj)); + } catch (IllegalArgumentException ignored) { + } + return super.equals(obj); + } + + /** Called by the {@link java.lang.reflect.Proxy} to mock the behaviour of an * invoked method and check expectations. */ @@ -298,6 +313,7 @@ return defaultResult( method.getReturnType() ); } + private Method getMatchingMethod(Method method) throws NoSuchMethodException { @@ -326,5 +342,4 @@ new Class[]{ interface_class }, handler ); } - } |