From: Steve F. <sm...@us...> - 2003-07-05 15:15:57
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv21732/src/core/com/mockobjects/dynamic Modified Files: Callable.java DynamicUtil.java ReturnStub.java CallBag.java VoidStub.java CallCollection.java CallOnceExpectation.java Mock.java CallStub.java CallSequence.java ThrowStub.java CallSignature.java Added Files: ActiveCall.java Log Message: Refactored methoName and arguments to ActiveCall object. Index: Callable.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Callable.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- Callable.java 12 Jun 2003 22:45:13 -0000 1.3 +++ Callable.java 5 Jul 2003 15:15:54 -0000 1.4 @@ -4,6 +4,6 @@ public interface Callable extends Verifiable { String getDescription(); - Object call( String methodName, Object[] args ) throws Throwable; - boolean matches(String methodName, Object[] args); + Object call( ActiveCall call ) throws Throwable; + boolean matches(ActiveCall activeCall); } Index: DynamicUtil.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/DynamicUtil.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- DynamicUtil.java 18 May 2003 20:59:35 -0000 1.2 +++ DynamicUtil.java 5 Jul 2003 15:15:54 -0000 1.3 @@ -96,6 +96,10 @@ } } + public static String methodToString(ActiveCall call) { + return methodToString(call.getMethodName(), call.args); + } + public static String methodToString(String name, Object[] args) { StringBuffer buf = new StringBuffer(); Index: ReturnStub.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/ReturnStub.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ReturnStub.java 5 Jul 2003 10:11:01 -0000 1.4 +++ ReturnStub.java 5 Jul 2003 15:15:54 -0000 1.5 @@ -12,7 +12,7 @@ this.result = result; } - public Object call(String methodName, Object[] args) throws Throwable { + public Object call(ActiveCall args) throws Throwable { return result; } Index: CallBag.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallBag.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- CallBag.java 12 Jun 2003 22:45:14 -0000 1.4 +++ CallBag.java 5 Jul 2003 15:15:54 -0000 1.5 @@ -20,25 +20,25 @@ this.expectedMatches.clear(); } - public Object call(String methodName, Object[] args) + public Object call(ActiveCall call) throws Throwable { - Callable matchingCall = findMatchingCall(methodName, args, this.expectedCalls); + Callable matchingCall = findMatchingCall(call, this.expectedCalls); if(matchingCall == null) { - matchingCall = findMatchingCall(methodName, args, this.expectedMatches); + matchingCall = findMatchingCall(call, this.expectedMatches); } if(matchingCall == null) { - throw createUnexpectedCallError(methodName, args); + throw createUnexpectedCallError(call); } - return matchingCall.call(methodName, args); + return matchingCall.call(call); } - private Callable findMatchingCall(String methodName, Object[] args, List callList) { - for (Iterator call = callList.iterator(); call.hasNext();) { - Callable element = (Callable) call.next(); + private Callable findMatchingCall(ActiveCall call, List callList) { + for (Iterator nextCall = callList.iterator(); nextCall.hasNext();) { + Callable element = (Callable) nextCall.next(); - if (element.matches(methodName, args)) { + if (element.matches(call)) { return element; } } @@ -63,7 +63,7 @@ } } - public boolean matches(String methodName, Object[] args) { + public boolean matches(ActiveCall activeCall) { throw new Error("not implemented"); } Index: VoidStub.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/VoidStub.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- VoidStub.java 12 Jun 2003 22:45:11 -0000 1.3 +++ VoidStub.java 5 Jul 2003 15:15:54 -0000 1.4 @@ -10,7 +10,7 @@ return "returns <void>"; } - public Object call(String methodName, Object[] args) throws Throwable { + public Object call(ActiveCall args) throws Throwable { return null; } Index: CallCollection.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallCollection.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- CallCollection.java 8 Jun 2003 21:48:24 -0000 1.3 +++ CallCollection.java 5 Jul 2003 15:15:54 -0000 1.4 @@ -4,11 +4,11 @@ abstract public class CallCollection { - protected AssertionFailedError createUnexpectedCallError(String methodName, Object[] args) { + protected AssertionFailedError createUnexpectedCallError(ActiveCall call) { StringBuffer buf = new StringBuffer(); buf.append("Unexpected call: "); - buf.append(DynamicUtil.methodToString(methodName, args)); + buf.append(DynamicUtil.methodToString(call)); buf.append("\n"); buf.append("Expected "); buf.append(getDescription()); Index: CallOnceExpectation.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallOnceExpectation.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- CallOnceExpectation.java 12 Jun 2003 22:45:13 -0000 1.2 +++ CallOnceExpectation.java 5 Jul 2003 15:15:54 -0000 1.3 @@ -14,13 +14,13 @@ return delegate.getDescription() + " [" + (wasCalled ? "" : "not ") + "called]"; } - public Object call(String methodName, Object[] args) throws Throwable { + public Object call(ActiveCall args) throws Throwable { wasCalled = true; - return delegate.call( methodName, args ); + return delegate.call( args ); } - public boolean matches(String methodName, Object[] args) { - return (!wasCalled) && delegate.matches( methodName, args ); + public boolean matches(ActiveCall activeCall) { + return (!wasCalled) && delegate.matches( activeCall ); } public void verify() { Index: Mock.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Mock.java,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- Mock.java 2 Jul 2003 03:46:18 -0000 1.24 +++ Mock.java 5 Jul 2003 15:15:54 -0000 1.25 @@ -80,24 +80,27 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { try { - if (isCheckingEqualityOnProxy(method, args)) { + ActiveCall activeCall = new ActiveCall(method, args); + + if (isCheckingEqualityOnProxy(activeCall)) { return new Boolean(args[0] == this.proxy); - } else if (isMockNameGetter(method, args)) { + } else if (isMockNameGetter(activeCall)) { return this.getMockName(); } else { - return calls.call(method.getName(), (args == null ? new Object[0] : args)); + return calls.call(activeCall); } } catch (AssertionFailedError ex) { throw new AssertionFailedError(name + ": " + ex.getMessage()); } } - private boolean isCheckingEqualityOnProxy(Method method, Object[] args) { - return (method.getName().equals("equals")) && (args.length == 1) && (Proxy.isProxyClass(args[0].getClass())); + private boolean isCheckingEqualityOnProxy(ActiveCall call) { + return (call.getMethodName().equals("equals")) && (call.args.length == 1) + && (Proxy.isProxyClass(call.args[0].getClass())); } - private boolean isMockNameGetter(Method method, Object[] args) { - return (method.getName().equals("getMockName")) && (args.length == 0); + private boolean isMockNameGetter(ActiveCall call) { + return (call.getMethodName().equals("getMockName")) && (call.args.length == 0); } public void verify() { Index: CallStub.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallStub.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- CallStub.java 10 Jun 2003 17:07:45 -0000 1.3 +++ CallStub.java 5 Jul 2003 15:15:54 -0000 1.4 @@ -6,7 +6,7 @@ public abstract class CallStub implements Callable { - public boolean matches(String methodName, Object[] args) { + public boolean matches(ActiveCall activeCall) { return true; } Index: CallSequence.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallSequence.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- CallSequence.java 12 Jun 2003 22:45:12 -0000 1.6 +++ CallSequence.java 5 Jul 2003 15:15:54 -0000 1.7 @@ -17,18 +17,18 @@ this.matchedCalls.reset(); } - public Object call(String methodName, Object[] args) throws Throwable { - if (expectedCalls.size() == 0) throw new AssertionFailedError("no methods defined on mock, received: " + DynamicUtil.methodToString(methodName, args)); - if (callIndex == expectedCalls.size()) throw new AssertionFailedError("mock called too many times, received: " + DynamicUtil.methodToString(methodName, args)); + public Object call(ActiveCall activeCall) throws Throwable { + if (expectedCalls.size() == 0) throw new AssertionFailedError("no methods defined on mock, received: " + DynamicUtil.methodToString(activeCall)); + if (callIndex == expectedCalls.size()) throw new AssertionFailedError("mock called too many times, received: " + DynamicUtil.methodToString(activeCall)); - Callable nextCall = (Callable)expectedCalls.get(callIndex++); - if (nextCall.matches(methodName, args)) - return nextCall.call(methodName, args); + Callable callable = (Callable)expectedCalls.get(callIndex++); + if (callable.matches(activeCall)) + return callable.call(activeCall); try { - return matchedCalls.call(methodName, args); + return matchedCalls.call(activeCall); } catch (AssertionFailedError ex) { - throw createUnexpectedCallError(methodName, args); + throw createUnexpectedCallError(activeCall); } } @@ -51,7 +51,7 @@ } } - public boolean matches(String methodName, Object[] args) { + public boolean matches(ActiveCall activeCall) { throw new AssertionFailedError("matches() operation not supported in CallSequence"); } Index: ThrowStub.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/ThrowStub.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ThrowStub.java 5 Jul 2003 10:11:01 -0000 1.4 +++ ThrowStub.java 5 Jul 2003 15:15:54 -0000 1.5 @@ -12,7 +12,7 @@ this.throwable = throwable; } - public Object call(String methodName, Object[] args) throws Throwable { + public Object call(ActiveCall args) throws Throwable { throw throwable; } Index: CallSignature.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallSignature.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- CallSignature.java 12 Jun 2003 22:45:14 -0000 1.2 +++ CallSignature.java 5 Jul 2003 15:15:54 -0000 1.3 @@ -14,18 +14,18 @@ this.delegate = delegate; } - public Object call( String methodName, Object[] args ) + public Object call( ActiveCall args ) throws Throwable { - return delegate.call( methodName, args ); + return delegate.call( args ); } public void verify() { delegate.verify(); } - public boolean matches(String methodName, Object[] args) { - return this.methodName.equals(methodName) && constraints.matches(args); + public boolean matches(ActiveCall activeCall) { + return this.methodName.equals(activeCall.getMethodName()) && constraints.matches(activeCall.args); } public String getDescription() { |