From: Steve F. <sm...@us...> - 2003-10-05 08:57:32
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv29646/src/core/com/mockobjects/dynamic Modified Files: InvocationMatcher.java VoidStub.java InvocationMocker.java Stub.java Log Message: Extended InvocationMatcher and InvocationMocker Index: InvocationMatcher.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/InvocationMatcher.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- InvocationMatcher.java 4 Oct 2003 22:56:45 -0000 1.1 +++ InvocationMatcher.java 5 Oct 2003 08:57:27 -0000 1.2 @@ -3,11 +3,15 @@ */ package com.mockobjects.dynamic; +import java.util.List; + import com.mockobjects.constraint.Constraint; import com.mockobjects.constraint.IsEqual; public interface InvocationMatcher { + boolean matches(Invocation invocation); + public class MethodName implements InvocationMatcher { private Constraint constraint; @@ -22,4 +26,27 @@ return constraint.eval(invocation.getMethodName()); } } + + public class Arguments implements InvocationMatcher { + private Constraint[] constraints; + + public Arguments(Constraint[] constraints) { + Arguments.this.constraints = constraints; + } + + public boolean matches(Invocation invocation) { + return constraints.length == invocation.getParameterValues().size() + && matchesValues(invocation.getParameterValues()); + } + + private boolean matchesValues(List list) { + for (int i = 0; i < constraints.length; ++i) { + if (!constraints[i].eval(list.get(i))) { + return false; + } + } + return true; + } + } + } Index: VoidStub.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/VoidStub.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- VoidStub.java 20 Aug 2003 21:51:27 -0000 1.6 +++ VoidStub.java 5 Oct 2003 08:57:27 -0000 1.7 @@ -4,7 +4,7 @@ package com.mockobjects.dynamic; -public class VoidStub extends CallStub { +public class VoidStub extends CallStub implements Stub { public String getDescription() { return "returns <void>"; Index: InvocationMocker.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/InvocationMocker.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- InvocationMocker.java 4 Oct 2003 22:56:45 -0000 1.1 +++ InvocationMocker.java 5 Oct 2003 08:57:27 -0000 1.2 @@ -8,6 +8,11 @@ private InvocationMatcher[] matchers; private Stub stub; + public InvocationMocker(String methodName, InvocationMatcher.Arguments arguments, Stub stub) { + this(new InvocationMatcher[] {new InvocationMatcher.MethodName(methodName), arguments}, + stub); + } + public InvocationMocker(InvocationMatcher[] matchers, Stub stub) { this.matchers = matchers; this.stub = stub; @@ -26,7 +31,7 @@ } public Object invoke(Invocation invocation) throws Throwable { - return stub.stub(invocation); + return stub.invoke(invocation); } public void verify() { Index: Stub.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Stub.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- Stub.java 2 Oct 2003 22:55:32 -0000 1.3 +++ Stub.java 5 Oct 2003 08:57:27 -0000 1.4 @@ -22,5 +22,5 @@ * An exception to be thrown to the caller, if not returning a value. A checked exception * thrown from this method must be in the <code>throws</code> list of the invoked method. */ - Object stub( Invocation invocation ) throws Throwable; + Object invoke( Invocation invocation ) throws Throwable; } |