You can subscribe to this list here.
2001 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(13) |
Aug
(151) |
Sep
(21) |
Oct
(6) |
Nov
(70) |
Dec
(8) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2002 |
Jan
(47) |
Feb
(66) |
Mar
(23) |
Apr
(115) |
May
(24) |
Jun
(53) |
Jul
(10) |
Aug
(279) |
Sep
(84) |
Oct
(149) |
Nov
(138) |
Dec
(52) |
2003 |
Jan
(22) |
Feb
(20) |
Mar
(29) |
Apr
(106) |
May
(170) |
Jun
(122) |
Jul
(70) |
Aug
(64) |
Sep
(27) |
Oct
(71) |
Nov
(49) |
Dec
(9) |
2004 |
Jan
(7) |
Feb
(38) |
Mar
(3) |
Apr
(9) |
May
(22) |
Jun
(4) |
Jul
(1) |
Aug
(2) |
Sep
(2) |
Oct
|
Nov
(15) |
Dec
(2) |
2005 |
Jan
(1) |
Feb
(1) |
Mar
|
Apr
(1) |
May
(28) |
Jun
(3) |
Jul
(11) |
Aug
(5) |
Sep
(1) |
Oct
(5) |
Nov
(2) |
Dec
(3) |
2006 |
Jan
(8) |
Feb
(3) |
Mar
(8) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv15934/core/com/mockobjects/dynamic Modified Files: Tag: DynamicMockExperiment CallFactory.java DefaultCallFactory.java CallCollection.java C.java Mock.java CallMatch.java ExpectedCall.java DynamicUtil.java Added Files: Tag: DynamicMockExperiment FullConstraintMatcher.java ConstraintMatcher.java AnyConstraintMatcher.java Log Message: - Changed Constraint[] usage to ConstraintMatcher to support Any constraint matching - Support for matching Object[] parameters --- NEW FILE: FullConstraintMatcher.java --- /* * Created on 20-Apr-03 */ package com.mockobjects.dynamic; import com.mockobjects.constraint.Constraint; public class FullConstraintMatcher implements ConstraintMatcher { private Constraint[] constraints; public FullConstraintMatcher(Constraint[] constraints) { this.constraints = constraints; } public FullConstraintMatcher(Constraint c1) { this(new Constraint[] {c1}); } public FullConstraintMatcher(Constraint c1, Constraint c2) { this(new Constraint[] {c1, c2}); } public FullConstraintMatcher(Constraint c1, Constraint c2, Constraint c3) { this(new Constraint[] {c1, c2, c3}); } public boolean matches(Object[] args) { if( args.length != constraints.length ) return false; for (int i = 0; i < args.length; i++) { if( !constraints[i].eval(args[i]) ) return false; } return true; } public Object[] getConstraints() { return constraints; } } --- NEW FILE: ConstraintMatcher.java --- /* * Created on 20-Apr-03 */ package com.mockobjects.dynamic; public interface ConstraintMatcher { boolean matches(Object[] args); Object[] getConstraints(); } --- NEW FILE: AnyConstraintMatcher.java --- /* * Created on 20-Apr-03 */ package com.mockobjects.dynamic; public class AnyConstraintMatcher implements ConstraintMatcher { public boolean matches(Object[] args) { return true; } public Object[] getConstraints() { return new String[] {"ANY"}; } } Index: CallFactory.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Attic/CallFactory.java,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -r1.1.2.3 -r1.1.2.4 --- CallFactory.java 11 Apr 2003 15:38:18 -0000 1.1.2.3 +++ CallFactory.java 5 May 2003 22:44:32 -0000 1.1.2.4 @@ -3,7 +3,6 @@ */ package com.mockobjects.dynamic; -import com.mockobjects.constraint.*; /** * @author dev @@ -13,5 +12,5 @@ Callable createThrowStub( Throwable throwable ); Callable createVoidStub(); Callable createExpectedCall( Callable call ); - Callable createCallMatch( String methodName, Constraint[] constraints, Callable call ); + Callable createCallMatch( String methodName, ConstraintMatcher constraints, Callable call ); } Index: DefaultCallFactory.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Attic/DefaultCallFactory.java,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -r1.1.2.3 -r1.1.2.4 --- DefaultCallFactory.java 11 Apr 2003 15:38:18 -0000 1.1.2.3 +++ DefaultCallFactory.java 5 May 2003 22:44:33 -0000 1.1.2.4 @@ -3,8 +3,6 @@ */ package com.mockobjects.dynamic; -import com.mockobjects.constraint.*; - /** * @author dev */ @@ -22,7 +20,7 @@ return new ExpectedCall(call); } - public Callable createCallMatch(String methodName, Constraint[] constraints, Callable call) { + public Callable createCallMatch(String methodName, ConstraintMatcher constraints, Callable call) { return new CallMatch( methodName, constraints, call ); } Index: CallCollection.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallCollection.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- CallCollection.java 16 Apr 2003 22:47:58 -0000 1.1.2.2 +++ CallCollection.java 5 May 2003 22:44:33 -0000 1.1.2.3 @@ -7,7 +7,7 @@ protected AssertionFailedError createUnexpectedCallError(String methodName, Object[] args) { StringBuffer buf = new StringBuffer(); - buf.append("Unexpected call to "); + buf.append("Unexpected call: "); buf.append(DynamicUtil.methodToString(methodName, args)); buf.append("\n"); buf.append("Expected "); Index: C.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/C.java,v retrieving revision 1.1.2.6 retrieving revision 1.1.2.7 diff -u -r1.1.2.6 -r1.1.2.7 --- C.java 17 Apr 2003 11:46:25 -0000 1.1.2.6 +++ C.java 5 May 2003 22:44:33 -0000 1.1.2.7 @@ -19,8 +19,8 @@ public static final Constraint IS_ZERO = eq(new Integer(0)); public static final Constraint IS_NOT_ZERO = not(IS_ZERO); - public static final Constraint[] NO_ARGS = new Constraint[0]; - + public static final ConstraintMatcher NO_ARGS = new FullConstraintMatcher(new Constraint[0]); + public static final ConstraintMatcher ANY_ARGS = new AnyConstraintMatcher(); public static Constraint same( Object o ) { return new IsSame(o); @@ -29,20 +29,13 @@ public static Constraint eq( Object o ) { return new IsEqual(o); } - - public static Constraint[] eq( Object o0, Object o1 ) { - Constraint[] result = new Constraint[2]; - result[0] = eq(o0); - result[1] = eq(o1); - return result; + + public static ConstraintMatcher eq( Object arg0, Object arg1 ) { + return args(eq(arg0), eq(arg1)); } - public static Constraint[] eq( Object o0, Object o1, Object o2 ) { - Constraint[] result = new Constraint[3]; - result[0] = eq(o0); - result[1] = eq(o1); - result[2] = eq(o2); - return result; + public static ConstraintMatcher eq( Object arg0, Object arg1, Object arg2 ) { + return args(eq(arg0), eq(arg1), eq(arg2)); } public static Constraint eq( int n ) { @@ -110,28 +103,28 @@ /* Helper methods for succinctly constructing Constraint arrays */ - public static Constraint[] args() { - return new Constraint[0]; + public static ConstraintMatcher args() { + return NO_ARGS; } - public static Constraint[] args(Constraint p) { - return new Constraint[] {p}; + public static ConstraintMatcher args(Constraint p) { + return new FullConstraintMatcher(new Constraint[]{p}); } - public static Constraint[] args(Constraint p1, Constraint p2) { - return new Constraint[] {p1, p2}; + public static ConstraintMatcher args(Constraint p1, Constraint p2) { + return new FullConstraintMatcher(new Constraint[]{p1, p2}); } - public static Constraint[] args(Constraint p1, Constraint p2, Constraint p3) { - return new Constraint[] {p1, p2, p3}; + public static ConstraintMatcher args(Constraint p1, Constraint p2, Constraint p3) { + return new FullConstraintMatcher(new Constraint[]{p1, p2, p3}); } - public static Constraint[] anyArgs( int argCount) { - Constraint[] result = new Constraint[argCount]; - for (int i = 0; i < result.length; i++) { - result[i] = new IsAnything(); + public static ConstraintMatcher anyArgs( int argCount) { + Constraint[] constraints = new Constraint[argCount]; + for (int i = 0; i < constraints.length; i++) { + constraints[i] = new IsAnything(); } - return result; + return new FullConstraintMatcher(constraints); } } Index: Mock.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Mock.java,v retrieving revision 1.16.2.11 retrieving revision 1.16.2.12 diff -u -r1.16.2.11 -r1.16.2.12 --- Mock.java 29 Apr 2003 15:39:05 -0000 1.16.2.11 +++ Mock.java 5 May 2003 22:44:33 -0000 1.16.2.12 @@ -13,7 +13,6 @@ import com.mockobjects.Verifiable; import com.mockobjects.constraint.Constraint; - /** * @author dev */ @@ -53,6 +52,22 @@ } } + private ConstraintMatcher createConstraintMatcher(Object constraintArg) { + // Can't overload this method as callee had an Object parameter, and java + // doesn't do a secondary dispatch on the true underlying type + + if(constraintArg instanceof Constraint[]) { + // to support possible legacy usage of new Contraint[] {...} + return new FullConstraintMatcher((Constraint[])constraintArg); + } else if(constraintArg instanceof Constraint) { + // to support usage of C.lt(5) type constraints + return C.args((Constraint)constraintArg); + } else { + // normal usage of the overloaded expect/match object parameter + return C.args(C.eq(constraintArg)); + } + } + public String getMockName() { return name; } @@ -102,10 +117,10 @@ } public void expect(String methodName, Object singleEqualArg) { - expect(methodName, C.args(C.eq(singleEqualArg))); + expect(methodName, createConstraintMatcher(singleEqualArg)); } - public void expect(String methodName, Constraint[] args) { + public void expect(String methodName, ConstraintMatcher args) { callSequence.addExpect(callFactory.createExpectedCall(callFactory.createCallMatch(methodName, args, callFactory.createVoidStub()))); } @@ -122,7 +137,7 @@ } public void expectAndReturn(String methodName, Object singleEqualArg, Object result) { - this.expectAndReturn(methodName, C.args(C.eq(singleEqualArg)), result); + this.expectAndReturn(methodName, createConstraintMatcher(singleEqualArg), result); } public void expectAndReturn(String methodName, Object singleEqualArg, boolean result) { @@ -133,15 +148,15 @@ this.expectAndReturn(methodName, singleEqualArg, new Integer(result)); } - public void expectAndReturn(String methodName, Constraint[] args, Object result) { + public void expectAndReturn(String methodName, ConstraintMatcher args, Object result) { callSequence.addExpect(callFactory.createExpectedCall(callFactory.createCallMatch(methodName, args, callFactory.createReturnStub(result)))); } - public void expectAndReturn(String methodName, Constraint[] args, boolean result) { + public void expectAndReturn(String methodName, ConstraintMatcher args, boolean result) { this.expectAndReturn(methodName, args, new Boolean(result)); } - public void expectAndReturn(String methodName, Constraint[] args, int result) { + public void expectAndReturn(String methodName, ConstraintMatcher args, int result) { this.expectAndReturn(methodName, args, new Integer(result)); } @@ -150,10 +165,10 @@ } public void expectAndThrow(String methodName, Object singleEqualArg, Throwable exception) { - this.expectAndThrow(methodName, C.args(C.eq(singleEqualArg)), exception); + this.expectAndThrow(methodName, createConstraintMatcher(singleEqualArg), exception); } - public void expectAndThrow(String methodName, Constraint[] args, Throwable exception) { + public void expectAndThrow(String methodName, ConstraintMatcher args, Throwable exception) { callSequence.addExpect(callFactory.createExpectedCall(callFactory.createCallMatch(methodName, args, callFactory.createThrowStub(exception)))); } @@ -170,7 +185,7 @@ } public void matchAndReturn(String methodName, Object singleEqualArg, Object result) { - this.matchAndReturn(methodName, C.args(C.eq(singleEqualArg)), result); + this.matchAndReturn(methodName, createConstraintMatcher(singleEqualArg), result); } public void matchAndReturn(String methodName, boolean singleEqualArg, Object result) { @@ -189,15 +204,15 @@ this.matchAndReturn(methodName, singleEqualArg, new Integer(result)); } - public void matchAndReturn(String methodName, Constraint[] args, Object result) { + public void matchAndReturn(String methodName, ConstraintMatcher args, Object result) { callSequence.addMatch(callFactory.createCallMatch(methodName, args, callFactory.createReturnStub(result))); } - public void matchAndReturn(String methodName, Constraint[] args, boolean result) { + public void matchAndReturn(String methodName, ConstraintMatcher args, boolean result) { this.matchAndReturn(methodName, args, new Boolean(result)); } - public void matchAndReturn(String methodName, Constraint[] args, int result) { + public void matchAndReturn(String methodName, ConstraintMatcher args, int result) { this.matchAndReturn(methodName, args, new Integer(result)); } @@ -206,7 +221,7 @@ } public void matchAndThrow(String methodName, Object singleEqualArg, Throwable throwable) { - this.matchAndThrow(methodName, C.args(C.eq(singleEqualArg)), throwable); + this.matchAndThrow(methodName, createConstraintMatcher(singleEqualArg), throwable); } public void matchAndThrow(String methodName, boolean singleEqualArg, Throwable throwable) { @@ -217,7 +232,7 @@ this.matchAndThrow(methodName,new Integer(singleEqualArg), throwable); } - public void matchAndThrow(String methodName, Constraint[] args, Throwable throwable) { + public void matchAndThrow(String methodName, ConstraintMatcher args, Throwable throwable) { callSequence.addMatch(callFactory.createCallMatch(methodName, args, callFactory.createThrowStub(throwable))); } @@ -241,7 +256,7 @@ /** @deprecated @see expect */ - public void expectVoid(String methodName, Constraint[] args) { + public void expectVoid(String methodName, ConstraintMatcher args) { this.expect(methodName, args); } Index: CallMatch.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Attic/CallMatch.java,v retrieving revision 1.1.2.5 retrieving revision 1.1.2.6 diff -u -r1.1.2.5 -r1.1.2.6 --- CallMatch.java 16 Apr 2003 22:47:37 -0000 1.1.2.5 +++ CallMatch.java 5 May 2003 22:44:33 -0000 1.1.2.6 @@ -3,58 +3,37 @@ */ package com.mockobjects.dynamic; -import junit.framework.*; - -import com.mockobjects.constraint.*; -import com.mockobjects.util.*; +import junit.framework.Assert; +// TODO rename to CallSignature public class CallMatch extends Assert implements Callable { private String methodName; - private Constraint[] constraints; - private Callable decorated; + private ConstraintMatcher constraints; + private Callable delegate; - public CallMatch( String methodName, Constraint[] constraints, Callable decorated ) { + public CallMatch( String methodName, ConstraintMatcher constraints, Callable delegate ) { this.methodName = methodName; - this.constraints = (Constraint[])constraints.clone(); - this.decorated = decorated; + this.constraints = constraints; + this.delegate = delegate; } public Object call( Mock mock, String methodName, Object[] args ) throws Throwable - { - assertEquals( methodName + " received the wrong number of arguments", - constraints.length, args.length ); - - for( int i = 0; i < args.length; i++ ) { - if( !constraints[i].eval(args[i]) ) { - throw new AssertionFailedError( - AssertMo.expectedErrorMessage( methodName + " received incorrect argument " + i, - DynamicUtil.join(constraints), - DynamicUtil.join(args) ) ); - } - } - - return decorated.call( mock, methodName, args ); + { + return delegate.call( mock, methodName, args ); } public void verify() { - decorated.verify(); + delegate.verify(); } public boolean matches(String methodName, Object[] args) { - if( !this.methodName.equals(methodName) ) return false; - if( args.length != constraints.length ) return false; - - for (int i = 0; i < args.length; i++) { - if( !constraints[i].eval(args[i]) ) return false; - } - - return decorated.matches( methodName, args ); + return this.methodName.equals(methodName) && constraints.matches(args); } public String getDescription() { - return DynamicUtil.methodToString(methodName, constraints); + return DynamicUtil.methodToString(methodName, constraints.getConstraints()); } // Implemented to aid visualisation in an IDE debugger Index: ExpectedCall.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Attic/ExpectedCall.java,v retrieving revision 1.2.2.6 retrieving revision 1.2.2.7 diff -u -r1.2.2.6 -r1.2.2.7 --- ExpectedCall.java 16 Apr 2003 22:17:04 -0000 1.2.2.6 +++ ExpectedCall.java 5 May 2003 22:44:33 -0000 1.2.2.7 @@ -8,6 +8,7 @@ /** * @author dev */ +//TODO rename to CallOnce public class ExpectedCall implements Callable { private Callable delegate; private boolean wasCalled = false; @@ -17,7 +18,7 @@ } public String getDescription() { - return delegate.getDescription() + " [mandatory]"; + return delegate.getDescription() + " [" + (wasCalled ? "" : "not ") + "called]"; } public Object call(Mock mock, String methodName, Object[] args) throws Throwable { @@ -26,7 +27,7 @@ } public boolean matches(String methodName, Object[] args) { - return (! wasCalled) && delegate.matches( methodName, args ); + return (!wasCalled) && delegate.matches( methodName, args ); } public void verify() { Index: DynamicUtil.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Attic/DynamicUtil.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- DynamicUtil.java 16 Apr 2003 16:31:44 -0000 1.1.2.1 +++ DynamicUtil.java 5 May 2003 22:44:33 -0000 1.1.2.2 @@ -6,9 +6,9 @@ import java.lang.reflect.Method; import java.lang.reflect.Proxy; - public class DynamicUtil { + //TODO rename to proxyToString public static String getProxyName(Object element) { if(Proxy.isProxyClass(element.getClass())) { try { @@ -20,7 +20,9 @@ } } + //TODO put in primitive array print handling return element.toString(); + } public static String methodToString( String name, Object[] args ) { @@ -39,12 +41,21 @@ for (int i = 0; i < elements.length; i++) { if( i > 0 ) buf.append(", "); - buf.append( "<" ); + Object element = elements[i]; - buf.append(DynamicUtil.getProxyName(element)); - buf.append( ">" ); - } - + //TODO put in primitive array print handling + if(element instanceof Object[]) { + buf.append( "[" ); + buf.append(join((Object[])element)); + buf.append( "]" ); + } else { + buf.append( "<" ); + buf.append(DynamicUtil.getProxyName(element)); + buf.append( ">" ); + } + } return buf.toString(); } + + } |
From: Tim M. <ma...@us...> - 2003-05-05 22:44:36
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/constraint In directory sc8-pr-cvs1:/tmp/cvs-serv15934/core/com/mockobjects/constraint Modified Files: Tag: DynamicMockExperiment IsEqual.java Log Message: - Changed Constraint[] usage to ConstraintMatcher to support Any constraint matching - Support for matching Object[] parameters Index: IsEqual.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/constraint/IsEqual.java,v retrieving revision 1.2.2.4 retrieving revision 1.2.2.5 diff -u -r1.2.2.4 -r1.2.2.5 --- IsEqual.java 16 Apr 2003 16:31:47 -0000 1.2.2.4 +++ IsEqual.java 5 May 2003 22:44:33 -0000 1.2.2.5 @@ -4,6 +4,8 @@ */ package com.mockobjects.constraint; +import java.util.Arrays; + import com.mockobjects.dynamic.DynamicUtil; @@ -15,16 +17,23 @@ { private Object _object; - public IsEqual( Object o ) { - _object = o; + public IsEqual( Object equalArg) { + if(equalArg instanceof Object[]) { + _object = Arrays.asList((Object[])equalArg); + } else { + _object = equalArg; + } } public boolean eval( Object arg ) { + if(arg instanceof Object[]) { + arg = Arrays.asList((Object[])arg); + } return arg.equals(_object); } - public String toString() { - return DynamicUtil.getProxyName(_object); + public String toString() { + return " = " + DynamicUtil.getProxyName(_object); } public boolean equals(Object anObject) { |
From: Jeff M. <cus...@us...> - 2003-05-01 09:26:56
|
Update of /cvsroot/mockobjects/mockobjects-java/src/j2ee/1.3/com/mockobjects/servlet In directory sc8-pr-cvs1:/tmp/cvs-serv27062/src/j2ee/1.3/com/mockobjects/servlet Modified Files: MockHttpServletRequest.java Log Message: Added expectaion for create session flag on getSession Index: MockHttpServletRequest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/j2ee/1.3/com/mockobjects/servlet/MockHttpServletRequest.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- MockHttpServletRequest.java 10 Apr 2003 10:39:12 -0000 1.15 +++ MockHttpServletRequest.java 1 May 2003 09:26:52 -0000 1.16 @@ -47,6 +47,7 @@ private final ReturnValue myParameterNames = new ReturnValue("parameter names"); private final ReturnValue requestDispatcher = new ReturnValue("request dispatcher"); private final ExpectationValue requestDispatcherURI = new ExpectationValue("request dispatcher uri"); + private final ExpectationValue createSession = new ExpectationValue("create session"); public void setupGetAttribute(Object anAttributeToReturn) { myAttributesToReturn.addObjectToReturn(anAttributeToReturn); @@ -236,16 +237,16 @@ return null; } - public void setupGetRequestDispatcher(RequestDispatcher requestDispatcher){ + public void setupGetRequestDispatcher(RequestDispatcher requestDispatcher) { this.requestDispatcher.setValue(requestDispatcher); } public RequestDispatcher getRequestDispatcher(String uri) { this.requestDispatcherURI.setActual(uri); - return (RequestDispatcher)requestDispatcher.getValue(); + return (RequestDispatcher) requestDispatcher.getValue(); } - public void setExpectedRequestDispatcherURI(String uri){ + public void setExpectedRequestDispatcherURI(String uri) { this.requestDispatcherURI.setExpected(uri); } @@ -291,9 +292,13 @@ this.myHttpSession.setValue(httpSession); } - public HttpSession getSession(boolean arg1) { - notImplemented(); - return null; + public void setExpectedCreateSession(boolean createSession) { + this.createSession.setExpected(createSession); + } + + public HttpSession getSession(boolean createSession) { + this.createSession.setActual(createSession); + return getSession(); } public void setupGetUserPrincipal(Principal userPrincipal) { |
From: Jeff M. <cus...@us...> - 2003-05-01 09:19:32
|
Update of /cvsroot/mockobjects/mockobjects-java/src/j2ee/1.3/com/mockobjects/servlet In directory sc8-pr-cvs1:/tmp/cvs-serv22959/src/j2ee/1.3/com/mockobjects/servlet Modified Files: MockHttpSession.java Log Message: Added setupGetAttribute instead of setAttribute Index: MockHttpSession.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/j2ee/1.3/com/mockobjects/servlet/MockHttpSession.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- MockHttpSession.java 24 Mar 2003 11:10:20 -0000 1.4 +++ MockHttpSession.java 1 May 2003 09:19:25 -0000 1.5 @@ -1,26 +1,22 @@ package com.mockobjects.servlet; -import com.mockobjects.ExpectationSet; -import com.mockobjects.MapEntry; -import com.mockobjects.MockObject; -import com.mockobjects.Verifiable; +import com.mockobjects.*; import javax.servlet.ServletContext; import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSessionContext; import java.util.Enumeration; -import java.util.HashMap; public class MockHttpSession extends MockObject implements HttpSession, Verifiable { private ExpectationSet myAttributes = new ExpectationSet("session attributes"); private ExpectationSet myRemovedAttributes = new ExpectationSet("removed session attributes"); - private HashMap myAttributeValues = new HashMap(); + private ReturnObjectBag myAttributeValues = new ReturnObjectBag("attributes"); private Enumeration attributeNames; private ServletContext servletContext; public Object getAttribute(String anAttributeName) { - return myAttributeValues.get(anAttributeName); + return myAttributeValues.getNextReturnObject(anAttributeName); } public void setupGetAttributeNames(Enumeration attributeNames) { @@ -93,15 +89,17 @@ public void removeAttribute(String anAttributeName) { myRemovedAttributes.addActual(anAttributeName); - myAttributeValues.remove(anAttributeName); } public void removeValue(String arg1) { notImplemented(); } + public void setupGetAttribute(String key, Object value){ + myAttributeValues.putObjectToReturn(key, value); + } + public void setAttribute(String aKey, Object aValue) { - myAttributeValues.put(aKey, aValue); myAttributes.addActual(new MapEntry(aKey, aValue)); } |
From: Tim M. <ma...@us...> - 2003-04-29 15:39:26
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv1119/com/mockobjects/dynamic Modified Files: Tag: DynamicMockExperiment Mock.java Log Message: made verifiable so that Verifier works on tests with these as fields, CJC Index: Mock.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Mock.java,v retrieving revision 1.16.2.10 retrieving revision 1.16.2.11 diff -u -r1.16.2.10 -r1.16.2.11 --- Mock.java 17 Apr 2003 16:17:28 -0000 1.16.2.10 +++ Mock.java 29 Apr 2003 15:39:05 -0000 1.16.2.11 @@ -10,13 +10,14 @@ import junit.framework.AssertionFailedError; +import com.mockobjects.Verifiable; import com.mockobjects.constraint.Constraint; /** * @author dev */ -public class Mock implements InvocationHandler { +public class Mock implements InvocationHandler,Verifiable { private String name; private Object proxy; private CallFactory callFactory; |
From: James H. <jw...@al...> - 2003-04-28 14:09:45
|
I'm trying to get a build of the latest MockObjects code base using Eclipse. I've connected to the CVS repository and checked things out and tried to build things using Ant, but I'm having problems getting the code to compile. My current problem involves references to JUnit. I'm sure I can come up with a way to make the thing build in Eclipse, but it would seem that all I should have to do is check things out in from CVS and do an Ant build. Are there any other specific things I need to setup/configure in Eclipse to make the Ant build script work correctly? Thanks. -- James Howe |
From: Jeff M. <cus...@us...> - 2003-04-23 11:53:41
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects In directory sc8-pr-cvs1:/tmp/cvs-serv29790/src/core/com/mockobjects Modified Files: ReturnObjectList.java ReturnObjectBag.java Log Message: Allow multiple return values from executeQuery Index: ReturnObjectList.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/ReturnObjectList.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ReturnObjectList.java 30 Aug 2002 14:49:57 -0000 1.4 +++ ReturnObjectList.java 23 Apr 2003 11:52:46 -0000 1.5 @@ -31,7 +31,7 @@ /** * Add a next object to the end of the list. - * @param anOjectToReturn object to be added to the list + * @param anObjectToReturn object to be added to the list */ public void addObjectToReturn(Object anObjectToReturn){ myObjects.add(anObjectToReturn); Index: ReturnObjectBag.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/ReturnObjectBag.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ReturnObjectBag.java 10 Apr 2003 10:33:22 -0000 1.3 +++ ReturnObjectBag.java 23 Apr 2003 11:52:46 -0000 1.4 @@ -59,6 +59,30 @@ } /** + * Places an int into the list of return objects for a particular key. The value can be retrieved + * using the getNextReturnInt method + * @param key the key against which the object will be stored + * @param value the value to be added to the list for that key + * @see ReturnObjectList#addObjectToReturn + * @see #getNextReturnInt + */ + public void putObjectToReturn(Object key, int value) { + putObjectToReturn(key, new Integer(value)); + } + + /** + * Places an boolean into the list of return objects for a particular key. The value can be retrieved + * using the getNextReturnBoolean method + * @param key the key against which the object will be stored + * @param value the value to be added to the list for that key + * @see ReturnObjectList#addObjectToReturn + * @see #getNextReturnBoolean + */ + public void putObjectToReturn(Object key, boolean value) { + putObjectToReturn(key, new Boolean(value)); + } + + /** * Checks each the list for each key to verify that all no objects remain * in the list for that key. * @see ReturnObjectList#verify @@ -98,4 +122,15 @@ return getNextReturnObject(new Integer(key)); } + public Hashtable getHashTable(){ + return returnObjectLists; + } + + public int getNextReturnInt(Object key) { + return ((Integer)getNextReturnObject(key)).intValue(); + } + + public boolean getNextReturnBoolean(Object key) { + return ((Boolean)getNextReturnObject(key)).booleanValue(); + } } |
From: Jeff M. <cus...@us...> - 2003-04-23 11:53:39
|
Update of /cvsroot/mockobjects/mockobjects-java/src/jdk/common/com/mockobjects/sql In directory sc8-pr-cvs1:/tmp/cvs-serv29790/src/jdk/common/com/mockobjects/sql Modified Files: CommonMockPreparedStatement.java CommonMockStatement.java MockResultSet.java Log Message: Allow multiple return values from executeQuery Index: CommonMockPreparedStatement.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/jdk/common/com/mockobjects/sql/CommonMockPreparedStatement.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- CommonMockPreparedStatement.java 9 Dec 2002 18:20:12 -0000 1.3 +++ CommonMockPreparedStatement.java 23 Apr 2003 11:52:46 -0000 1.4 @@ -78,8 +78,6 @@ abstract class CommonMockPreparedStatement extends CommonMockStatement implements PreparedStatement { -// -------------------------------------------------------------------- fields - private ExpectationSet mySetParameters = new ExpectationSet("CommonMockPreparedStatement.setParameters"); @@ -89,8 +87,12 @@ private ExpectationSet myTargetSQLTypes = new ExpectationSet("CommonMockPreparedStatement.targetSQLTypes"); + private final ReturnObjectList myResultSets = new ReturnObjectList("result sets"); + private final ReturnObjectList executeUpdates = new ReturnObjectList("update count"); -// -------------------------------------------------------------- addExpected* + public void addResultSet(MockResultSet aResultSet) { + myResultSets.addObjectToReturn(aResultSet); + } public void addExpectedSetParameter(int parameterIndex, int intValue) { addExpectedSetParameter(parameterIndex, new Integer(intValue)); @@ -140,14 +142,26 @@ * Returns executeQuery(String) with an empty String. */ public ResultSet executeQuery() throws SQLException { - return executeQuery(""); + innerExecute(); + return (ResultSet)myResultSets.nextReturnObject(); } /** - * Returns executeUpdate(String) with an empty String. + * Added value to be returned by executeUpdate() + * @param count + * @see #executeUpdate + */ + public void addUpdateCount(int count){ + this.executeUpdates.addObjectToReturn(count); + } + + /** + * Returns value set with addUpdateCount + * @see #addUpdateCount */ public int executeUpdate() throws SQLException { - return executeUpdate(""); + innerExecute(); + return ((Integer)executeUpdates.nextReturnObject()).intValue(); } public void setInt(int parameterIndex, int x) throws SQLException { Index: CommonMockStatement.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/jdk/common/com/mockobjects/sql/CommonMockStatement.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- CommonMockStatement.java 9 Dec 2002 18:20:10 -0000 1.3 +++ CommonMockStatement.java 23 Apr 2003 11:52:46 -0000 1.4 @@ -1,9 +1,8 @@ package com.mockobjects.sql; import com.mockobjects.ExpectationCounter; -import com.mockobjects.ExpectationValue; import com.mockobjects.MockObject; -import com.mockobjects.ReturnObjectList; +import com.mockobjects.ReturnObjectBag; import java.sql.*; @@ -12,29 +11,29 @@ */ abstract class CommonMockStatement extends MockObject implements Statement { protected final ExpectationCounter myCloseCalls = new ExpectationCounter("CommonMockStatement.closeCalls"); - protected final ExpectationCounter myExecuteCalls = new ExpectationCounter("CommonMockStatement.executeCalls"); - protected final ExpectationValue myQueryString = new ExpectationValue("CommonMockStatement.queryString"); - protected final ReturnObjectList myResultSets = new ReturnObjectList("result set"); + private final ReturnObjectBag executeQueryResults = new ReturnObjectBag("executeQuery"); + private final ReturnObjectBag executeUpdateResults = new ReturnObjectBag("executeUpdate"); + private final ReturnObjectBag executeResults = new ReturnObjectBag("execute"); private int myUpdateCount = 0; private SQLException myExecuteException = null; private Connection myConnection = null; - public void setExpectedExecuteCalls(int callCount) { - myExecuteCalls.setExpected(callCount); + public void addExpectedExecuteQuery(String queryString, ResultSet resultSet) { + executeQueryResults.putObjectToReturn(queryString, resultSet); } - public void setExpectedQueryString(String queryString) { - myQueryString.setExpected(queryString); + public void addExpectedExecuteUpdate(String queryString, int updateCount) { + executeUpdateResults.putObjectToReturn(queryString, updateCount); } - public void setExpectedCloseCalls(int callCount) { - myCloseCalls.setExpected(callCount); + public void addExpectedExecute(String queryString, boolean success) { + executeResults.putObjectToReturn(queryString, success); } - public void addResultSet(MockResultSet aResultSet) { - myResultSets.addObjectToReturn(aResultSet); + public void setExpectedCloseCalls(int callCount) { + myCloseCalls.setExpected(callCount); } public void setupConnection(Connection conn) { @@ -50,7 +49,6 @@ } protected void innerExecute() throws SQLException { - myExecuteCalls.inc(); if (null != myExecuteException) { throw myExecuteException; } @@ -61,20 +59,18 @@ } public boolean execute(String sql) throws SQLException { - notImplemented(); - return true; + innerExecute(); + return executeResults.getNextReturnBoolean(sql); } public ResultSet executeQuery(String sql) throws SQLException { - myQueryString.setActual(sql); innerExecute(); - return (ResultSet)myResultSets.nextReturnObject(); + return (ResultSet) executeQueryResults.getNextReturnObject(sql); } public int executeUpdate(String sql) throws SQLException { - myQueryString.setActual(sql); innerExecute(); - return myUpdateCount; + return executeUpdateResults.getNextReturnInt(sql); } public int getMaxFieldSize() throws SQLException { Index: MockResultSet.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/jdk/common/com/mockobjects/sql/MockResultSet.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- MockResultSet.java 10 Apr 2003 10:37:39 -0000 1.6 +++ MockResultSet.java 23 Apr 2003 11:52:46 -0000 1.7 @@ -3,6 +3,7 @@ import com.mockobjects.ExpectationCounter; import com.mockobjects.MockObject; import com.mockobjects.ReturnValue; +import com.mockobjects.util.AssertMo; import java.io.InputStream; import java.io.Reader; @@ -248,7 +249,15 @@ } public String getString(int columnIndex) throws SQLException { - return (String) getObject(columnIndex); + final Object object = getObject(columnIndex); + if (object != null) { + AssertMo.assertTrue("Column " + columnIndex + " in " + name + " is a " + + object.getClass().getName() + " not a String", object instanceof String); + + return (String) object; + } else { + return null; + } } public String getString(String columnName) throws SQLException { |
From: Jeff M. <cus...@us...> - 2003-04-23 11:53:27
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects In directory sc8-pr-cvs1:/tmp/cvs-serv29790/src/core/test/mockobjects Modified Files: TestReturnObjectBag.java Log Message: Allow multiple return values from executeQuery Index: TestReturnObjectBag.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/TestReturnObjectBag.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- TestReturnObjectBag.java 10 Apr 2003 10:33:57 -0000 1.3 +++ TestReturnObjectBag.java 23 Apr 2003 11:52:47 -0000 1.4 @@ -41,6 +41,20 @@ bag.verify(); } + public void testReturnInt() { + bag.putObjectToReturn(KEY1, 1); + + assertEquals("Should be 1", 1, bag.getNextReturnInt(KEY1)); + bag.verify(); + } + + public void testReturnBoolean() { + bag.putObjectToReturn(KEY1, true); + + assertEquals("Should be true", true, bag.getNextReturnBoolean(KEY1)); + bag.verify(); + } + public void testShortKey(){ bag.putObjectToReturn(SHORT_KEY1, VALUE_ONE); bag.putObjectToReturn(SHORT_KEY2, VALUE_TWO); |
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv26046/core/test/mockobjects/dynamic Modified Files: Tag: DynamicMockExperiment MockTest.java MockCallableAddable.java CallBagTest.java CallSequenceTest.java Log Message: expectAndReturn has a higher precendence than matchAndReturn. This was previously unclear and could give strange results. this can be used to provide default method return values which can then be overridden in specific tests where there needs to be a precise expectation. AddableCallable interface has seperate addExpect and addMatch methods which open the door to simpler testing and less reliance on the DefaultCallFactory (this hasn't been implemented) Index: MockTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockTest.java,v retrieving revision 1.8.2.8 retrieving revision 1.8.2.9 diff -u -r1.8.2.8 -r1.8.2.9 --- MockTest.java 16 Apr 2003 22:48:21 -0000 1.8.2.8 +++ MockTest.java 17 Apr 2003 16:17:25 -0000 1.8.2.9 @@ -57,7 +57,7 @@ mockCallFactory.addExpectedCreateExpectedCall(mockCallMatch); mockCallFactory.setupCreateExpectedCall(mockExpectedCall); - mockCallableAddable.addExpectedAdd(mockExpectedCall); + mockCallableAddable.addExpectedAddExpect(mockExpectedCall); mock.expect(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS); @@ -73,7 +73,7 @@ mockCallFactory.addExpectedCreateExpectedCall(mockCallMatch); mockCallFactory.setupCreateExpectedCall(mockExpectedCall); - mockCallableAddable.addExpectedAdd(mockExpectedCall); + mockCallableAddable.addExpectedAddExpect(mockExpectedCall); mock.expectAndReturn(METHOD_NOARGANDRETURN_NAME, METHOD_NOARGANDRETURN_RESULT); @@ -89,7 +89,7 @@ mockCallFactory.addExpectedCreateExpectedCall(mockCallMatch); mockCallFactory.setupCreateExpectedCall(mockExpectedCall); - mockCallableAddable.addExpectedAdd(mockExpectedCall); + mockCallableAddable.addExpectedAddExpect(mockExpectedCall); mock.expectAndThrow(METHOD_NOARGANDRETURN_NAME, METHOD_EXCEPTION); @@ -105,7 +105,7 @@ mockCallFactory.addExpectedCreateExpectedCall(mockCallMatch); mockCallFactory.setupCreateExpectedCall(mockExpectedCall); - mockCallableAddable.addExpectedAdd(mockExpectedCall); + mockCallableAddable.addExpectedAddExpect(mockExpectedCall); mock.expectAndThrow(METHOD_ONEARG_NAME, METHOD_ONEARG_ARGS[0], METHOD_EXCEPTION); @@ -121,7 +121,7 @@ mockCallFactory.addExpectedCreateExpectedCall(mockCallMatch); mockCallFactory.setupCreateExpectedCall(mockExpectedCall); - mockCallableAddable.addExpectedAdd(mockExpectedCall); + mockCallableAddable.addExpectedAddExpect(mockExpectedCall); mock.expect(METHOD_NOARG_NAME); @@ -137,7 +137,7 @@ mockCallFactory.addExpectedCreateExpectedCall(mockCallMatch); mockCallFactory.setupCreateExpectedCall(mockExpectedCall); - mockCallableAddable.addExpectedAdd(mockExpectedCall); + mockCallableAddable.addExpectedAddExpect(mockExpectedCall); mock.expect(METHOD_ONEARG_NAME, METHOD_ONEARG_ARGS[0]); @@ -153,8 +153,8 @@ mockCallFactory.addExpectedCreateExpectedCall(mockCallMatch); mockCallFactory.setupCreateExpectedCall(mockExpectedCall); - mockCallableAddable.addExpectedAdd(mockExpectedCall); - mockCallableAddable.setupCallReturn(METHOD_TWOARG_RESULT); + mockCallableAddable.addExpectedAddExpect(mockExpectedCall); + mockCallableAddable.setupCall(METHOD_TWOARG_RESULT); mock.expectAndReturn(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, METHOD_TWOARG_RESULT); @@ -170,8 +170,8 @@ mockCallFactory.addExpectedCreateExpectedCall(mockCallMatch); mockCallFactory.setupCreateExpectedCall(mockExpectedCall); - mockCallableAddable.addExpectedAdd(mockExpectedCall); - mockCallableAddable.setupCallReturn(METHOD_TWOARG_RESULT); + mockCallableAddable.addExpectedAddExpect(mockExpectedCall); + mockCallableAddable.setupCall(METHOD_TWOARG_RESULT); mock.expectAndThrow(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, METHOD_EXCEPTION); @@ -187,8 +187,8 @@ mockCallFactory.addExpectedCreateExpectedCall(mockCallMatch); mockCallFactory.setupCreateExpectedCall(mockExpectedCall); - mockCallableAddable.addExpectedAdd(mockExpectedCall); - mockCallableAddable.setupCallReturn(METHOD_ONEARG_RESULT); + mockCallableAddable.addExpectedAddExpect(mockExpectedCall); + mockCallableAddable.setupCall(METHOD_ONEARG_RESULT); mock.expectAndReturn(METHOD_ONEARG_NAME, METHOD_ONEARG_ARGS[0], METHOD_ONEARG_RESULT); @@ -202,8 +202,8 @@ mockCallFactory.addExpectedCreateCallMatch(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockReturnStub); mockCallFactory.setupCreateCallMatch(mockCallMatch); - mockCallableAddable.addExpectedAdd(mockCallMatch); - mockCallableAddable.setupCallReturn(METHOD_TWOARG_RESULT); + mockCallableAddable.addExpectedAddMatch(mockCallMatch); + mockCallableAddable.setupCall(METHOD_TWOARG_RESULT); mock.matchAndReturn(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, METHOD_TWOARG_RESULT); @@ -217,8 +217,8 @@ mockCallFactory.addExpectedCreateCallMatch(METHOD_NOARG_NAME, C.NO_ARGS, mockThrowStub); mockCallFactory.setupCreateCallMatch(mockCallMatch); - mockCallableAddable.addExpectedAdd(mockCallMatch); - mockCallableAddable.setupCallReturn(METHOD_NOARGANDRETURN_RESULT); + mockCallableAddable.addExpectedAddMatch(mockCallMatch); + mockCallableAddable.setupCall(METHOD_NOARGANDRETURN_RESULT); mock.matchAndThrow(METHOD_NOARG_NAME, METHOD_EXCEPTION); @@ -232,8 +232,8 @@ mockCallFactory.addExpectedCreateCallMatch(METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockThrowStub); mockCallFactory.setupCreateCallMatch(mockCallMatch); - mockCallableAddable.addExpectedAdd(mockCallMatch); - mockCallableAddable.setupCallReturn(METHOD_ONEARG_RESULT); + mockCallableAddable.addExpectedAddMatch(mockCallMatch); + mockCallableAddable.setupCall(METHOD_ONEARG_RESULT); mock.matchAndThrow(METHOD_ONEARG_NAME, METHOD_ONEARG_ARGS[0], METHOD_EXCEPTION); @@ -247,8 +247,8 @@ mockCallFactory.addExpectedCreateCallMatch(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockThrowStub); mockCallFactory.setupCreateCallMatch(mockCallMatch); - mockCallableAddable.addExpectedAdd(mockCallMatch); - mockCallableAddable.setupCallReturn(METHOD_TWOARG_RESULT); + mockCallableAddable.addExpectedAddMatch(mockCallMatch); + mockCallableAddable.setupCall(METHOD_TWOARG_RESULT); mock.matchAndThrow(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, METHOD_EXCEPTION); @@ -262,8 +262,8 @@ mockCallFactory.addExpectedCreateCallMatch(METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockReturnStub); mockCallFactory.setupCreateCallMatch(mockCallMatch); - mockCallableAddable.addExpectedAdd(mockCallMatch); - mockCallableAddable.setupCallReturn(METHOD_ONEARG_RESULT); + mockCallableAddable.addExpectedAddMatch(mockCallMatch); + mockCallableAddable.setupCall(METHOD_ONEARG_RESULT); mock.matchAndReturn(METHOD_ONEARG_NAME, METHOD_ONEARG_ARGS[0], METHOD_ONEARG_RESULT); @@ -277,8 +277,8 @@ mockCallFactory.addExpectedCreateCallMatch(METHOD_NOARG_NAME, C.NO_ARGS, mockReturnStub); mockCallFactory.setupCreateCallMatch(mockCallMatch); - mockCallableAddable.addExpectedAdd(mockCallMatch); - mockCallableAddable.setupCallReturn(METHOD_ONEARG_RESULT); + mockCallableAddable.addExpectedAddMatch(mockCallMatch); + mockCallableAddable.setupCall(METHOD_ONEARG_RESULT); mock.matchAndReturn(METHOD_NOARG_NAME, METHOD_NOARGANDRETURN_RESULT); @@ -290,7 +290,7 @@ throws Throwable { final String originalMessage = "original message"; - mockCallableAddable.setupCallThrow(new AssertionFailedError(originalMessage)); + mockCallableAddable.setupCall(new AssertionFailedError(originalMessage)); try { proxy.noArgMethodVoid(); @@ -308,14 +308,14 @@ throws Throwable { final String result = "configured result"; - mockCallableAddable.setupCallReturn(result); + mockCallableAddable.setupCall(result); assertSame("result is returned by mock", result, proxy.oneArgMethod(METHOD_TWOARG_ARGS[0])); } public void testMockProxySendsAllArgument() throws Throwable { - mockCallableAddable.setExpectedCall(mock, METHOD_TWOARG_NAME, METHOD_TWOARG_ARGS); - mockCallableAddable.setupCallReturn("result ignored"); + mockCallableAddable.addExpectedCall(mock, METHOD_TWOARG_NAME, METHOD_TWOARG_ARGS); + mockCallableAddable.setupCall("result ignored"); proxy.twoArgMethod(METHOD_TWOARG_ARGS[0], METHOD_TWOARG_ARGS[1]); @@ -324,8 +324,8 @@ public void testMockProxySendsEmptyArrayWhenNoArguments() throws Exception { - mockCallableAddable.setExpectedCall(mock, METHOD_NOARG_NAME, METHOD_NOARG_ARGS); - mockCallableAddable.setupCallReturn("result ignored"); + mockCallableAddable.addExpectedCall(mock, METHOD_NOARG_NAME, METHOD_NOARG_ARGS); + mockCallableAddable.setupCall("result ignored"); proxy.noArgMethodVoid(); @@ -337,7 +337,7 @@ throws Throwable { final Throwable throwable = new DummyThrowable(); - mockCallableAddable.setupCallReturn(new ThrowStub(throwable)); + mockCallableAddable.setupCall(new ThrowStub(throwable)); try { proxy.noArgMethodVoid(); @@ -367,7 +367,7 @@ CallStub ret = new ReturnStub(new Boolean(IGNORED_RESULT)); mockCallFactory.setupCreateReturnStub(ret); mockCallFactory.setupCreateCallMatch(new CallMatch("call",C.anyArgs(1),ret)); - mockCallableAddable.setupCallReturn(new Boolean(false)); + mockCallableAddable.setupCall(new Boolean(false)); mock.matchAndReturn("call", C.anyArgs(1), IGNORED_RESULT); assertFalse("Should handle proxy inequality by calling through", proxy.equals("not a proxy")); Index: MockCallableAddable.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/MockCallableAddable.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- MockCallableAddable.java 14 Apr 2003 08:46:29 -0000 1.1.2.1 +++ MockCallableAddable.java 17 Apr 2003 16:17:26 -0000 1.1.2.2 @@ -1,38 +1,143 @@ package test.mockobjects.dynamic; - import com.mockobjects.*; -import com.mockobjects.dynamic.CallableAddable; + import com.mockobjects.dynamic.Callable; +import com.mockobjects.dynamic.CallableAddable; +import com.mockobjects.dynamic.Mock; + +//Mock modified for []args +public class MockCallableAddable extends MockObject implements CallableAddable { + private ExpectationCounter myAddMatchCalls = new ExpectationCounter("com.mockobjects.dynamic.CallableAddable AddMatchCalls"); + private ExpectationList myAddMatchParameter0Values = new ExpectationList("com.mockobjects.dynamic.CallableAddable AddMatchParameter0Values"); + private ExpectationCounter myAddExpectCalls = new ExpectationCounter("com.mockobjects.dynamic.CallableAddable AddExpectCalls"); + private ExpectationList myAddExpectParameter0Values = new ExpectationList("com.mockobjects.dynamic.CallableAddable AddExpectParameter0Values"); + private ExpectationCounter myMatchesCalls = new ExpectationCounter("com.mockobjects.dynamic.CallableAddable MatchesCalls"); + private ReturnValues myActualMatchesReturnValues = new ReturnValues(true); + private ExpectationList myMatchesParameter0Values = new ExpectationList("com.mockobjects.dynamic.CallableAddable MatchesParameter0Values"); + private ExpectationList myMatchesParameter1Values = new ExpectationList("com.mockobjects.dynamic.CallableAddable MatchesParameter1Values"); + private ExpectationCounter myGetDescriptionCalls = new ExpectationCounter("com.mockobjects.dynamic.CallableAddable GetDescriptionCalls"); + private ReturnValues myActualGetDescriptionReturnValues = new ReturnValues(true); + private ExpectationCounter myCallCalls = new ExpectationCounter("com.mockobjects.dynamic.CallableAddable CallCalls"); + private ReturnValues myActualCallReturnValues = new ReturnValues(true); + private ExpectationList myCallParameter0Values = new ExpectationList("com.mockobjects.dynamic.CallableAddable CallParameter0Values"); + private ExpectationList myCallParameter1Values = new ExpectationList("com.mockobjects.dynamic.CallableAddable CallParameter1Values"); + private ExpectationList myCallParameter2Values = new ExpectationList("com.mockobjects.dynamic.CallableAddable CallParameter2Values"); + private ExpectationCounter myVerifyCalls = new ExpectationCounter("com.mockobjects.dynamic.CallableAddable VerifyCalls"); + + public void setExpectedAddMatchCalls(int calls) { + myAddMatchCalls.setExpected(calls); + } + + public void addExpectedAddMatch(Callable arg0) { + myAddMatchParameter0Values.addExpected(arg0); + } + + public void addMatch(Callable arg0) { + myAddMatchCalls.inc(); + myAddMatchParameter0Values.addActual(arg0); + } + + public void setExpectedAddExpectCalls(int calls) { + myAddExpectCalls.setExpected(calls); + } + + public void addExpectedAddExpect(Callable arg0) { + myAddExpectParameter0Values.addExpected(arg0); + } + + public void addExpect(Callable arg0) { + myAddExpectCalls.inc(); + myAddExpectParameter0Values.addActual(arg0); + } + + public void setExpectedMatchesCalls(int calls) { + myMatchesCalls.setExpected(calls); + } + + public void addExpectedMatches(String arg0, Object[] arg1) { + myMatchesParameter0Values.addExpected(arg0); + myMatchesParameter1Values.addExpected(arg1); + } + + public boolean matches(String arg0, Object[] arg1) { + myMatchesCalls.inc(); + myMatchesParameter0Values.addActual(arg0); + myMatchesParameter1Values.addActual(arg1); + + Object nextReturnValue = myActualMatchesReturnValues.getNext(); + + return ((Boolean) nextReturnValue).booleanValue(); + } + + public void setupMatches(boolean arg) { + myActualMatchesReturnValues.add(new Boolean(arg)); + } + + public void setExpectedGetDescriptionCalls(int calls) { + myGetDescriptionCalls.setExpected(calls); + } + + public String getDescription() { + myGetDescriptionCalls.inc(); + + Object nextReturnValue = myActualGetDescriptionReturnValues.getNext(); + + return (String) nextReturnValue; + } + + public void setupGetDescription(String arg) { + myActualGetDescriptionReturnValues.add(arg); + } + + public void setExpectedCallCalls(int calls) { + myCallCalls.setExpected(calls); + } + + public void addExpectedCall(Mock arg0, String arg1, Object[] arg2) { + myCallParameter0Values.addExpected(arg0); + myCallParameter1Values.addExpected(arg1); + myCallParameter2Values.addExpectedMany(arg2); + } + + public Object call(Mock arg0, String arg1, Object[] arg2) + throws Throwable { + myCallCalls.inc(); + myCallParameter0Values.addActual(arg0); + myCallParameter1Values.addActual(arg1); + myCallParameter2Values.addActualMany(arg2); -public class MockCallableAddable extends MockCallable implements CallableAddable{ - private ExpectationCounter myAddCalls = new ExpectationCounter("MockCallableAddable.add(Callable)"); - private ReturnValues myActualAddReturnValues = new VoidReturnValues("MockCallableAddable.add(Callable)", true); - private ExpectationList myAddParameter0Values = new ExpectationList("MockCallableAddable.add(Callable) com.mockobjects.dynamic.Callable"); + Object nextReturnValue = myActualCallReturnValues.getNext(); - public void setExpectedAddCalls(int calls){ - myAddCalls.setExpected(calls); + return (Object) nextReturnValue; } - public void addExpectedAdd(Callable arg0){ - myAddParameter0Values.addExpected(arg0); + public void setupCall(Object arg) { + myActualCallReturnValues.add(arg); } - public void add(Callable arg0){ - myAddCalls.inc(); - myAddParameter0Values.addActual(arg0); - Object nextReturnValue = myActualAddReturnValues.getNext(); - if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException) - throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException(); + public void setExpectedVerifyCalls(int calls) { + myVerifyCalls.setExpected(calls); } - public void setupExceptionAdd(Throwable arg){ - myActualAddReturnValues.add(new ExceptionalReturnValue(arg)); + /** @deprected use verifyExpectations as this is a mockmock */ + public void verify() { + myVerifyCalls.inc(); } - public void verifyExpectations(){ - super.verifyExpectations(); - myAddCalls.verify(); - myAddParameter0Values.verify(); + public void verifyExpectations() { + myAddMatchCalls.verify(); + myAddMatchParameter0Values.verify(); + myAddExpectCalls.verify(); + myAddExpectParameter0Values.verify(); + myMatchesCalls.verify(); + myMatchesParameter0Values.verify(); + myMatchesParameter1Values.verify(); + myGetDescriptionCalls.verify(); + myCallCalls.verify(); + myCallParameter0Values.verify(); + myCallParameter1Values.verify(); + myCallParameter2Values.verify(); + myVerifyCalls.verify(); } } Index: CallBagTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/CallBagTest.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- CallBagTest.java 16 Apr 2003 22:21:06 -0000 1.1.2.1 +++ CallBagTest.java 17 Apr 2003 16:17:27 -0000 1.1.2.2 @@ -55,8 +55,8 @@ methodB.setExpectedCallCount(0); - callSet.add(methodA); - callSet.add(methodB); + callSet.addExpect(methodA); + callSet.addExpect(methodB); assertSame("expected result from method A", METHOD_A_RESULT, callSet.call(unusedMock, METHOD_A_NAME, METHOD_A_ARGS)); @@ -64,6 +64,18 @@ methodA.verifyExpectations(); methodB.verifyExpectations(); } + + public void testExpectOverridesMatch() throws Throwable { + + Callable methodAMatch = new CallMatch(METHOD_A_NAME,METHOD_A_CONSTRAINTS, new ReturnStub("result1")); + Callable anotherMethodAMatch = new CallMatch(METHOD_A_NAME,METHOD_A_CONSTRAINTS, new ReturnStub("result2")); + + callSet.addMatch(methodAMatch); + callSet.addExpect(new ExpectedCall(anotherMethodAMatch)); + + assertSame("expected result from method B, as expect has precendence over match", "result2", + callSet.call(unusedMock, METHOD_A_NAME, METHOD_A_ARGS)); + } public void testCallPassedToContainedElementsOtherOrder() throws Throwable { @@ -76,8 +88,8 @@ methodB.setExpectedMatches(METHOD_B_NAME, METHOD_B_ARGS); methodB.setupMatchesReturn(true); - callSet.add(methodA); - callSet.add(methodB); + callSet.addExpect(methodA); + callSet.addExpect(methodB); assertSame("expected result from method B", METHOD_B_RESULT, callSet.call(unusedMock, METHOD_B_NAME, METHOD_B_ARGS)); @@ -92,7 +104,7 @@ mockCallable.setupCallReturn(result); mockCallable.setupMatchesReturn(true); - callSet.add(mockCallable); + callSet.addExpect(mockCallable); assertSame("result is returned by mock", result, callSet.call(unusedMock, "method", new Object[0])); } @@ -104,7 +116,7 @@ mockCallable.setupMatchesReturn(true); mockCallable.setupCallThrow(throwable); - callSet.add(mockCallable); + callSet.addExpect(mockCallable); try { callSet.call(unusedMock, "hello", new String[0]); @@ -130,8 +142,8 @@ methodB.setExpectedCallCount(0); methodB.setupGetDescription("***methodB-description****"); - callSet.add(methodA); - callSet.add(methodB); + callSet.addExpect(methodA); + callSet.addExpect(methodB); try { callSet.call(unusedMock, methodCName, methodCArgs); @@ -154,8 +166,8 @@ methodA.setExpectedVerifyCalls(1); methodB.setExpectedVerifyCalls(1); - callSet.add(methodA); - callSet.add(methodB); + callSet.addExpect(methodA); + callSet.addExpect(methodB); callSet.verify(); methodA.verifyExpectations(); @@ -166,7 +178,7 @@ throws Exception { methodA.setExpectedVerifyCalls(1); methodA.setupVerifyThrow(new AssertionFailedError("verify failed")); - callSet.add(methodA); + callSet.addExpect(methodA); try { callSet.verify(); Index: CallSequenceTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/CallSequenceTest.java,v retrieving revision 1.5.2.3 retrieving revision 1.5.2.4 diff -u -r1.5.2.3 -r1.5.2.4 --- CallSequenceTest.java 16 Apr 2003 22:48:21 -0000 1.5.2.3 +++ CallSequenceTest.java 17 Apr 2003 16:17:27 -0000 1.5.2.4 @@ -6,8 +6,12 @@ import com.mockobjects.constraint.Constraint; import com.mockobjects.dynamic.C; +import com.mockobjects.dynamic.CallMatch; import com.mockobjects.dynamic.CallSequence; +import com.mockobjects.dynamic.Callable; +import com.mockobjects.dynamic.ExpectedCall; import com.mockobjects.dynamic.Mock; +import com.mockobjects.dynamic.ReturnStub; import com.mockobjects.util.AssertMo; @@ -40,7 +44,7 @@ mockCallable.setupMatchesReturn(true); mockCallable.setupCallThrow(throwable); - callSequence.add(mockCallable); + callSequence.addExpect(mockCallable); try { callSequence.call(unusedMock, "hello", new String[0]); @@ -64,7 +68,7 @@ public void testCallFailsWithTooManyCalls() throws Throwable { mockCallable.setupMatchesReturn(true); mockCallable.setupCallReturn(METHOD_A_RESULT); - callSequence.add(mockCallable); + callSequence.addExpect(mockCallable); callSequence.call(unusedMock, "willdefinitelyMatch", new Object[0]); try { @@ -86,8 +90,8 @@ methodB.setExpectedCallCount(0); - callSequence.add(methodA); - callSequence.add(methodB); + callSequence.addExpect(methodA); + callSequence.addExpect(methodB); assertSame("expected result from method A", METHOD_A_RESULT, callSequence.call(unusedMock, METHOD_A_NAME, METHOD_A_ARGS)); @@ -102,8 +106,8 @@ methodA.setupGetDescription("***methodA-description****"); methodB.setupGetDescription("***methodB-description****"); - callSequence.add(methodA); - callSequence.add(methodB); + callSequence.addExpect(methodA); + callSequence.addExpect(methodB); try { assertSame("expected result from method B", METHOD_B_RESULT, callSequence.call(unusedMock, METHOD_B_NAME, METHOD_B_ARGS)); @@ -130,7 +134,7 @@ mockCallable.setupCallReturn(result); mockCallable.setupMatchesReturn(true); - callSequence.add(mockCallable); + callSequence.addExpect(mockCallable); assertSame("result is returned by mock", result, callSequence.call(unusedMock, "method", new Object[0])); } @@ -152,8 +156,8 @@ methodB.setExpectedCallCount(0); methodB.setupGetDescription("***methodB-description****"); - callSequence.add(methodA); - callSequence.add(methodB); + callSequence.addExpect(methodA); + callSequence.addExpect(methodB); try { callSequence.call(unusedMock, methodCName, methodCArgs); @@ -176,8 +180,8 @@ methodA.setExpectedVerifyCalls(1); methodB.setExpectedVerifyCalls(1); - callSequence.add(methodA); - callSequence.add(methodB); + callSequence.addExpect(methodA); + callSequence.addExpect(methodB); callSequence.verify(); methodA.verifyExpectations(); @@ -188,7 +192,7 @@ throws Exception { methodA.setExpectedVerifyCalls(1); methodA.setupVerifyThrow(new AssertionFailedError("verify failed")); - callSequence.add(methodA); + callSequence.addExpect(methodA); try { callSequence.verify(); @@ -199,5 +203,17 @@ } fail("Should have got a failure for contained element failing"); + } + + public void testExpectOverridesMatch() throws Throwable { + + Callable methodAMatch = new CallMatch(METHOD_A_NAME,METHOD_A_CONSTRAINTS, new ReturnStub("result1")); + Callable anotherMethodAMatch = new CallMatch(METHOD_A_NAME,METHOD_A_CONSTRAINTS, new ReturnStub("result2")); + + callSequence.addMatch(methodAMatch); + callSequence.addExpect(new ExpectedCall(anotherMethodAMatch)); + + assertSame("expected result from method B, as expect has precendence over match", "result2", + callSequence.call(unusedMock, METHOD_A_NAME, METHOD_A_ARGS)); } } |
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv26046/core/com/mockobjects/dynamic Modified Files: Tag: DynamicMockExperiment CallableAddable.java Mock.java CallBag.java CallSequence.java Log Message: expectAndReturn has a higher precendence than matchAndReturn. This was previously unclear and could give strange results. this can be used to provide default method return values which can then be overridden in specific tests where there needs to be a precise expectation. AddableCallable interface has seperate addExpect and addMatch methods which open the door to simpler testing and less reliance on the DefaultCallFactory (this hasn't been implemented) Index: CallableAddable.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Attic/CallableAddable.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- CallableAddable.java 14 Apr 2003 08:46:27 -0000 1.1.2.1 +++ CallableAddable.java 17 Apr 2003 16:17:27 -0000 1.1.2.2 @@ -4,5 +4,6 @@ package com.mockobjects.dynamic; public interface CallableAddable extends Callable { - public abstract void add(Callable call); + void addExpect(Callable call); + void addMatch(Callable call); } Index: Mock.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Mock.java,v retrieving revision 1.16.2.9 retrieving revision 1.16.2.10 diff -u -r1.16.2.9 -r1.16.2.10 --- Mock.java 16 Apr 2003 22:47:06 -0000 1.16.2.9 +++ Mock.java 17 Apr 2003 16:17:28 -0000 1.16.2.10 @@ -105,7 +105,7 @@ } public void expect(String methodName, Constraint[] args) { - callSequence.add(callFactory.createExpectedCall(callFactory.createCallMatch(methodName, args, callFactory.createVoidStub()))); + callSequence.addExpect(callFactory.createExpectedCall(callFactory.createCallMatch(methodName, args, callFactory.createVoidStub()))); } public void expectAndReturn(String methodName, Object result) { @@ -133,7 +133,7 @@ } public void expectAndReturn(String methodName, Constraint[] args, Object result) { - callSequence.add(callFactory.createExpectedCall(callFactory.createCallMatch(methodName, args, callFactory.createReturnStub(result)))); + callSequence.addExpect(callFactory.createExpectedCall(callFactory.createCallMatch(methodName, args, callFactory.createReturnStub(result)))); } public void expectAndReturn(String methodName, Constraint[] args, boolean result) { @@ -153,7 +153,7 @@ } public void expectAndThrow(String methodName, Constraint[] args, Throwable exception) { - callSequence.add(callFactory.createExpectedCall(callFactory.createCallMatch(methodName, args, callFactory.createThrowStub(exception)))); + callSequence.addExpect(callFactory.createExpectedCall(callFactory.createCallMatch(methodName, args, callFactory.createThrowStub(exception)))); } public void matchAndReturn(String methodName, Object result) { @@ -189,7 +189,7 @@ } public void matchAndReturn(String methodName, Constraint[] args, Object result) { - callSequence.add(callFactory.createCallMatch(methodName, args, callFactory.createReturnStub(result))); + callSequence.addMatch(callFactory.createCallMatch(methodName, args, callFactory.createReturnStub(result))); } public void matchAndReturn(String methodName, Constraint[] args, boolean result) { @@ -217,7 +217,7 @@ } public void matchAndThrow(String methodName, Constraint[] args, Throwable throwable) { - callSequence.add(callFactory.createCallMatch(methodName, args, callFactory.createThrowStub(throwable))); + callSequence.addMatch(callFactory.createCallMatch(methodName, args, callFactory.createThrowStub(throwable))); } /** @deprecated @see OrderedMock Index: CallBag.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallBag.java,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -r1.1.2.3 -r1.1.2.4 --- CallBag.java 16 Apr 2003 22:47:58 -0000 1.1.2.3 +++ CallBag.java 17 Apr 2003 16:17:30 -0000 1.1.2.4 @@ -10,24 +10,39 @@ public class CallBag extends CallCollection implements Callable, CallableAddable { private List expectedCalls = new ArrayList(); + private List expectedMatches = new ArrayList(); public CallBag() { } public Object call(Mock mock, String methodName, Object[] args) throws Throwable { - for (Iterator call = expectedCalls.iterator(); call.hasNext();) { - Callable element = (Callable)call.next(); + + Callable matchingCall = findMatchingCall(methodName, args, expectedCalls); + if(matchingCall == null) { + matchingCall = findMatchingCall(methodName, args, expectedMatches); + } + if(matchingCall == null) { + throw createUnexpectedCallError(methodName, args); + } + + return matchingCall.call(mock, methodName, args); + + } + + private Callable findMatchingCall(String methodName, Object[] args, List callList) { + for (Iterator call = callList.iterator(); call.hasNext();) { + Callable element = (Callable) call.next(); if (element.matches(methodName, args)) { - return element.call(mock, methodName, args); + return element; } } - throw createUnexpectedCallError(methodName, args); + return null; } - public String getDescription() { + public String getDescription() { if (expectedCalls.isEmpty()) { return "no methods"; } else { @@ -36,7 +51,7 @@ buf.append("one of:\n"); for (Iterator i = expectedCalls.iterator(); i.hasNext();) { - buf.append(((Callable)i.next()).getDescription()); + buf.append(((Callable) i.next()).getDescription()); buf.append("\n"); } @@ -50,12 +65,16 @@ public void verify() { for (Iterator call = expectedCalls.iterator(); call.hasNext();) { - Callable element = (Callable)call.next(); + Callable element = (Callable) call.next(); element.verify(); } } - public void add(Callable call) { + public void addExpect(Callable call) { expectedCalls.add(call); + } + + public void addMatch(Callable call) { + expectedMatches.add(call); } } Index: CallSequence.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallSequence.java,v retrieving revision 1.4.2.6 retrieving revision 1.4.2.7 diff -u -r1.4.2.6 -r1.4.2.7 --- CallSequence.java 16 Apr 2003 22:47:58 -0000 1.4.2.6 +++ CallSequence.java 17 Apr 2003 16:17:30 -0000 1.4.2.7 @@ -11,6 +11,7 @@ public class CallSequence extends CallCollection implements Callable, CallableAddable { private ArrayList expectedCalls = new ArrayList(); + private CallBag matchedCalls = new CallBag(); int callIndex = 0; public CallSequence() { @@ -25,7 +26,11 @@ if (nextCall.matches(methodName, args)) return nextCall.call(mock, methodName, args); - throw createUnexpectedCallError(methodName, args); + try { + return matchedCalls.call(mock, methodName, args); + } catch (AssertionFailedError ex) { + throw createUnexpectedCallError(methodName, args); + } } public String getDescription() { @@ -51,8 +56,12 @@ throw new AssertionFailedError("matches() operation not supported in CallSequence"); } - public void add(Callable call) { + public void addExpect(Callable call) { expectedCalls.add(call); + } + + public void addMatch(Callable call) { + matchedCalls.addMatch(call); } public void verify() { |
From: Tim M. <ma...@us...> - 2003-04-17 11:46:29
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv32102/core/com/mockobjects/dynamic Modified Files: Tag: DynamicMockExperiment C.java Log Message: Spooky C.eq(o0,o1) had a silent complier bug - the setter used O1 not o1 but the compiler didn't pick it up - and defaulted to a value of "1"??? When I resaved it then showed the error? Index: C.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/C.java,v retrieving revision 1.1.2.5 retrieving revision 1.1.2.6 diff -u -r1.1.2.5 -r1.1.2.6 --- C.java 16 Apr 2003 16:31:44 -0000 1.1.2.5 +++ C.java 17 Apr 2003 11:46:25 -0000 1.1.2.6 @@ -33,15 +33,15 @@ public static Constraint[] eq( Object o0, Object o1 ) { Constraint[] result = new Constraint[2]; result[0] = eq(o0); - result[1] = eq(01); + result[1] = eq(o1); return result; } public static Constraint[] eq( Object o0, Object o1, Object o2 ) { Constraint[] result = new Constraint[3]; result[0] = eq(o0); - result[1] = eq(01); - result[2] = eq(02); + result[1] = eq(o1); + result[2] = eq(o2); return result; } |
From: Vincent M. <vm...@pi...> - 2003-04-17 06:37:20
|
Hi, I've been thinking about the features of AgileTest (from Polygenix). I think there's an easy way to support the same feature (which would be just great for most mockobjects users). It's by using a java AOP framework. For example, look at AspectWerkz: http://aspectwerkz.sourceforge.net/ (see http://freeroller.net/page/jboner/20030416 for an example of how to use it to code a cache). Imagine you have the following piece of code: public myMethod(.) { [.] = SomeClass.getXXX() ; } where getXXX() is static. Or anything else for that matter. The goal here is to introduce the Mocks in the class being tested. We usually do this using refactoring and providing setters/constructors/etc. And again this is the best practice. However, in some cases, like when you inherit from a legacy application, you can't easily break everything and refactor it all. Then imagine the following (using AspectWerkz): public class TestAdvice extends MethodAdvice { public TestAdvice() { super(); } public Object execute(final JoinPoint joinPoint) throws Throwable { return [whatever is needed for the test]; } } Where "whatever is needed for the test" would be setup using the same kind of API (setupXXX, etc) like our current Mock (AspectWerkz supports dynamically addition of interfaces, methods and fields to existing classes). From what I currently understand, AspectWerkz needs an XML descriptor to tell where to apply the advice. Something like: <advice name="testing" class="...TestingAdvice" deploymentModel="perInstance"/> <aspect class=".*"> <pointcut type="method" pattern="ce qu'on veut trapper"> <advice-ref name="testing"/> </pointcut> </aspect> But I haven't checked and it may also support a java API (as does the JBoss AOP fwk) to dynamically create aspects which would make it even easier for users to declare where swap-ins should occur. My example is a bit rough and is far from a real implementation but I hope it gives some ideas of what I mean. With AspectJ it was a bit awkward as it introduces a new langage which needs a post compiler, changes to the build system, is not IDE-friendly, etc. With the new AOP frameworks like AspectWerkz or others, I think AOP for unit testing is really a boon. And we should probably explore it, don't you think? :-). I'll certainly explore these new frameworks for Cactus in order to be able to intercept calls in the container. Thanks -Vincent |
From: Tim M. <ma...@us...> - 2003-04-17 01:54:22
|
Update of /cvsroot/mockobjects/mockobjects-java/src/examples/com/mockobjects/examples/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv2033/src/examples/com/mockobjects/examples/dynamic Modified Files: Tag: DynamicMockExperiment SimpleServletTest.java Log Message: Missing timer.verify Index: SimpleServletTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/examples/com/mockobjects/examples/dynamic/Attic/SimpleServletTest.java,v retrieving revision 1.1.2.8 retrieving revision 1.1.2.9 diff -u -r1.1.2.8 -r1.1.2.9 --- SimpleServletTest.java 16 Apr 2003 22:17:36 -0000 1.1.2.8 +++ SimpleServletTest.java 17 Apr 2003 01:54:16 -0000 1.1.2.9 @@ -36,11 +36,6 @@ Mock mockHttpServletResponse = new Mock(HttpServletResponse.class); Mock mockHttpServletRequest = new Mock(HttpServletRequest.class); - CallSequence calls = new CallSequence(); - calls.add("getParameter", "body", "this is the body"); - calls.add("getParameter", "subject", "mail from tim"); - calls.add("getParameterValues", "recipients", new String[] {"na...@te...", "st...@mp..."} ); - CallSequence params = new CallSequence(); params.expectAndReturn( new Constraint[] { C.eq("body") }, "this is the body" ); params.expectAndReturn( new Constraint[] { C.eq("subject") }, "mail from tim" ); @@ -69,7 +64,7 @@ final PrintWriter contentWriter = new PrintWriter(new StringWriter()); mockHttpServletResponse.expect( "setContentType", "text/html"); - mockHttpServletResponse.expectAndReturn( "getWriter", C.args(), contentWriter ); + mockHttpServletResponse.expectAndReturn( "getWriter", contentWriter ); // CallMatch m1 = mockHttpServletResponse.expect( "setContentType", "text/html"); // CallMatch m2 = mockHttpServletResponse.expectAndReturn( "getWriter", C.args(), contentWriter ); @@ -80,5 +75,6 @@ mockHttpServletRequest.verify(); mockHttpServletResponse.verify(); + mockTimer.verify(); } } |
From: Tim M. <tim...@po...> - 2003-04-17 01:48:04
|
No problems Nat - we have made some good progress, and things are pretty much how you would expect them. Mostly like your diagram but a few things haven't materialised as you drew them yet (I forget which, but it was trivial). I'm not going to be at XtC next week as I am in America for two weeks (leaving this Sunday). If you are near Liverpool St. today (Thurs) give me a call and drop by the e2x offices. CallSequence has been completed - so no need to worry on that one. The last big one is ANY_ARGS - it should be an object in its own right (we shouldn't use Constraint[] in a CallMatch it should be a Contraints object with an interface which AnyContraints can implement and just always return true ). The callable interface may be ok - I'm divided on this one - we can discuss it later. As for the before/after idea - I like how the functional test proposes it. It should be easy to implement too - just decorate an ExpectedCall with a before field - when you call, make sure the before object wasCalled (may need to add wasCalled to the Callable interface though). Anyway - the current stuff is very usuable for most cases now, I'm really enjoying using it. Tim -----Original Message----- From: Nat Pryce [mailto:nat...@b1...] Sent: 16 April 2003 11:08 To: Tim Mackinnon; Mockobjects-Java-Dev Subject: Re: [MO-java-dev] Java Dynamic Mocks - going to Head? Sorry for being incomunicado for the last few days. I haven't had a chance to see the latest changes -- it seems next to impossible to get BT to acknowledge that they can install a phone line to my boat let alone broadband! I'd like the chance to meet up and check out / comment on the latest updates. Are you (Tim) going to be at XTC this week? Perhaps we could hammer out the CallSequence class. > 2) The Callable interface has a "matches" method, this doesn't feel right > for all callables, its required for CallBag to operate - others don't need > it. This should be removed and implemented as a private decoration for > CallBag. For a CallSequence it will also need a "complete" method that returns true if the Callable can be removed from the front of the sequence. Personally, I feel comfortable having these methods in the Callable interface, but if the Decorator approach works that will be great. > 3) Steve's exellent suggestion of having: > > Callable c1 = mock.expect("setContentType".....) > Callable c2 = mock.expect("getWriter".....) > c1.expectBefore(c2) > > has not yet been implemented. This should work quite easily, but the focus > has been on UnorderdMock and OrderedMock. In the new design, this would be accomplished by organising "setContentType" and "getWriter" into a CallSequence and adding the call sequence to the Mock. CallCollection seq = mock.expectSequence(); seq.expectVoid( "setContentType", ... ); seq.expectAndReturn( "getWriter", ... ); The expectBefore method will be quite messy to implement in the current design. Since there is already a way to achieve the same effect, I'd suggest not implementing expectBefore. --- Incoming mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.467 / Virus Database: 266 - Release Date: 01/04/2003 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.467 / Virus Database: 266 - Release Date: 01/04/2003 |
From: Tim M. <tim...@po...> - 2003-04-17 01:17:53
|
Hi Vincent - thanks for chipping in, it was on the ToDo list to catch up with you and see how the changes would impact you as well. (If anyone else is using it - please speak up as well). Basically the library is pretty similar to before however when using it when working with e2x i noticed that the TDD experience wasn't as good as it should be - the use of a separate CallSequence to order calls or have multiple calls to the same method wasn't very intuitive. Also the error messages that you got back when things failed were not easy to interpit. I worked with Nat and then Steve to get something that seems to satisfy everyone so far. I ported the e2x codebase in about an hour - and some of that time were actually flaws in tests that the old library sort of covered up (some of these were mocks expecting other mocks as parameters, so you might not even experience this. It would be really good if you could port to the new one (I still shudder from my Connextra experience of the old mock library being so diverged we never were able to go back). The following is a fragment of how you would have written a simple servlet test: public void testDoGetOldStyle() throws ServletException, IOException { Mock mockHttpServletResponse = new Mock(HttpServletResponse.class); Mock mockHttpServletRequest = new Mock(HttpServletRequest.class); CallSequence params = new CallSequence(); params.expectAndReturn( new Constraint[] { C.eq("body") }, "this is the body" ); params.expectAndReturn( new Constraint[] { C.eq("subject") }, "mail from tim" ); params.expectAndReturn( new Constraint[] { C.eq("recipients") }, new String[] { "nat...@b1...", "st...@m3..." } ); mockHttpServletRequest.expect( "getParameter", params ); SimpleServlet aServlet = new SimpleServlet(); aServlet.doGet((HttpServletRequest) mockHttpServletRequest.proxy(), (HttpServletResponse) mockHttpServletResponse.proxy()); mockHttpServletRequest.verify(); mockHttpServletResponse.verify(); } The following is how you would now write it (with a few extra features and examples shown as well): public void testDoGetOldStyle() throws ServletException, IOException { Mock mockTimer = new Mock(Timer.class); Mock mockHttpServletResponse = new OrderedMock(HttpServletResponse.class, "response"); Mock mockHttpServletRequest = new Mock(HttpServletRequest.class); mockHttpServletRequest.matchAndReturn( "getParameter", C.args(C.eq("browser-identifier")), "MSIE-5.0" ); mockHttpServletRequest.expectAndReturn( "getParameter", "subject", "Mail Subject" ); mockHttpServletRequest.expectAndReturn( "getParameter", C.args(C.eq("body")), "Mail Body" ); mockTimer.expectAndReturn("getTime", 10000); mockTimer.expectAndReturn("getTime", 20000); final PrintWriter contentWriter = new PrintWriter(new StringWriter()); mockHttpServletResponse.expect( "setContentType", "text/html"); mockHttpServletResponse.expectAndReturn( "getWriter", C.args(), contentWriter ); // proposed arbitrary odering implementation // CallMatch m1 = mockHttpServletResponse.expect( "setContentType", "text/html"); // CallMatch m2 = mockHttpServletResponse.expectAndReturn( "getWriter", contentWriter ); // m1.expectBefore(m2); SimpleServlet aServlet = new SimpleServlet((Timer)mockTimer.proxy()); aServlet.doGet((HttpServletRequest) mockHttpServletRequest.proxy(), (HttpServletResponse) mockHttpServletResponse.proxy()); mockHttpServletRequest.verify(); mockHttpServletResponse.verify(); mockTimer.verify(); } Basically to port: references to CallSequence will break (its now an interenal object that shouldn't be used). Take each of the expectAndReturn lines and just run them against a Mock (like we with the mockHttpServletRequest) and then remove the sequence. Mock.expect doesn't take a calls object - its like expectVoid (see below). You can choose between Mock and OrderedMock - to decide if you want set like (any order calls) or list like behavior. They both have expect, expectAndReturn, expectAndThrow style methods, along with match... methods (this latter is for returning a value for a method signature that matches). YOUR OPINION? For void methods, we have used expect("aVoidMethod"... in the old library this was called expectVoid(... There is a deprecated version in there to help porting - whats your opinion on the rename to just expect? (The issue is - for true consistency it should be ExpectAndVoid - but if you aren't expecting any return value or exception why put that in the name? Shorter seems better?). FUTURE: Error messages are much better - they still can be improved. Mocks that takes mocks as expect parameters give strange errors if you forget to use mock.proxy (we could overload this and do the .proxy automatically?) You can see the example of how we might do call odering for better precision C.ANY_ARGS is currently removed - use C.anyArgs(argCount) - becuase of the proper signature overloading using null is a problematic. ANY_ARGS should be a proper object not an array. It may be useful to have a CallSubSetMock and a CallSubListMock (which probably means OrderedMock should be renamed to CallListMock) Hope this helps. Tim -----Original Message----- From: Vincent Massol [mailto:vm...@pi...] Sent: 16 April 2003 18:45 To: 'Tim Mackinnon'; 'Mockobjects-Java-Dev' Subject: RE: [MO-java-dev] Java Dynamic Mocks - going to Head? Hi Tim, I have been using the DynaMocks for a while now on several projects (using CVS builds as there were no releases). I have not been following very closely the changes you brought to the experimental branch. Are the new DynaMocks very different from the other ones? How easy is it for me to migrate? I guess I should take a look but I am very much in a hurry and any help will be greatly appreciated. Maybe some docs about how to use the new dyna mocks, etc? Thanks -Vincent > -----Original Message----- > From: moc...@li... > [mailto:moc...@li...] On Behalf Of Tim > Mackinnon > Sent: 16 April 2003 10:23 > To: Mockobjects-Java-Dev > Subject: [MO-java-dev] Java Dynamic Mocks - going to Head? > > Guys - > > First of all, sorry for missing Xtc - I've got the dynamic bug and want to > see the library in a state that it can be used in many projects. I think > its > important to convey the power and simplicity of mocks (we all know this, > but > there are so many bad examples out there...). > > Anyway - I tried using the branch in the e2x codebase and as always, on a > real project there are often little subtleties that catch you out. As John > Nolan was around working on his own little pet project we bounced ideas of > each other to get things done. > > Anyway - the library is working out quite well now and we should consider > rolling it in to the head stream soom! (Maybe a day or two more of "in > usage" testing, and comments from anyone else who is interested - but to > be > honest making it available in the head should allow greater changes). > > Here are some points: > > 1) To test the dynamic stuff, we used Traditional Mocks - it became a pain > hand coding them, especially on larger interfaces, so we took the decision > to use MockMaker. This worked well, however their are some ReturnXXX > objects > that it uses that should be in the base library. In the branch I have just > put them in - however they duplicate some existing functionality. I propse > we resolve this duplication in a second pass as it requires updates to > code > that mockmaker generates. Having the additional duplication allows an > exisiting generated mock to be updated by simply removing 3 import lines. > To > get a full solution we need to get all the tools running on a single > platform - and you use the right one for the right job. > > 2) The Callable interface has a "matches" method, this doesn't feel right > for all callables, its required for CallBag to operate - others don't need > it. This should be removed and implemented as a private decoration for > CallBag. > > 3) Steve's exellent suggestion of having: > > Callable c1 = mock.expect("setContentType".....) > Callable c2 = mock.expect("getWriter".....) > c1.expectBefore(c2) > > has not yet been implemented. This should work quite easily, but the focus > has been on UnorderdMock and OrderedMock. > > 4) As you can use mocks as expected values themselves - there was some > ugliness with the proxies needing to detect equality of mocks (you can see > this in the invoke method). I'm not sure if there is a better way to do > this. > > 5) I think Mocks should probably register with something so that we can do > the Verifier.verify on both instance variables and local variables in a > test. I am still seeing lots of accidently unverified mocks > > Overall the sample test case is looking very good (I have included it > again > below). How does everyone feel going ahead with a merge (I can probably > get > Chris Cottee to help me merge it in at e2x)? > > Tim > > public void testDoGetNew() throws ServletException, IOException { > Mock mockHttpServletResponse = new > OrderedMock(HttpServletResponse.class, > "response"); > Mock mockHttpServletRequest = new > Mock(HttpServletRequest.class); > > mockHttpServletRequest.matchAndReturn( "getParameter", > C.args(C.eq("browser-identifier")), "MSIE-5.0" ); > mockHttpServletRequest.expectAndReturn( "getParameter", > "subject", "Mail > Subject" ); > // Alternative syntax > mockHttpServletRequest.expectAndReturn( "getParameter", > C.args(C.eq("body")), "Mail Body" ); > > final PrintWriter contentWriter = new PrintWriter(new > StringWriter()); > > mockHttpServletResponse.expect( "setContentType", > "text/html"); > mockHttpServletResponse.expectAndReturn( "getWriter", > contentWriter ); > > // Still to do, instead of making response an OrderedMock > // CallMatch m1 = mockHttpServletResponse.expect( > "setContentType", > "text/html"); > // CallMatch m2 = mockHttpServletResponse.expectAndReturn( > "getWriter", > C.args(), contentWriter ); > // m1.expectBefore(m2); > > SimpleServlet aServlet = new SimpleServlet(); > aServlet.doGet((HttpServletRequest) > mockHttpServletRequest.proxy(), > (HttpServletResponse) mockHttpServletResponse.proxy()); > > mockHttpServletRequest.verify(); > mockHttpServletResponse.verify(); > } > --- > Outgoing mail is certified Virus Free. > Checked by AVG anti-virus system (http://www.grisoft.com). > Version: 6.0.467 / Virus Database: 266 - Release Date: 01/04/2003 > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Mockobjects-java-dev mailing list > Moc...@li... > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev --- Incoming mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.467 / Virus Database: 266 - Release Date: 01/04/2003 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.467 / Virus Database: 266 - Release Date: 01/04/2003 |
From: Steve F. <sm...@us...> - 2003-04-16 22:48:24
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv4087/src/core/test/mockobjects/dynamic Modified Files: Tag: DynamicMockExperiment CallSequenceTest.java MockTest.java Log Message: Tidy up Index: CallSequenceTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/CallSequenceTest.java,v retrieving revision 1.5.2.2 retrieving revision 1.5.2.3 diff -u -r1.5.2.2 -r1.5.2.3 --- CallSequenceTest.java 16 Apr 2003 17:20:32 -0000 1.5.2.2 +++ CallSequenceTest.java 16 Apr 2003 22:48:21 -0000 1.5.2.3 @@ -16,7 +16,6 @@ public class CallSequenceTest extends TestCase { - private static final String MOCK_NAME = "Test mock"; final String METHOD_A_NAME = "methodA"; final String METHOD_A_RESULT = "resultA"; final String METHOD_B_NAME = "methodB"; Index: MockTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockTest.java,v retrieving revision 1.8.2.7 retrieving revision 1.8.2.8 diff -u -r1.8.2.7 -r1.8.2.8 --- MockTest.java 16 Apr 2003 16:31:46 -0000 1.8.2.7 +++ MockTest.java 16 Apr 2003 22:48:21 -0000 1.8.2.8 @@ -289,7 +289,6 @@ public void testMockAnnotatesAssertionFailedErrors() throws Throwable { final String originalMessage = "original message"; - final AssertionFailedError error = new AssertionFailedError(originalMessage); mockCallableAddable.setupCallThrow(new AssertionFailedError(originalMessage)); |
From: Steve F. <sm...@us...> - 2003-04-16 22:48:24
|
Update of /cvsroot/mockobjects/mockobjects-java/src/j2ee/1.3/alt/javax/mail In directory sc8-pr-cvs1:/tmp/cvs-serv4087/src/j2ee/1.3/alt/javax/mail Modified Files: Tag: DynamicMockExperiment MessageImpl.java Log Message: Tidy up Index: MessageImpl.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/j2ee/1.3/alt/javax/mail/MessageImpl.java,v retrieving revision 1.1 retrieving revision 1.1.4.1 diff -u -r1.1 -r1.1.4.1 --- MessageImpl.java 14 Oct 2002 22:58:28 -0000 1.1 +++ MessageImpl.java 16 Apr 2003 22:48:21 -0000 1.1.4.1 @@ -1,16 +1,15 @@ package alt.javax.mail; -import com.mockobjects.MockObject; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.Date; +import java.util.Enumeration; -import javax.mail.MessagingException; import javax.mail.Address; import javax.mail.Flags; +import javax.mail.MessagingException; import javax.mail.Multipart; -import java.util.Date; -import java.util.Enumeration; -import java.io.InputStream; -import java.io.IOException; -import java.io.OutputStream; public class MessageImpl implements Message { private final javax.mail.Message message; |
From: Steve F. <sm...@us...> - 2003-04-16 22:48:02
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv3948/src/core/com/mockobjects/dynamic Modified Files: Tag: DynamicMockExperiment CallSequence.java CallBag.java Added Files: Tag: DynamicMockExperiment CallCollection.java Log Message: Factored out error reporting Index: CallSequence.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallSequence.java,v retrieving revision 1.4.2.5 retrieving revision 1.4.2.6 diff -u -r1.4.2.5 -r1.4.2.6 --- CallSequence.java 16 Apr 2003 22:14:46 -0000 1.4.2.5 +++ CallSequence.java 16 Apr 2003 22:47:58 -0000 1.4.2.6 @@ -8,52 +8,45 @@ import junit.framework.AssertionFailedError; -public class CallSequence implements Callable, CallableAddable { +public class CallSequence extends CallCollection implements Callable, CallableAddable { private ArrayList expectedCalls = new ArrayList(); int callIndex = 0; - public String getDescription() { - if (expectedCalls.isEmpty()) { - return "no methods"; - } else { - StringBuffer buf = new StringBuffer(); - - buf.append("in sequence:\n"); - - int j=0; - for (Iterator i = expectedCalls.iterator(); i.hasNext();) { - buf.append(((Callable)i.next()).getDescription()); - if (j++==(callIndex-1)) buf.append(" <<< NEXT EXPECTED CALL"); - buf.append("\n"); - } - - return buf.toString(); - } - } - - public CallSequence() { } public Object call(Mock mock, 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, recieved: " + DynamicUtil.methodToString(methodName, args)); + if (callIndex == expectedCalls.size()) throw new AssertionFailedError("mock called too many times, received: " + DynamicUtil.methodToString(methodName, args)); Callable nextCall = (Callable)expectedCalls.get(callIndex++); if (nextCall.matches(methodName, args)) return nextCall.call(mock, methodName, args); - StringBuffer buf = new StringBuffer(); - buf.append("Unexpected call to "); - buf.append(DynamicUtil.methodToString(methodName, args)); - buf.append("\n"); - buf.append("Expected "); - buf.append(getDescription()); - throw new AssertionFailedError(buf.toString()); + throw createUnexpectedCallError(methodName, args); } + public String getDescription() { + if (expectedCalls.isEmpty()) { + return "no methods"; + } else { + StringBuffer buf = new StringBuffer(); + + buf.append("in sequence:\n"); + + int j=0; + for (Iterator i = expectedCalls.iterator(); i.hasNext();) { + buf.append(((Callable)i.next()).getDescription()); + if (j++==(callIndex-1)) buf.append(" <<< Next Expected Call"); + buf.append("\n"); + } + + return buf.toString(); + } + } + public boolean matches(String methodName, Object[] args) { throw new AssertionFailedError("matches() operation not supported in CallSequence"); } Index: CallBag.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallBag.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- CallBag.java 16 Apr 2003 22:21:04 -0000 1.1.2.2 +++ CallBag.java 16 Apr 2003 22:47:58 -0000 1.1.2.3 @@ -7,13 +7,8 @@ import java.util.Iterator; import java.util.List; -import junit.framework.AssertionFailedError; - -/** - * @author dev - */ -public class CallBag implements Callable, CallableAddable { +public class CallBag extends CallCollection implements Callable, CallableAddable { private List expectedCalls = new ArrayList(); public CallBag() { @@ -29,16 +24,10 @@ } } - StringBuffer buf = new StringBuffer(); - buf.append("Unexpected call to "); - buf.append(DynamicUtil.methodToString(methodName, args)); - buf.append("\n"); - buf.append("Expected "); - buf.append(getDescription()); - throw new AssertionFailedError(buf.toString()); + throw createUnexpectedCallError(methodName, args); } - public String getDescription() { + public String getDescription() { if (expectedCalls.isEmpty()) { return "no methods"; } else { |
From: Steve F. <sm...@us...> - 2003-04-16 22:47:41
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv3831/src/core/com/mockobjects/dynamic Modified Files: Tag: DynamicMockExperiment CallMatch.java Log Message: Removed null handling Index: CallMatch.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Attic/CallMatch.java,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -u -r1.1.2.4 -r1.1.2.5 --- CallMatch.java 16 Apr 2003 16:31:44 -0000 1.1.2.4 +++ CallMatch.java 16 Apr 2003 22:47:37 -0000 1.1.2.5 @@ -16,7 +16,7 @@ public CallMatch( String methodName, Constraint[] constraints, Callable decorated ) { this.methodName = methodName; - this.constraints = constraints == null ? null : (Constraint[])constraints.clone(); + this.constraints = (Constraint[])constraints.clone(); this.decorated = decorated; } |
From: Steve F. <sm...@us...> - 2003-04-16 22:47:11
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv3694/src/core/com/mockobjects/dynamic Modified Files: Tag: DynamicMockExperiment Mock.java Log Message: Tidy up Index: Mock.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Mock.java,v retrieving revision 1.16.2.8 retrieving revision 1.16.2.9 diff -u -r1.16.2.8 -r1.16.2.9 --- Mock.java 16 Apr 2003 22:21:05 -0000 1.16.2.8 +++ Mock.java 16 Apr 2003 22:47:06 -0000 1.16.2.9 @@ -4,11 +4,13 @@ */ package com.mockobjects.dynamic; -import java.lang.reflect.*; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; -import com.mockobjects.constraint.Constraint; +import junit.framework.AssertionFailedError; -import junit.framework.*; +import com.mockobjects.constraint.Constraint; /** |
From: Steve F. <sm...@us...> - 2003-04-16 22:21:10
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv26193/src/core/test/mockobjects/dynamic Added Files: Tag: DynamicMockExperiment CallBagTest.java Removed Files: Tag: DynamicMockExperiment CallSetTest.java Log Message: Renamed CallSet to CallBag --- NEW FILE: CallBagTest.java --- /* * Created on 04-Apr-2003 */ package test.mockobjects.dynamic; import com.mockobjects.constraint.*; import com.mockobjects.dynamic.*; import com.mockobjects.util.*; import junit.framework.*; /** * @author dev */ public class CallBagTest extends TestCase { final String METHOD_A_NAME = "methodA"; final String METHOD_A_RESULT = "resultA"; final String METHOD_B_NAME = "methodB"; final String METHOD_B_RESULT = "resultB"; final Throwable METHOD_A_EXCEPTION = new DummyThrowable("Configured test throwable"); final String[] METHOD_A_ARGS = new String[] { "a1", "a2" }; final Constraint[] METHOD_A_CONSTRAINTS = C.args(C.eq("a1"), C.eq("a2")); final String[] METHOD_B_ARGS = new String[] { "b1", "b2" }; private CallBag callSet = new CallBag(); private Mock unusedMock = null; private MockCallable methodA = new MockCallable(); private MockCallable methodB = new MockCallable(); private MockCallable mockCallable = new MockCallable(); public CallBagTest(String name) { super(name); } public void testCallFailsOnEmptySet() throws Throwable { try { callSet.call(unusedMock, "missingMethod", new Object[0]); } catch (AssertionFailedError ex) { AssertMo.assertIncludes("reports empty set in error message", "no methods", ex.getMessage()); return; } fail("Should fail for a missing item"); } public void testCallPassedToContainedElements() throws Throwable { methodA.setExpectedMatches(METHOD_A_NAME, METHOD_A_ARGS); methodA.setupMatchesReturn(true); methodA.setExpectedCall(unusedMock, METHOD_A_NAME, METHOD_A_ARGS); methodA.setupCallReturn(METHOD_A_RESULT); methodB.setExpectedCallCount(0); callSet.add(methodA); callSet.add(methodB); assertSame("expected result from method A", METHOD_A_RESULT, callSet.call(unusedMock, METHOD_A_NAME, METHOD_A_ARGS)); methodA.verifyExpectations(); methodB.verifyExpectations(); } public void testCallPassedToContainedElementsOtherOrder() throws Throwable { methodA.setExpectedMatches(METHOD_B_NAME, METHOD_B_ARGS); methodA.setupMatchesReturn(false); methodA.setExpectedCallCount(0); methodB.setExpectedCall(unusedMock, METHOD_B_NAME, METHOD_B_ARGS); methodB.setupCallReturn(METHOD_B_RESULT); methodB.setExpectedMatches(METHOD_B_NAME, METHOD_B_ARGS); methodB.setupMatchesReturn(true); callSet.add(methodA); callSet.add(methodB); assertSame("expected result from method B", METHOD_B_RESULT, callSet.call(unusedMock, METHOD_B_NAME, METHOD_B_ARGS)); methodA.verifyExpectations(); methodB.verifyExpectations(); } public void testConfiguredResultReturned() throws Throwable { final String result = "result"; mockCallable.setupCallReturn(result); mockCallable.setupMatchesReturn(true); callSet.add(mockCallable); assertSame("result is returned by mock", result, callSet.call(unusedMock, "method", new Object[0])); } public void testCallableThrowableThrown() throws Throwable { final Throwable throwable = new DummyThrowable(); mockCallable.setupMatchesReturn(true); mockCallable.setupCallThrow(throwable); callSet.add(mockCallable); try { callSet.call(unusedMock, "hello", new String[0]); } catch (Throwable ex) { assertSame("exception is caught by mock", throwable, ex); } } public void testEmptySetVerifies() throws Exception { callSet.verify(); } public void testFailureIfNoElementMatches() throws Throwable { final String methodCName = "methodC"; final String[] methodCArgs = { "c1", "c2" }; methodA.setExpectedMatches(methodCName, methodCArgs); methodA.setupMatchesReturn(false); methodA.setExpectedCallCount(0); methodA.setupGetDescription("***methodA-description****"); methodB.setExpectedCall(unusedMock, methodCName, methodCArgs); methodB.setupMatchesReturn(false); methodB.setExpectedCallCount(0); methodB.setupGetDescription("***methodB-description****"); callSet.add(methodA); callSet.add(methodB); try { callSet.call(unusedMock, methodCName, methodCArgs); } catch (AssertionFailedError ex) { AssertMo.assertIncludes("method name is in error message", "methodC", ex.getMessage()); AssertMo.assertIncludes("argument is in error message (1)", methodCArgs[0], ex.getMessage()); AssertMo.assertIncludes("argument is in error message (2)", methodCArgs[1], ex.getMessage()); AssertMo.assertIncludes("shows set contents (A)", methodA.getDescription(), ex.getMessage()); AssertMo.assertIncludes("shows set contents (B)", methodB.getDescription(), ex.getMessage()); return; } fail("Should fail for a missing item"); } public void testVerifiesIfAllContainedElementsVerify() throws Throwable { methodA.setExpectedVerifyCalls(1); methodB.setExpectedVerifyCalls(1); callSet.add(methodA); callSet.add(methodB); callSet.verify(); methodA.verifyExpectations(); methodB.verifyExpectations(); } public void testVerifyFailsIfContainedElementDoesNotVerify() throws Exception { methodA.setExpectedVerifyCalls(1); methodA.setupVerifyThrow(new AssertionFailedError("verify failed")); callSet.add(methodA); try { callSet.verify(); } catch (AssertionFailedError ex) { methodA.verifyExpectations(); return; } fail("Should have got a failure for contained element failing"); } } --- CallSetTest.java DELETED --- |
From: Steve F. <sm...@us...> - 2003-04-16 22:21:10
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv26193/src/core/com/mockobjects/dynamic Modified Files: Tag: DynamicMockExperiment Mock.java Added Files: Tag: DynamicMockExperiment CallBag.java Removed Files: Tag: DynamicMockExperiment CallSet.java Log Message: Renamed CallSet to CallBag Index: Mock.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Mock.java,v retrieving revision 1.16.2.7 retrieving revision 1.16.2.8 diff -u -r1.16.2.7 -r1.16.2.8 --- Mock.java 16 Apr 2003 22:15:47 -0000 1.16.2.7 +++ Mock.java 16 Apr 2003 22:21:05 -0000 1.16.2.8 @@ -28,7 +28,7 @@ } public Mock(Class mockedClass, String name) { - this(new DefaultCallFactory(), new CallSet(), mockedClass, name); + this(new DefaultCallFactory(), new CallBag(), mockedClass, name); } public Mock(Class mockedClass) { --- CallSet.java DELETED --- |
From: Steve F. <sm...@us...> - 2003-04-16 22:17:41
|
Update of /cvsroot/mockobjects/mockobjects-java/src/examples/com/mockobjects/examples/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv25147/src/examples/com/mockobjects/examples/dynamic Modified Files: Tag: DynamicMockExperiment SimpleServlet.java SimpleServletTest.java Added Files: Tag: DynamicMockExperiment Timer.java Log Message: Added example of multiple calls to same method (Timer) --- NEW FILE: Timer.java --- package com.mockobjects.examples.dynamic; public interface Timer { int getTime(); } Index: SimpleServlet.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/examples/com/mockobjects/examples/dynamic/Attic/SimpleServlet.java,v retrieving revision 1.1.2.5 retrieving revision 1.1.2.6 diff -u -r1.1.2.5 -r1.1.2.6 --- SimpleServlet.java 14 Apr 2003 18:46:51 -0000 1.1.2.5 +++ SimpleServlet.java 16 Apr 2003 22:17:35 -0000 1.1.2.6 @@ -15,16 +15,30 @@ public class SimpleServlet extends HttpServlet { + private Timer timer; + + public SimpleServlet(Timer aTimer) { + super(); + timer = aTimer; + } + + public SimpleServlet() { + this(null); // really this would be a proper timer... + } + public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String body = request.getParameter("body"); String subject = request.getParameter("subject"); String browser = request.getParameter("browser-identifier"); - String subjectCopy = request.getParameter("subject"); //String pet = request.getParameter("favourite-pet"); - - response.setContentType("text/html"); - Writer writer = response.getWriter(); + + response.setContentType("text/html"); + PrintWriter writer = response.getWriter(); + + writer.print("timer before:" + timer.getTime()); + // some long operation + writer.print("timer after:" + timer.getTime()); } Index: SimpleServletTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/examples/com/mockobjects/examples/dynamic/Attic/SimpleServletTest.java,v retrieving revision 1.1.2.7 retrieving revision 1.1.2.8 diff -u -r1.1.2.7 -r1.1.2.8 --- SimpleServletTest.java 14 Apr 2003 18:46:51 -0000 1.1.2.7 +++ SimpleServletTest.java 16 Apr 2003 22:17:36 -0000 1.1.2.8 @@ -6,15 +6,19 @@ */ package com.mockobjects.examples.dynamic; -import java.io.*; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; -import javax.servlet.*; -import javax.servlet.http.*; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; -import com.mockobjects.constraint.*; -import com.mockobjects.dynamic.*; +import junit.framework.TestCase; -import junit.framework.*; +import com.mockobjects.dynamic.C; +import com.mockobjects.dynamic.Mock; +import com.mockobjects.dynamic.OrderedMock; /** * @author dev @@ -52,12 +56,15 @@ } */ public void testDoGetNew() throws ServletException, IOException { + Mock mockTimer = new Mock(Timer.class); Mock mockHttpServletResponse = new OrderedMock(HttpServletResponse.class, "response"); Mock mockHttpServletRequest = new Mock(HttpServletRequest.class); mockHttpServletRequest.matchAndReturn( "getParameter", C.args(C.eq("browser-identifier")), "MSIE-5.0" ); mockHttpServletRequest.expectAndReturn( "getParameter", "subject", "Mail Subject" ); mockHttpServletRequest.expectAndReturn( "getParameter", C.args(C.eq("body")), "Mail Body" ); + mockTimer.expectAndReturn("getTime", 10000); + mockTimer.expectAndReturn("getTime", 20000); final PrintWriter contentWriter = new PrintWriter(new StringWriter()); @@ -68,7 +75,7 @@ // CallMatch m2 = mockHttpServletResponse.expectAndReturn( "getWriter", C.args(), contentWriter ); // m1.expectBefore(m2); - SimpleServlet aServlet = new SimpleServlet(); + SimpleServlet aServlet = new SimpleServlet((Timer)mockTimer.proxy()); aServlet.doGet((HttpServletRequest) mockHttpServletRequest.proxy(), (HttpServletResponse) mockHttpServletResponse.proxy()); mockHttpServletRequest.verify(); |
From: Steve F. <sm...@us...> - 2003-04-16 22:17:07
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv24985/src/core/test/mockobjects/dynamic Modified Files: Tag: DynamicMockExperiment ExpectedCallTest.java Log Message: ExpectedCalls are now only valid for one call. After that they will not match. Index: ExpectedCallTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/ExpectedCallTest.java,v retrieving revision 1.1.2.5 retrieving revision 1.1.2.6 diff -u -r1.1.2.5 -r1.1.2.6 --- ExpectedCallTest.java 16 Apr 2003 16:31:47 -0000 1.1.2.5 +++ ExpectedCallTest.java 16 Apr 2003 22:17:04 -0000 1.1.2.6 @@ -75,6 +75,16 @@ mockCallable.verifyExpectations(); } + public void testDoesNotMatchAfterMethodCalled() throws Throwable + { + mockCallable.setupMatchesReturn(true); + mockCallable.setupCallReturn(RESULT); + + assertTrue( "First time should match", call.matches(METHOD_NAME, ARGS)); + call.call(ignoredMock, METHOD_NAME, ARGS); + assertFalse( "Second time should not match", call.matches(METHOD_NAME, ARGS)); + } + public void testDecoratedResultPassedThrough() throws Throwable { mockCallable.setupCallReturn(RESULT); |