Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv805/src/core/com/mockobjects/dynamic Modified Files: Tag: DynamicMockExperiment CallSet.java DefaultCallFactory.java CallFactory.java ExpectedCall.java Added Files: Tag: DynamicMockExperiment VoidStub.java Log Message: expect and VoidReturnStub --- NEW FILE: VoidStub.java --- /* * Created on 11-Apr-2003 */ package com.mockobjects.dynamic; public class VoidStub extends CallStub { public String getDescription() { return "returns <void>"; } public Object call(Mock mock, String methodName, Object[] args) throws Throwable { return null; } } Index: CallSet.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Attic/CallSet.java,v retrieving revision 1.1.2.5 retrieving revision 1.1.2.6 diff -u -r1.1.2.5 -r1.1.2.6 --- CallSet.java 11 Apr 2003 13:18:43 -0000 1.1.2.5 +++ CallSet.java 11 Apr 2003 15:38:18 -0000 1.1.2.6 @@ -59,6 +59,21 @@ } } + public void expect( String methodName, Constraint[] args) { + add( callFactory.createExpectedCall( callFactory.createCallMatch( methodName, args, callFactory.createVoidStub()))); + } + + public void expectAndReturn( String methodName, Object equalArg, Object result ) { + expectAndReturn(methodName, C.args(C.eq(equalArg)), result); + } + + public void expectAndReturn( String methodName, Constraint[] args, Object result ) { + add( callFactory.createExpectedCall( callFactory.createCallMatch( methodName, args, callFactory.createReturnStub(result)))); + } + + public void expectAndThrow( String methodName, Constraint[] args, Throwable exception ) { + add( callFactory.createExpectedCall( callFactory.createCallMatch( methodName, args, callFactory.createThrowStub(exception)))); + } public void verify() { for (Iterator call = expectedCalls.iterator(); call.hasNext();) { Callable element = (Callable) call.next(); @@ -83,19 +98,6 @@ public void matchAndThrow( String methodName, Constraint[] args, Throwable throwable ) { add( callFactory.createCallMatch( methodName, args, callFactory.createThrowStub(throwable) ) ); - } - - - - public void expectAndReturn( String methodName, Object equalArg, Object result ) { - expectAndReturn(methodName, C.args(C.eq(equalArg)), result); - } - - public void expectAndReturn( String methodName, Constraint[] args, Object result ) { - add( callFactory.createExpectedCall( callFactory.createCallMatch( methodName, args, callFactory.createReturnStub(result)))); - } - public void expectAndThrow( String methodName, Constraint[] args, Throwable exception ) { - add( callFactory.createExpectedCall( callFactory.createCallMatch( methodName, args, callFactory.createThrowStub(exception)))); } public boolean matches(String methodName, Object[] args) { Index: DefaultCallFactory.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Attic/DefaultCallFactory.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- DefaultCallFactory.java 11 Apr 2003 13:18:44 -0000 1.1.2.2 +++ DefaultCallFactory.java 11 Apr 2003 15:38:18 -0000 1.1.2.3 @@ -26,4 +26,8 @@ return new CallMatch( methodName, constraints, call ); } + public Callable createVoidStub() { + return new VoidStub(); + } + } Index: CallFactory.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Attic/CallFactory.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- CallFactory.java 11 Apr 2003 13:18:45 -0000 1.1.2.2 +++ CallFactory.java 11 Apr 2003 15:38:18 -0000 1.1.2.3 @@ -11,6 +11,7 @@ public interface CallFactory { Callable createReturnStub( Object result ); Callable createThrowStub( Throwable throwable ); + Callable createVoidStub(); Callable createExpectedCall( Callable call ); Callable createCallMatch( String methodName, Constraint[] constraints, Callable call ); } Index: ExpectedCall.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Attic/ExpectedCall.java,v retrieving revision 1.2.2.3 retrieving revision 1.2.2.4 diff -u -r1.2.2.3 -r1.2.2.4 --- ExpectedCall.java 11 Apr 2003 13:18:45 -0000 1.2.2.3 +++ ExpectedCall.java 11 Apr 2003 15:38:18 -0000 1.2.2.4 @@ -9,31 +9,31 @@ * @author dev */ public class ExpectedCall implements Callable { - private Callable decorated; + private Callable delegate; private boolean wasCalled = false; - public ExpectedCall( Callable decorated ) { - this.decorated = decorated; + public ExpectedCall( Callable delegate ) { + this.delegate = delegate; } public String getDescription() { - return decorated.getDescription() + " [mandatory]"; + return delegate.getDescription() + " [mandatory]"; } public Object call(Mock mock, String methodName, Object[] args) throws Throwable { wasCalled = true; - return decorated.call( mock, methodName, args ); + return delegate.call( mock, methodName, args ); } public boolean matches(String methodName, Object[] args) { - return decorated.matches( methodName, args ); + return delegate.matches( methodName, args ); } public void verify() { if( !wasCalled ) { - throw new AssertionFailedError( decorated.getDescription() + " was expected but not called" ); + throw new AssertionFailedError( delegate.getDescription() + " was expected but not called" ); } - decorated.verify(); + delegate.verify(); } } |