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
|
From: Francois B. <fbe...@ft...> - 2002-11-04 23:22:05
|
Hi ! Simple patch to expect calls to flush(). I also reordered the methods so that all expectations are first, then the overriden methods, and finally, the verify() method. Have a nice day ! Francois Beausoleil Index: MockPrintWriter.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/jdk/common/com/mockobjects/io/MockPrintWriter.java,v retrieving revision 1.2 diff -u -r1.2 MockPrintWriter.java --- MockPrintWriter.java 22 Aug 2002 09:33:44 -0000 1.2 +++ MockPrintWriter.java 4 Nov 2002 23:19:00 -0000 @@ -1,21 +1,22 @@ package com.mockobjects.io; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.io.Writer; - import com.mockobjects.ExpectationCounter; import com.mockobjects.ExpectationSegment; import com.mockobjects.Verifiable; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.io.Writer; + /** * @author st...@m3... + * @author Francois Beausoleil (fb...@us...) */ - public class MockPrintWriter extends PrintWriter implements Verifiable { private ExpectationSegment mySegment = new ExpectationSegment("String segment"); private ExpectationCounter myCloseCalls = new ExpectationCounter("close calls"); + private ExpectationCounter myFlushCalls = new ExpectationCounter("flush calls"); public MockPrintWriter() { this(new StringWriter()); @@ -25,26 +26,35 @@ super(writer); } - public void close() { - super.close(); - myCloseCalls.inc(); - } - public void setExpectedCloseCalls(int calls) { myCloseCalls.setExpected(calls); } + public void setExpectedFlushCalls(int calls) { + myFlushCalls.setExpected(calls); + } + public void setExpectedSegment(String aString) { mySegment.setExpected(aString); } - public void verify() { - mySegment.verify(); - myCloseCalls.verify(); + public void flush() { + super.flush(); + myFlushCalls.inc(); + } + + public void close() { + super.close(); + myCloseCalls.inc(); } public void write(String s) { super.write(s); mySegment.setActual(s); + } + + public void verify() { + mySegment.verify(); + myCloseCalls.verify(); } } -- http://fastmail.fm - The holy hand grenade of email services |
From: Steve F. <sm...@us...> - 2002-11-04 22:26:55
|
Update of /cvsroot/mockobjects/mockobjects-java In directory usw-pr-cvs1:/tmp/cvs-serv21053 Modified Files: .cvsignore Log Message: more things to ignore Index: .cvsignore =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/.cvsignore,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- .cvsignore 4 Nov 2002 20:35:04 -0000 1.1 +++ .cvsignore 4 Nov 2002 22:26:52 -0000 1.2 @@ -1,2 +1,8 @@ +.project +.cvsignore +classes build.properties out +bin +dist +.classpath |
From: Steve F. <st...@m3...> - 2002-11-04 21:03:11
|
From: "Vincent Massol" <vm...@oc...> > > From: moc...@li... > > [mailto:moc...@li...] On Behalf Of > > Steve Freeman > > Sent: 03 November 2002 11:39 > > To: 'MockObjects' > > Subject: Re: [MO-java-dev] Building the core library problem + version > > number issue > > > > I can't reproduce that. The src archive might be out of date, so I'll put another one up. > > I'm actually talking about building from CVS. Try it: make a clean > checkout somewhere and run "ant", you should get the same error. I just did and it ran fine, both 1.3.1 and 1.4.1. Can you check the class AbstractExpectationCollection and see if it's got the relevant method? It should have. > > Well, I thought it would make the numbers line up better. I've just changed > > the formatting, not the value. > > I can tell you it looks very strange when on SF you look at the > downloadable versions and see 0.2, 0.3, 0.4, 0.5, 0.6 and 0.07, because > mathematically 0.07 < 0.6 (I do understand the point about 0.07 not > being a number but nevertheless it will cause confusion - it already > has! :-)). I'm half inclined just to set the date yyyymmdd, but that would get a bit long. I'm not sure we have clean enough releases to justify major/minor versions. S. |
From: Vincent M. <vm...@oc...> - 2002-11-04 20:45:16
|
Hi Steve, > -----Original Message----- > From: moc...@li... > [mailto:moc...@li...] On Behalf Of > Steve Freeman > Sent: 03 November 2002 11:39 > To: 'MockObjects' > Subject: Re: [MO-java-dev] Building the core library problem + version > number issue > > I can't reproduce that. The src archive might be out of date, so I'll put > another one up. I'm actually talking about building from CVS. Try it: make a clean checkout somewhere and run "ant", you should get the same error. > > You should at least copy junit.jar in the lib directory. The junit jar has to be in Anthome/lib otherwise the ant <junit> task won't work. Thus junit is already in the classpath. Anyway the error seems to be with some mockobject class. > > From: "Vincent Massol" <vm...@oc...> > > I'm trying to build the mockobject core library by executing "ant jar" > > and it fails with the following kind of errors: > > > > compile-core: > > [mkdir] Created dir: > > E:\Dev\mockobjects\mockobjects-java\out\core\classes > > [javac] Compiling 62 source files to > > E:\Dev\mockobjects\mockobjects-java\out\core\classes > > > > compile-jdk: > > [mkdir] Created dir: > > E:\Dev\mockobjects\mockobjects-java\out\jdk\classes > > [javac] Compiling 38 source files to > > E:\Dev\mockobjects\mockobjects-java\out\jdk\classes > > [javac] > > E:\Dev\mockobjects\mockobjects-java\src\jdk\common\com\mockobjects\sql\C > > ommonMockResultS > > etMetaData.java:86: addActual(java.lang.Object) in > > com.mockobjects.AbstractExpectationCollection can > > not be applied to (int) > > [javac] myColumnNameIndexes.addActual(aColumnIndex); > > > > What am I missing? Note: I haven't put any jar in the lib/ directory but > > the error doesn't seem to be about any missing jar. > > > Well, I thought it would make the numbers line up better. I've just > changed > the formatting, not the value. I can tell you it looks very strange when on SF you look at the downloadable versions and see 0.2, 0.3, 0.4, 0.5, 0.6 and 0.07, because mathematically 0.07 < 0.6 (I do understand the point about 0.07 not being a number but nevertheless it will cause confusion - it already has! :-)). Thanks -Vincent |
From: Vincent M. <vm...@oc...> - 2002-11-04 20:45:12
|
[snip] > > > I also think that the default return value for the String class should > > be null and not "", as null is what anyone expects when an object has > > not been defined. Thus, I find myself adding: > > > > mock.setupDefaultResult(String.class, null); > > > > in the setUp() methods of lots of my test cases. > > > > What do you think? > > surely that would apply to any return type, not just strings? Are your > test > for getting property values back? There are already default results for lots of types. I think the default values should the ones defined by the JVM specification (which is null for Objects). Yes, my tests are for getting HTTP parameters (getParameter()). Thanks -Vincent |
From: Vincent M. <vm...@us...> - 2002-11-04 20:35:10
|
Update of /cvsroot/mockobjects/mockobjects-java In directory usw-pr-cvs1:/tmp/cvs-serv28522 Added Files: .cvsignore Log Message: Added files to ignore by CVS --- NEW FILE: .cvsignore --- build.properties out |
From: Steve F. <sm...@us...> - 2002-11-03 15:19:54
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory usw-pr-cvs1:/tmp/cvs-serv10290/src/core/com/mockobjects/dynamic Modified Files: Tag: reworked_DynaMock_collection MockVoidCall.java Log Message: javadoc corrections compacted checkArguments logic Index: MockVoidCall.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/MockVoidCall.java,v retrieving revision 1.1 retrieving revision 1.1.4.1 diff -u -r1.1 -r1.1.4.1 --- MockVoidCall.java 31 Oct 2002 17:03:45 -0000 1.1 +++ MockVoidCall.java 3 Nov 2002 15:19:52 -0000 1.1.4.1 @@ -22,8 +22,6 @@ /** Constructs an <code>MockVoidCall</code> that accepts any arguments. - * - * @param name * The name of the expected method. */ public MockVoidCall() { @@ -32,8 +30,6 @@ /** Constructs a <code>MockVoidCall</code> that checks its arguments. * - * @param name - * The name of the expected method. * @param expected_args * Predicates that define the valid arguments of the method. */ @@ -57,12 +53,10 @@ private void checkArguments( Object[] args ) { int arg_count = (args == null) ? 0 : args.length; - assertEquals( "wrong number of arguments", - getArgumentCount(), arg_count ); + assertEquals( "wrong number of arguments", getArgumentCount(), arg_count ); for( int i = 0; i < arg_count; i++ ) { - Object arg = args[i]; - checkArgument(i, arg); + checkArgument( i, _expected_args[i], args[i]); } } @@ -70,12 +64,11 @@ return _expected_args.length; } - private void checkArgument( int i, Object arg ) { - if( !_expected_args[i].eval(arg) ) { - fail( "unexpected argument " + (i+1) + ": " + - ", expected " + describeArgument(i) + - ", was <" + arg + ">" ); - } + private void checkArgument( int i, Predicate expectedArg, Object arg ) { + assertTrue("argument " + (i+1) + "\n" + + "expected " + expectedArg + "\n" + + " was " + arg + "", + expectedArg.eval(arg) ); } public String describeArgument( int n ) { |
From: Steve F. <sm...@us...> - 2002-11-03 15:18:29
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects In directory usw-pr-cvs1:/tmp/cvs-serv9969/src/core/com/mockobjects Modified Files: Tag: reworked_DynaMock_collection AbstractExpectationCollection.java Log Message: Removed some duplication Index: AbstractExpectationCollection.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/AbstractExpectationCollection.java,v retrieving revision 1.4 retrieving revision 1.4.2.1 diff -u -r1.4 -r1.4.2.1 --- AbstractExpectationCollection.java 30 Aug 2002 14:49:57 -0000 1.4 +++ AbstractExpectationCollection.java 3 Nov 2002 15:18:26 -0000 1.4.2.1 @@ -18,12 +18,7 @@ } public void addActual(int actualItem) { - Integer actualItemWrapper = new Integer(actualItem); - - getActualCollection().add(actualItemWrapper); - if (shouldCheckImmediately()) { - checkImmediateValues(actualItemWrapper); - } + addActual(new Integer(actualItem)); } public void addActualMany(Object[] items) { @@ -45,9 +40,7 @@ } public void addExpected(int expectedItem) { - Integer expectedItemWrapper = new Integer(expectedItem); - getExpectedCollection().add(expectedItemWrapper); - setHasExpectations(); + addExpected(new Integer(expectedItem)); } public void addExpected(Object expectedItem) { |
From: Steve F. <sm...@us...> - 2002-11-03 15:18:10
|
Update of /cvsroot/mockobjects/mockobjects-java In directory usw-pr-cvs1:/tmp/cvs-serv9884 Modified Files: build.xml Log Message: Added version number to src zip filename Index: build.xml =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/build.xml,v retrieving revision 1.29 retrieving revision 1.30 diff -u -r1.29 -r1.30 --- build.xml 27 Oct 2002 11:46:32 -0000 1.29 +++ build.xml 3 Nov 2002 15:18:06 -0000 1.30 @@ -520,7 +520,7 @@ <zipfileset dir="${out.doc.dir}" prefix="doc" /> <zipfileset dir="${out.dir}" prefix="src"> - <include name="mockobjects-src.zip" /> + <include name="mockobjects-${project.version}-src.zip" /> </zipfileset> </zip> </target> |
From: Steve F. <st...@m3...> - 2002-11-03 11:47:13
|
From: "Vincent Massol" <vm...@oc...> > I've just started playing with Dynamic Mocks and it looks just great! > >From the little I have seen so far, it looks much compact than EasyMock > for example. It seems it is also more extensible and has already more > features. glad you liked it. Nat did most of the work. > I had to read the source code and the MockTest class to understand how > it works. When is a tutorial scheduled? :-) um. when we get around to it... > I also think that the default return value for the String class should > be null and not "", as null is what anyone expects when an object has > not been defined. Thus, I find myself adding: > > mock.setupDefaultResult(String.class, null); > > in the setUp() methods of lots of my test cases. > > What do you think? surely that would apply to any return type, not just strings? Are your test for getting property values back? S. |
From: Steve F. <st...@m3...> - 2002-11-03 11:38:48
|
I can't reproduce that. The src archive might be out of date, so I'll put another one up. You should at least copy junit.jar in the lib directory. From: "Vincent Massol" <vm...@oc...> > I'm trying to build the mockobject core library by executing "ant jar" > and it fails with the following kind of errors: > > compile-core: > [mkdir] Created dir: > E:\Dev\mockobjects\mockobjects-java\out\core\classes > [javac] Compiling 62 source files to > E:\Dev\mockobjects\mockobjects-java\out\core\classes > > compile-jdk: > [mkdir] Created dir: > E:\Dev\mockobjects\mockobjects-java\out\jdk\classes > [javac] Compiling 38 source files to > E:\Dev\mockobjects\mockobjects-java\out\jdk\classes > [javac] > E:\Dev\mockobjects\mockobjects-java\src\jdk\common\com\mockobjects\sql\C > ommonMockResultS > etMetaData.java:86: addActual(java.lang.Object) in > com.mockobjects.AbstractExpectationCollection can > not be applied to (int) > [javac] myColumnNameIndexes.addActual(aColumnIndex); > > What am I missing? Note: I haven't put any jar in the lib/ directory but > the error doesn't seem to be about any missing jar. Well, I thought it would make the numbers line up better. I've just changed the formatting, not the value. > In addition it seems the latest version is 0.07 but the previous version > was 0.6 ... Isn't that strange? Are we going backwards? ;-) S. |
From: Steve F. <sm...@us...> - 2002-11-02 21:17:39
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory usw-pr-cvs1:/tmp/cvs-serv21393/src/core/com/mockobjects/dynamic Modified Files: Tag: reworked_DynaMock_collection Mock.java Added Files: Tag: reworked_DynaMock_collection MethodMap.java MethodExpectation.java Log Message: Factored out MethodExpectation and MethodMap from Mock --- NEW FILE: MethodMap.java --- /** * Date: Nov 2, 2002 * Time: 5:41:16 PM */ package com.mockobjects.dynamic; import com.mockobjects.Verifiable; import java.util.HashMap; import java.util.Iterator; public class MethodMap implements Verifiable { private HashMap map = new HashMap(); public void setupCall(String methodName, MockCall call) { get(methodName).setupCall(call); } public void expectCall(String methodName, MockCall call) { get(methodName).expectCall(call); } public void expectNotCalled(String methodName) { get(methodName).expectNotCalled(); } public void order( String preceding_method, String subsequent_method ) { get(preceding_method).shouldCallBefore(get(subsequent_method)); } public MethodExpectation startCall(String methodName) { MethodExpectation expectation = get(methodName); expectation.startCall(); return expectation; } public void put(MethodExpectation expectation) { map.put(expectation.name, expectation); } public void verify() { Iterator i = map.values().iterator(); while( i.hasNext() ) { ((MethodExpectation)i.next()).verify(); } } private MethodExpectation get(String methodName) { MethodExpectation expectation = (MethodExpectation)map.get(methodName); if (null == expectation) { expectation = new MethodExpectation(methodName); put(expectation); } return expectation; } } --- NEW FILE: MethodExpectation.java --- /** * Date: Nov 2, 2002 */ package com.mockobjects.dynamic; import junit.framework.Assert; import java.lang.reflect.Method; import com.mockobjects.ExpectationValue; import com.mockobjects.Verifiable; public class MethodExpectation implements Verifiable { final public String name; private ExpectationValue wasCalled; private MockCall call; private MethodMap prerequisites = new MethodMap(); public MethodExpectation(String aName) { name = aName; initializeWasCalled(); } public void expectCall(MockCall aCall) { call = aCall; wasCalled.setExpected(true); } public void setupCall(MockCall aCall) { call = aCall; initializeWasCalled(); } public void expectNotCalled() { wasCalled.setExpectNothing(); } public void shouldCallBefore(MethodExpectation laterMethod) { laterMethod.prerequisites.put(this); } public boolean canBeCalled() { return call != null; } public Object callAndCheckResult(Method method, Object[] args) throws Throwable { Object result = call.call(args); checkResultType(method, result); return result; } public void startCall() { wasCalled.setActual(true); prerequisites.verify(); } public void verify() { wasCalled.verify(); } private void initializeWasCalled() { wasCalled = new ExpectationValue(name + " was called"); } private void checkResultType(Method method, Object result) { Assert.assertTrue("trying to return " + result + " from void method " + method.getName(), (result == Mock.VOID) == (method.getReturnType() == void.class)); } } Index: Mock.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Mock.java,v retrieving revision 1.7 retrieving revision 1.7.4.1 diff -u -r1.7 -r1.7.4.1 --- Mock.java 1 Nov 2002 15:35:40 -0000 1.7 +++ Mock.java 2 Nov 2002 21:17:37 -0000 1.7.4.1 @@ -6,7 +6,6 @@ import com.mockobjects.Verifiable; import junit.framework.Assert; -import junit.framework.AssertionFailedError; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; @@ -27,12 +26,8 @@ * have no methods. */ public static final Predicate[] NO_ARGS = new Predicate[0]; - - - private Map _expectations = new HashMap(); - private Set _not_called_expectations = new HashSet(); - private Map _order_constraints = new HashMap(); - private Set _called_methods = new HashSet(); + + protected MethodMap methods = new MethodMap(); private boolean _strict = false; private Map _default_results = new HashMap(); @@ -73,9 +68,7 @@ * The call to be mocked. */ public void setup( String method_name, MockCall call ) { - _expectations.put( method_name, call ); - _not_called_expectations.remove( method_name ); - _called_methods.add( method_name ); + methods.setupCall(method_name, call); } /** Set up calls to <var>method</var> to return <var>result</var>, @@ -127,9 +120,7 @@ * An object describing the expected call and mocking its behaviour. */ public void expect( String method_name, MockCall call ) { - _expectations.put( method_name, call ); - _not_called_expectations.remove( method_name ); - _called_methods.remove( method_name ); + methods.expectCall(method_name, call); } /** Expect a method call and return a result when it is called. @@ -257,11 +248,11 @@ * An {@link junit.framework.AssertionFailedError} will be thrown if * the method is called. * - * @param method + * @param methodName * The name of the method that will not be called. */ - public void expectNotCalled( String method ) { - _not_called_expectations.add(method); + public void expectNotCalled( String methodName ) { + methods.expectNotCalled(methodName); } /** @@ -271,13 +262,7 @@ * {@link junit.framework.AssertionFailedError} will be thrown. */ public void order( String preceding_method, String subsequent_method ) { - Set preceding_calls = orderConstraintsFor(subsequent_method); - if( null == preceding_calls) { - preceding_calls = new HashSet(); - _order_constraints.put( subsequent_method, preceding_calls ); - } - - preceding_calls.add( preceding_method ); + methods.order(preceding_method, subsequent_method); } /** Called by the {@link java.lang.reflect.Proxy} to mock the behaviour of an @@ -286,54 +271,37 @@ public Object invoke( Object obj, Method method, Object[] args ) throws Throwable { - _called_methods.add( method.getName() ); - + MethodExpectation expectation = methods.startCall(method.getName()); try { - return getClass().getMethod( - method.getName(), method.getParameterTypes() ).invoke( this, args ); + return getMatchingMethod(method).invoke( this, args ); } catch( NoSuchMethodException ex ) { - return mockCall( method, args ); + return mockCall(expectation, method, args ); } } - - protected Object mockCall( Method method, Object[] args ) + + protected Object mockCall(Method method, Object[] args ) throws Throwable { - String method_name = method.getName(); - - assertCanBeCalled( method_name ); - - if( _expectations.containsKey( method_name ) ) { - MockCall expected = (MockCall)_expectations.get(method_name); - - checkCallOrder( method_name ); - return checkResult(method, expected.call( args )); - - } else if( _strict ) { - throw new AssertionFailedError( - "unexpected call to " + method_name ); - } else { - return defaultResult( method.getReturnType() ); - } + return mockCall(methods.startCall(method.getName()), method, args); } - - private Object checkResult(Method method, Object result) { - if( method.getReturnType() == void.class && result != VOID ) { - fail("trying to return " + result + " from void method"); + + protected Object mockCall(MethodExpectation expectation, Method method, Object[] args ) + throws Throwable + { + if( expectation.canBeCalled() ) { + return expectation.callAndCheckResult( method, args ); } - return result; + assertTrue("Unexpected call to " + method.getName(), ! _strict); + + return defaultResult( method.getReturnType() ); } - private void checkCallOrder( String method_name ) { - if( _order_constraints.containsKey(method_name) ) { - assertMethodsHaveBeenCalled(orderConstraintsFor(method_name) ); - } - } - - private Set orderConstraintsFor(String method_name) { - return (Set)_order_constraints.get(method_name); + private Method getMatchingMethod(Method method) + throws NoSuchMethodException + { + return getClass().getMethod( method.getName(), method.getParameterTypes() ); } private Object defaultResult(Class return_type) { @@ -346,33 +314,9 @@ * Not all expected calls were made to this mock object. */ public void verify() { - assertAllExpectedMethodsCalled(); - } - - private void assertAllExpectedMethodsCalled() { - - assertMethodsHaveBeenCalled( _expectations.keySet() ); - } - - private void assertMethodsHaveBeenCalled( Set method_names ) { - Iterator i = method_names.iterator(); - while( i.hasNext() ) { - assertHasBeenCalled( (String)i.next() ); - } - } - - private void assertHasBeenCalled( String method_name ) { - if( !_called_methods.contains(method_name) ) { - fail( "method " + method_name + " was not called" ); - } + methods.verify(); } - private void assertCanBeCalled( String method_name ) { - if( _not_called_expectations.contains(method_name) ) { - fail( "unexpected call to method " + method_name ); - } - } - public Object createInterface( Class interface_class ) { return createInterface(interface_class, this); } |
From: Steve F. <sm...@us...> - 2002-11-02 21:17:17
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory usw-pr-cvs1:/tmp/cvs-serv21164/src/core/test/mockobjects/dynamic Modified Files: Tag: reworked_DynaMock_collection MockTest.java Log Message: Corrected incorrect method calls on interface Index: MockTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockTest.java,v retrieving revision 1.2 retrieving revision 1.2.4.1 diff -u -r1.2 -r1.2.4.1 --- MockTest.java 31 Oct 2002 17:03:46 -0000 1.2 +++ MockTest.java 2 Nov 2002 21:17:13 -0000 1.2.4.1 @@ -47,10 +47,8 @@ } public String objectTypes( Integer n ) throws Throwable { - Method method = getClass().getMethod("objectTypes", - new Class[] { Integer.class } ); - - return (String)mockCall( method , new Object[]{n} ); + Method method = getClass().getMethod("objectTypes", new Class[] { Integer.class } ); + return (String)mockCall(method , new Object[]{n} ); } }; @@ -186,9 +184,9 @@ } public void testCalledExpectationClearedBySubsequentExpecation() { - _mock.expectVoid( "noArgs", Mock.NO_ARGS ); - _interface.noArgs(); - _mock.expectVoid( "noArgs", Mock.NO_ARGS ); + _mock.expectVoid( "voidMethod", Mock.NO_ARGS ); + _interface.voidMethod(); + _mock.expectVoid( "voidMethod", Mock.NO_ARGS ); assertFails("verify did not fail when not all of the expected methods were called", new Runnable() { @@ -320,10 +318,10 @@ } public void testExpectNotCalledClearedBySubsequentExpectation() { - _mock.expectNotCalled("noArgs"); - _mock.expectVoid( "noArgs", Mock.NO_ARGS ); + _mock.expectNotCalled("voidMethod"); + _mock.expectVoid( "voidMethod", Mock.NO_ARGS ); - _interface.noArgs(); + _interface.voidMethod(); _mock.verify(); } |
From: Vincent M. <vm...@oc...> - 2002-11-02 19:43:00
|
Hi, I've just started playing with Dynamic Mocks and it looks just great! From the little I have seen so far, it looks much compact than EasyMock for example. It seems it is also more extensible and has already more features. I had to read the source code and the MockTest class to understand how it works. When is a tutorial scheduled? :-) I also think that the default return value for the String class should be null and not "", as null is what anyone expects when an object has not been defined. Thus, I find myself adding: mock.setupDefaultResult(String.class, null); in the setUp() methods of lots of my test cases. What do you think? Thanks -Vincent |
From: Vincent M. <vm...@oc...> - 2002-11-02 17:31:37
|
Hi, I'm trying to build the mockobject core library by executing "ant jar" and it fails with the following kind of errors: compile-core: [mkdir] Created dir: E:\Dev\mockobjects\mockobjects-java\out\core\classes [javac] Compiling 62 source files to E:\Dev\mockobjects\mockobjects-java\out\core\classes compile-jdk: [mkdir] Created dir: E:\Dev\mockobjects\mockobjects-java\out\jdk\classes [javac] Compiling 38 source files to E:\Dev\mockobjects\mockobjects-java\out\jdk\classes [javac] E:\Dev\mockobjects\mockobjects-java\src\jdk\common\com\mockobjects\sql\C ommonMockResultS etMetaData.java:86: addActual(java.lang.Object) in com.mockobjects.AbstractExpectationCollection can not be applied to (int) [javac] myColumnNameIndexes.addActual(aColumnIndex); What am I missing? Note: I haven't put any jar in the lib/ directory but the error doesn't seem to be about any missing jar. In addition it seems the latest version is 0.07 but the previous version was 0.6 ... Isn't that strange? Are we going backwards? ;-) Thanks -Vincent |
From: Nat P. <np...@us...> - 2002-11-01 15:37:31
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects In directory usw-pr-cvs1:/tmp/cvs-serv32458/src/core/test/mockobjects Added Files: AutoTestSuite.java Log Message: Added AutoTestSuite that finds and loads all tests. Useful for Eclipse users. Made TestCaseMo abstract so that it isn't considered to be an actual test suite by AutoTestSuite objects. --- NEW FILE: AutoTestSuite.java --- package test.mockobjects; import java.io.File; import java.lang.reflect.Modifier; import java.util.StringTokenizer; import junit.framework.*; /** A TestSuite containing all test classes found on the class path in a * hierarchy that matches the class-path and package structure of the system. */ public class AutoTestSuite extends TestSuite { /** Constructs a SystemTestSuite by finding all the test classes and * building the test hierarchy. */ public AutoTestSuite() { super("System Tests"); String class_path= System.getProperty("java.class.path"); String separator= System.getProperty("path.separator"); StringTokenizer path_elements = new StringTokenizer( class_path, separator ); while( path_elements.hasMoreTokens() ) { File root = new File( path_elements.nextToken() ); if( root.isDirectory() ) { TestSuite sub_suite = new AutoTestSuite( root.toString(), root, root ); if( sub_suite.testCount() > 0 ) addTest( sub_suite ); } } } private AutoTestSuite( String name, File root, File dir ) { super( name ); File[] contents = dir.listFiles(); for( int i = 0; i < contents.length; i++ ) { File f = contents[i]; if( f.isDirectory() ) { addNonEmptySuite(new AutoTestSuite( f.getName(), root, f )); } else if( isTestClass(f) ) { try { Class test_class = fileToClass( root, f ); if( isInstantiable(test_class) ) { addNonEmptySuite(new TestSuite(test_class)); } } catch( ClassNotFoundException ex ) { System.err.println("failed to load class " + f ); ex.printStackTrace(); // Continue adding other classes to the test suite } } } } private void addNonEmptySuite(TestSuite suite) { if( suite.testCount() > 0 ) { addTest( suite ); } } private boolean isInstantiable( Class c ) { int mods = c.getModifiers(); return !Modifier.isAbstract(mods) && !Modifier.isInterface(mods) && Modifier.isPublic(mods); } /** Is `f' a class-file containing a test case? */ protected boolean isTestClass( File f ) { String name = f.getName(); return name.endsWith("Test.class") || ( name.endsWith(".class") && name.startsWith("Test") && !isFilenameOfInnerClass(name) ); } private boolean isFilenameOfInnerClass(String name) { return name.indexOf('$') >= 0; } private Class fileToClass( File root, File f ) throws ClassNotFoundException { String class_name = pathToClassName( root.toString(), f.toString() ); return Class.forName( class_name ); } private String pathToClassName( String root, String f ) { int root_len = root.length(); if( !root.endsWith("/") ) root_len++; int tail_len = f.length() - ".class".length(); return f.substring( root_len, tail_len ).replace('/','.'); } /** Constructs and returns a SystemTestSuite. */ public static TestSuite suite() { return new AutoTestSuite(); } public static void main( String[] args ) { junit.swingui.TestRunner.main( new String[]{ AutoTestSuite.class.getName() } ); } } |
From: Nat P. <np...@us...> - 2002-11-01 15:37:31
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/util In directory usw-pr-cvs1:/tmp/cvs-serv32458/src/core/com/mockobjects/util Modified Files: TestCaseMo.java Log Message: Added AutoTestSuite that finds and loads all tests. Useful for Eclipse users. Made TestCaseMo abstract so that it isn't considered to be an actual test suite by AutoTestSuite objects. Index: TestCaseMo.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/util/TestCaseMo.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- TestCaseMo.java 25 Oct 2002 22:06:08 -0000 1.2 +++ TestCaseMo.java 1 Nov 2002 15:37:28 -0000 1.3 @@ -9,7 +9,7 @@ * JUnit interface changes (like the change from 2.x to 3.1) */ -public class TestCaseMo extends TestCase { +public abstract class TestCaseMo extends TestCase { public TestCaseMo(String name) { super(name); |
From: Nat P. <np...@us...> - 2002-11-01 15:36:20
|
Update of /cvsroot/mockobjects/mockobjects-java/src/jdk/1.4/test/mockobjects In directory usw-pr-cvs1:/tmp/cvs-serv32087/src/jdk/1.4/test/mockobjects Added Files: MatchesTest.java Removed Files: Test_Matches.java Log Message: Renamed Test_Matches to MatchesTest to match other test classes --- NEW FILE: MatchesTest.java --- /* * Date: 21-Oct-2002 */ package test.mockobjects; import com.mockobjects.dynamic.Matches; import com.mockobjects.dynamic.Predicate; import junit.framework.TestCase; public class MatchesTest extends TestCase { public MatchesTest(String name) { super(name); } public void testMatches() { Predicate p = new Matches("^hello, (.*)\\.$"); assertTrue(p.eval("hello, world.")); assertTrue(p.eval("hello, mum.")); assertTrue(!p.eval("hello world.")); assertTrue(!p.eval("hello, world")); assertTrue(!p.eval("goodbye, world.")); } } --- Test_Matches.java DELETED --- |
From: Nat P. <np...@us...> - 2002-11-01 15:35:43
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory usw-pr-cvs1:/tmp/cvs-serv31876/src/core/com/mockobjects/dynamic Modified Files: Mock.java Log Message: Fixed some erroneous javadoc comments Index: Mock.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Mock.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- Mock.java 31 Oct 2002 17:03:45 -0000 1.6 +++ Mock.java 1 Nov 2002 15:35:40 -0000 1.7 @@ -154,7 +154,7 @@ * @param method * The name of the method that will be called. * @param arg - * An single object that will be compared with predicate same() + * An single object that will be compared with predicate eq() * @param result * The result that will be returned from this call. Primitive types * must be wrapped in the equivalent Java object, and will be unwrapped @@ -197,7 +197,7 @@ * @param method * The name of the method that will be called. * @param arg - * An single object that will be compared with predicate same() + * An single object that will be compared with predicate eq() */ public void expectVoid(String method, Object arg) { expectVoid( method, P.args(P.eq(arg)) ); @@ -233,7 +233,7 @@ * @param method * The name of the method that will be called. * @param arg - * An single object that will be compared with predicate same() + * An single object that will be compared with predicate eq() * @param exception * The exception or error that will be thrown as a result of this call. */ |
From: Nat P. <np...@us...> - 2002-11-01 15:35:25
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory usw-pr-cvs1:/tmp/cvs-serv31724/src/core/com/mockobjects/dynamic Added Files: CallSequence.java Log Message: Added CallSequence class that tests sequences of calls to a method --- NEW FILE: CallSequence.java --- /** Created on Oct 31, 2002 by npryce * Copyright (c) B13media Ltd. */ package com.mockobjects.dynamic; import java.util.ArrayList; import java.util.List; import com.mockobjects.Verifiable; import com.mockobjects.util.AssertMo; /** A {@link MockCall} that expects a sequence of calls, checks their * arguments and mocks their behaviour. * A test will fail if too few or too many calls are made. */ public class CallSequence extends AssertMo implements MockCall, Verifiable { List _expected_calls = new ArrayList(); int _next_index = 0; public CallSequence() { super(); } public void expect( MockCall call ) { _expected_calls.add(call); } /* The following were copy-and-pasted from Mock.java with minor editing. * Is there any way to remove this duplication? */ /** Expect a method call and return a result when it is called. * * @param args * An array of {@link com.mockobjects.dynamic.Predicate}s that specify the * epxected arguments of the method call. The length of the array defines * the expected arity of the method call. * @param result * The result that will be returned from this call. Primitive types * must be wrapped in the equivalent Java object, and will be unwrapped * before being returned to the caller of the method. */ public void expectReturn( Predicate[] args, Object result ) { expect( new MockReturnCall( args, result ) ); } /** Expect a method call and return a result when it is called. * * @param arg * An single object that will be compared with predicate same() * @param result * The result that will be returned from this call. Primitive types * must be wrapped in the equivalent Java object, and will be unwrapped * before being returned to the caller of the method. */ public void expectReturn( Object arg, Object result ) { expectReturn( P.args(P.eq(arg) ), result); } /** Expect a method call with no parameters and return a result when it is called. * * @param result * The result that will be returned from this call. Primitive types * must be wrapped in the equivalent Java object, and will be unwrapped * before being returned to the caller of the method. */ public void expectReturn( Object result ) { expectReturn( Mock.NO_ARGS, result ); } /** Expect a call to a method with a void return type. * * @param args * An array of {@link com.mockobjects.dynamic.Predicate}s that specify the * epxected arguments of the method call. The length of the array defines * the expected arity of the method call. */ public void expectVoid( Predicate[] args ) { expect( new MockVoidCall( args ) ); } /** Expect a call to a method with a void return type. * * @param method * The name of the method that will be called. * @param arg * An single object that will be compared with predicate eq() */ public void expectVoid( Object arg ) { expectVoid( P.args(P.eq(arg)) ); } /** Expect a call to a method with a void return type and no parameters */ public void expectVoid() { expectVoid( Mock.NO_ARGS ); } /** Expect a method call and throw an exception or error when it is called. * * @param args * An array of {@link com.mockobjects.dynamic.Predicate}s that specify the * epxected arguments of the method call. The length of the array defines * the expected arity of the method call. * @param exception * The exception or error that will be thrown as a result of this call. */ public void expectThrow( Predicate[] args, Throwable exception ) { expect( new MockThrowCall( args, exception ) ); } /** Expect a method call and throw an exception or error when it is called. * * @param arg * An single object that will be compared with predicate eq() * @param exception * The exception or error that will be thrown as a result of this call. */ public void expectThrow( Object arg, Throwable exception ) { expectThrow( P.args(P.eq(arg)), exception ); } /** Expect a method call with no parameters and throw an exception or error when it is called. * * @param exception * The exception or error that will be thrown as a result of this call. */ public void expectThrow( Throwable exception ) { expectThrow( Mock.NO_ARGS, exception ); } public Object call(Object[] args) throws Throwable { if( _next_index >= _expected_calls.size() ) { fail("too many calls"); } MockCall call = (MockCall)_expected_calls.get(_next_index); _next_index++; return call.call( args ); } public void verify() { if( _next_index < _expected_calls.size() ) { fail("too few calls"); } } } |
From: Nat P. <np...@us...> - 2002-11-01 15:35:24
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory usw-pr-cvs1:/tmp/cvs-serv31724/src/core/test/mockobjects/dynamic Added Files: CallSequenceTest.java Log Message: Added CallSequence class that tests sequences of calls to a method --- NEW FILE: CallSequenceTest.java --- /** Created on Oct 31, 2002 by npryce * Copyright (c) B13media Ltd. */ package test.mockobjects.dynamic; import junit.framework.AssertionFailedError; import com.mockobjects.dynamic.CallSequence; import com.mockobjects.dynamic.Mock; import com.mockobjects.dynamic.MockCall; import com.mockobjects.dynamic.P; import com.mockobjects.util.TestCaseMo; public class CallSequenceTest extends TestCaseMo { public CallSequenceTest(String name) { super(name); } public void testCallListInitiallyExpectsNoCalls() throws Throwable { CallSequence call_list = new CallSequence(); call_list.verify(); } public void testCallToEmptyCallListFails() throws Throwable { CallSequence call_list = new CallSequence(); try { call_list.call( new Object[0] ); } catch( AssertionFailedError expected ) { return; } fail( "call to empty call list should fail" ); } public void testCallListPassesArguments() throws Throwable { Mock mock_call_1 = new Mock(); Mock mock_call_2 = new Mock(); CallSequence call_list = new CallSequence(); final Object[] ARGS_1 = { new Object() }; final Object[] ARGS_2 = { new Object() }; mock_call_1.expectVoid( "call", P.args( P.same(ARGS_1) ) ); call_list.expect( (MockCall)mock_call_1.createInterface(MockCall.class) ); mock_call_2.expectVoid( "call", P.args( P.same(ARGS_2) ) ); call_list.expect( (MockCall)mock_call_2.createInterface(MockCall.class) ); call_list.call( ARGS_1 ); call_list.call( ARGS_2 ); mock_call_1.verify(); mock_call_2.verify(); call_list.verify(); } public void testCallListReturnsValue() throws Throwable { Mock mock_call_1 = new Mock(); Mock mock_call_2 = new Mock(); CallSequence call_list = new CallSequence(); final Object[] ARGS_1 = { new Object() }; final Object[] ARGS_2 = { new Object() }; final Object RESULT_1 = new Object(); final Object RESULT_2 = new Object(); mock_call_1.expectReturn( "call", P.args(P.same(ARGS_1)), RESULT_1 ); call_list.expect( (MockCall)mock_call_1.createInterface(MockCall.class) ); mock_call_2.expectReturn( "call", P.args(P.eq(ARGS_2)), RESULT_2 ); call_list.expect( (MockCall)mock_call_2.createInterface(MockCall.class) ); assertSame( RESULT_1, call_list.call( ARGS_1 ) ); assertSame( RESULT_2, call_list.call( ARGS_2 ) ); mock_call_1.verify(); mock_call_2.verify(); call_list.verify(); } public void testCallListThrowsExceptionValue() throws Throwable { Mock mock_call_1 = new Mock(); Mock mock_call_2 = new Mock(); CallSequence call_list = new CallSequence(); final Object[] ARGS_1 = { new Object() }; final Object[] ARGS_2 = { new Object() }; final ExampleException EXCEPTION_1 = new ExampleException(); final ExampleException EXCEPTION_2 = new ExampleException(); mock_call_1.expectThrow( "call", P.args(P.same(ARGS_1)), EXCEPTION_1 ); call_list.expect( (MockCall)mock_call_1.createInterface(MockCall.class) ); mock_call_2.expectThrow( "call", P.args(P.eq(ARGS_2)), EXCEPTION_2 ); call_list.expect( (MockCall)mock_call_2.createInterface(MockCall.class) ); try { call_list.call( ARGS_1 ); fail("expected ExampleException to be thrown"); } catch( ExampleException ex ) { assertSame( EXCEPTION_1, ex ); } try { call_list.call( ARGS_2 ); fail("expected ExampleException to be thrown"); } catch( ExampleException ex ) { assertSame( EXCEPTION_2, ex ); } mock_call_1.verify(); mock_call_2.verify(); call_list.verify(); } static final MockCall CALL = new MockCall() { public Object call( Object[] args ) throws Throwable { return Mock.VOID; } }; static final Object[] NO_ARGS = {}; public void testTooManyCalls() throws Throwable { CallSequence call_list = new CallSequence(); call_list.expect(CALL); call_list.expect(CALL); call_list.call( NO_ARGS ); call_list.call( NO_ARGS ); try { call_list.call( NO_ARGS ); } catch( AssertionFailedError expected ) { return; } fail("third call should have failed"); } public void testTooFewCalls() throws Throwable { CallSequence call_list = new CallSequence(); call_list.expect(CALL); call_list.expect(CALL); call_list.call( NO_ARGS ); try { call_list.verify(); } catch( AssertionFailedError expected ) { return; } fail("verify should have failed"); } private static class ExampleException extends Exception { } } |
From: Nat P. <np...@us...> - 2002-10-31 17:03:50
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory usw-pr-cvs1:/tmp/cvs-serv16430/src/core/com/mockobjects/dynamic Modified Files: P.java Mock.java Added Files: CallCounter.java MockReturnCall.java MockCall.java MockVoidCall.java MockThrowCall.java Removed Files: ExpectedThrow.java ExpectedCall.java ExpectedReturn.java Trainer.java Log Message: Removed Trainer while refactoring Mock class Extracted MockCall interface from ExpectedCall abstract class Moved argument checking into ExpectedCall Changed uses of ExpectedCall to uses of MockCall Renamed ExpectedCall etc. to MockCall etc. Added CallCounter to decorator to show advantages of MockCall interface Cleaned up some javadoc --- NEW FILE: CallCounter.java --- /** Created on Oct 31, 2002 by npryce * Copyright (c) B13media Ltd. */ package com.mockobjects.dynamic; import com.mockobjects.Verifiable; import com.mockobjects.util.AssertMo; public class CallCounter extends AssertMo implements MockCall, Verifiable { private MockCall _call; private int _expected_calls; public CallCounter( int expected_calls, MockCall call ) { _call = call; _expected_calls = expected_calls; } public Object call(Object[] args) throws Throwable { if( _expected_calls == 0 ) { fail( "too many calls" ); } _expected_calls--; return _call.call(args); } public void verify() { if( _expected_calls != 0 ) { fail("expected " + _expected_calls + " additional call(s)" ); } } } --- NEW FILE: MockReturnCall.java --- /* Copyright (c) 2002 Nat Pryce. All rights reserved. * * Created on February 10, 2002, 11:59 PM */ package com.mockobjects.dynamic; import com.mockobjects.dynamic.MockVoidCall; /** An mocked call to a method that returns a result. */ class MockReturnCall extends MockVoidCall { private Object _result; public MockReturnCall( Object result ) { this( ANY_ARGS, result ); } public MockReturnCall( Predicate[] expected_args, Object result ) { super( expected_args ); _result = result; } public Object call( Object[] args ) throws Throwable { super.call(args); return _result; } } --- NEW FILE: MockCall.java --- /** Created on Oct 31, 2002 by npryce * Copyright (c) B13media Ltd. */ package com.mockobjects.dynamic; /** An object that mocks the behaviour of a method call. */ public interface MockCall { Object call( Object[] args ) throws Throwable; } --- NEW FILE: MockVoidCall.java --- /* Copyright (c) 2002 Nat Pryce. All rights reserved. * * Created on February 10, 2002, 11:09 PM */ package com.mockobjects.dynamic; /** An mocked call to a method of that has a void result. */ public class MockVoidCall extends junit.framework.Assert implements MockCall { /** A constant that indicates that the <code>MockVoidCall</code> accepts * any arguments, that is, that the call does not check the arguments * passed to it. */ static final Predicate[] ANY_ARGS = null; private Predicate[] _expected_args; /** Constructs an <code>MockVoidCall</code> that accepts any arguments. * * @param name * The name of the expected method. */ public MockVoidCall() { this( ANY_ARGS ); } /** Constructs a <code>MockVoidCall</code> that checks its arguments. * * @param name * The name of the expected method. * @param expected_args * Predicates that define the valid arguments of the method. */ public MockVoidCall( Predicate[] expected_args ) { _expected_args = expected_args; } public Object call( Object[] args ) throws Throwable { if( isTestingArguments() ) { checkArguments( args ); } return Mock.VOID; } private boolean isTestingArguments() { return _expected_args != null; } private void checkArguments( Object[] args ) { int arg_count = (args == null) ? 0 : args.length; assertEquals( "wrong number of arguments", getArgumentCount(), arg_count ); for( int i = 0; i < arg_count; i++ ) { Object arg = args[i]; checkArgument(i, arg); } } private int getArgumentCount() { return _expected_args.length; } private void checkArgument( int i, Object arg ) { if( !_expected_args[i].eval(arg) ) { fail( "unexpected argument " + (i+1) + ": " + ", expected " + describeArgument(i) + ", was <" + arg + ">" ); } } public String describeArgument( int n ) { if( _expected_args == null ) { return "anything"; } else { return _expected_args[n].toString(); } } } --- NEW FILE: MockThrowCall.java --- /* Copyright (c) 2002 B13media Ltd. All rights reserved. * * Created on February 10, 2002, 11:59 PM */ package com.mockobjects.dynamic; import com.mockobjects.dynamic.MockVoidCall; /** A mocked call to a method results in a thrown exception. */ class MockThrowCall extends MockVoidCall { private Throwable _exception; public MockThrowCall( Throwable exception ) { this( ANY_ARGS, exception ); } public MockThrowCall( Predicate[] expected_args, Throwable exception ) { super( expected_args ); _exception = exception; } public Object call( Object[] args ) throws Throwable { super.call(args); throw _exception; } } Index: P.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/P.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- P.java 25 Oct 2002 21:06:28 -0000 1.3 +++ P.java 31 Oct 2002 17:03:45 -0000 1.4 @@ -18,6 +18,8 @@ public static final Predicate IS_ZERO = eq(new Integer(0)); public static final Predicate IS_NOT_ZERO = not(IS_ZERO); + public static final Predicate[] ANY_ARGS = MockVoidCall.ANY_ARGS; + public static Predicate same( Object o ) { return new IsSame(o); Index: Mock.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Mock.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- Mock.java 27 Oct 2002 22:29:23 -0000 1.5 +++ Mock.java 31 Oct 2002 17:03:45 -0000 1.6 @@ -14,8 +14,7 @@ import java.util.*; -/** - * A convenient class for creating simple +/** A convenient class for creating simple * <a href="http://www.mockobjects.com">mock objects</a>. */ public class Mock @@ -24,13 +23,12 @@ { public static final Object VOID = new Object(); - /** - * A convenient constant for defining expectations for methods that + /** A convenient constant for defining expectations for methods that * have no methods. */ public static final Predicate[] NO_ARGS = new Predicate[0]; - - private String _name; + + private Map _expectations = new HashMap(); private Set _not_called_expectations = new HashSet(); private Map _order_constraints = new HashMap(); @@ -40,12 +38,9 @@ private Map _default_results = new HashMap(); - /** - * Creates a named Mock object, The name will be included in the messages - * of exceptions thrown to indicate violated expectations. + /** Creates a new Mock object. */ - public Mock( String name ) { - _name = name; + public Mock() { setupDefaultResult( byte.class, new Byte((byte)0) ); setupDefaultResult( short.class, new Short((short)0) ); setupDefaultResult( int.class, new Integer(0) ); @@ -57,27 +52,7 @@ setupDefaultResult( String.class, "" ); } - /** - * Creates a Mock object and automatically assigns a name to it. The assigned - * name will include the name of the concrete class and a unique identifier of - * this instance, but will not be particularly user friendly when included in - * error messages. Therefore, it is recommended that you explictly name mock - * objects if you use more than one in the same test case. - */ - public Mock() { - this(null); - _name = super.toString(); - } - - /** - * Returns the Mock's name. - */ - public String toString() { - return _name; - } - - /** - * Is the mock in strict mode? In strict mode the mock will throw + /** Is the mock in strict mode? In strict mode the mock will throw * {@link junit.framework.AssertionFailedError} exceptions when * unexpected method calls are made. Otherwise, the mock ignore * the call or return default arguments. @@ -85,28 +60,25 @@ public boolean isStrict() { return _strict; } - + public void setStrict( boolean strict ) { _strict = strict; } - - /** - * Mock the behaviour of a method without requiring that the method + + /** Mock the behaviour of a method without requiring that the method * actually be called. Note: the ExpectedCall may check the arguments * of the call but should usually not do so. * * @param call * The call to be mocked. */ - public void setup( ExpectedCall call ) { - String methodName = call.getMethodName(); - _expectations.put( methodName, call ); - _not_called_expectations.remove( methodName ); - _called_methods.add( methodName ); + public void setup( String method_name, MockCall call ) { + _expectations.put( method_name, call ); + _not_called_expectations.remove( method_name ); + _called_methods.add( method_name ); } - - /** - * Set up calls to <var>method</var> to return <var>result</var>, + + /** Set up calls to <var>method</var> to return <var>result</var>, * but do not define any expectations upon arguments to those calls. * Arguments of calls to <var>method</var> will be ignored. * @@ -118,11 +90,10 @@ * before being returned to the caller of the method. */ public void setupResult( String method_name, Object result ) { - setup( new ExpectedReturn( method_name, null, result ) ); + setup( method_name, new MockReturnCall( result ) ); } - /** - * Set up calls to <var>method</var> to throw <var>exception</var>, + /** Set up calls to <var>method</var> to throw <var>exception</var>, * but do not define any expectations upon arguments to those calls. * Arguments of calls to <var>method</var> will be ignored. * @@ -132,11 +103,10 @@ * The exception or error that will be thrown as a result of this call. */ public void setupThrow( String method_name, Throwable exception ) { - setup( new ExpectedThrow( method_name, null, exception ) ); + setup( method_name, new MockThrowCall( exception ) ); } - /** - * Set up the value returned by methods that have the given result + /** Set up the value returned by methods that have the given result * type, if no result or exception has been explicitly defined for * the called method by {@link #setupResult}, {@link #setupThrow}, * {@link #expectReturn} or {@link #expectThrow}. @@ -151,21 +121,18 @@ _default_results.put( result_type, result_value ); } - /** - * Expect a method call and mock the behaviour of that call. - * + /** Expect a method call and mock the behaviour of that call. + * * @param call * An object describing the expected call and mocking its behaviour. */ - public void expect( ExpectedCall call ) { - String methodName = call.getMethodName(); - _expectations.put( methodName, call ); - _not_called_expectations.remove( methodName ); - _called_methods.remove( methodName ); + public void expect( String method_name, MockCall call ) { + _expectations.put( method_name, call ); + _not_called_expectations.remove( method_name ); + _called_methods.remove( method_name ); } - - /** - * Expect a method call and return a result when it is called. + + /** Expect a method call and return a result when it is called. * * @param method * The name of the method that will be called. @@ -179,11 +146,10 @@ * before being returned to the caller of the method. */ public void expectReturn( String method, Predicate[] args, Object result ) { - expect( new ExpectedReturn( method, args, result ) ); + expect( method, new MockReturnCall( args, result ) ); } - /** - * Expect a method call and return a result when it is called. + /** Expect a method call and return a result when it is called. * * @param method * The name of the method that will be called. @@ -195,11 +161,10 @@ * before being returned to the caller of the method. */ public void expectReturn( String method, Object arg, Object result ) { - expectReturn(method, P.args(P.eq(arg)), result); + expectReturn( method, P.args(P.eq(arg) ), result); } - /** - * Expect a method call with no parameters and return a result when it is called. + /** Expect a method call with no parameters and return a result when it is called. * * @param method * The name of the method that will be called. @@ -209,7 +174,7 @@ * before being returned to the caller of the method. */ public void expectReturn( String method, Object result ) { - expectReturn(method, NO_ARGS, result ); + expectReturn( method, NO_ARGS, result ); } /** @@ -223,7 +188,7 @@ * the expected arity of the method call. */ public void expectVoid( String method, Predicate[] args ) { - expect( new ExpectedReturn( method, args, VOID ) ); + expect( method, new MockVoidCall( args ) ); } /** @@ -235,7 +200,7 @@ * An single object that will be compared with predicate same() */ public void expectVoid(String method, Object arg) { - expectVoid(method, P.args(P.eq(arg))); + expectVoid( method, P.args(P.eq(arg)) ); } /** @@ -245,11 +210,10 @@ * The name of the method that will be called. */ public void expectVoid(String method) { - expectVoid(method, NO_ARGS); + expectVoid( method, NO_ARGS ); } - /** - * Expect a method call and throw an exception or error when it is called. + /** Expect a method call and throw an exception or error when it is called. * * @param method * The name of the method that will be called. @@ -261,11 +225,10 @@ * The exception or error that will be thrown as a result of this call. */ public void expectThrow( String method, Predicate[] args, Throwable exception ) { - expect( new ExpectedThrow( method, args, exception ) ); + expect( method, new MockThrowCall( args, exception ) ); } - /** - * Expect a method call and throw an exception or error when it is called. + /** Expect a method call and throw an exception or error when it is called. * * @param method * The name of the method that will be called. @@ -278,8 +241,7 @@ expectThrow( method, P.args(P.eq(arg)), exception ); } - /** - * Expect a method call with no parameters and throw an exception or error when it is called. + /** Expect a method call with no parameters and throw an exception or error when it is called. * * @param method * The name of the method that will be called. @@ -289,7 +251,7 @@ public void expectThrow( String method, Throwable exception ) { expectThrow( method, NO_ARGS, exception ); } - + /** * Expect a method not to be called. * An {@link junit.framework.AssertionFailedError} will be thrown if @@ -318,8 +280,7 @@ preceding_calls.add( preceding_method ); } - /** - * Called by the {@link java.lang.reflect.Proxy} to mock the behaviour of an + /** Called by the {@link java.lang.reflect.Proxy} to mock the behaviour of an * invoked method and check expectations. */ public Object invoke( Object obj, Method method, Object[] args ) @@ -335,40 +296,36 @@ return mockCall( method, args ); } } - + protected Object mockCall( Method method, Object[] args ) throws Throwable { String method_name = method.getName(); assertCanBeCalled( method_name ); - + if( _expectations.containsKey( method_name ) ) { - ExpectedCall expected = (ExpectedCall)_expectations.get(method_name); - + MockCall expected = (MockCall)_expectations.get(method_name); + checkCallOrder( method_name ); - if( expected.isTestingArguments() ) { - checkArguments( expected, args ); - } - - return checkResult(method, expected.eval( args )); + return checkResult(method, expected.call( args )); } else if( _strict ) { throw new AssertionFailedError( - _name + ": unexpected call to " + method_name ); + "unexpected call to " + method_name ); } else { return defaultResult( method.getReturnType() ); } } - + private Object checkResult(Method method, Object result) { - if( method.getReturnType() == void.class && VOID != result ) { + if( method.getReturnType() == void.class && result != VOID ) { fail("trying to return " + result + " from void method"); } return result; } - + private void checkCallOrder( String method_name ) { if( _order_constraints.containsKey(method_name) ) { assertMethodsHaveBeenCalled(orderConstraintsFor(method_name) ); @@ -379,24 +336,6 @@ return (Set)_order_constraints.get(method_name); } - private void checkArguments( ExpectedCall expected, Object[] args ) - { - int arg_count = (args == null) ? 0 : args.length; - assertEquals( _name + ": wrong number of arguments to " + - expected.getMethodName() + " method", - expected.getArgumentCount(), arg_count ); - - for( int i = 0; i < arg_count; i++ ) { - Object arg = args[i]; - if( !expected.testArgument( i, arg ) ) { - fail( _name + ": unexpected argument " + (i+1) + - " to " + expected.getMethodName() + " method" + - ", expected " + expected.describeArgument(i) + - ", was " + arg ); - } - } - } - private Object defaultResult(Class return_type) { return _default_results.get(return_type); } @@ -424,22 +363,18 @@ private void assertHasBeenCalled( String method_name ) { if( !_called_methods.contains(method_name) ) { - fail( _name + ": method " + method_name + " was not called" ); + fail( "method " + method_name + " was not called" ); } } private void assertCanBeCalled( String method_name ) { if( _not_called_expectations.contains(method_name) ) { - fail(_name + ": unexpected call to method " + method_name ); + fail( "unexpected call to method " + method_name ); } } - + public Object createInterface( Class interface_class ) { return createInterface(interface_class, this); - } - - public Object getTrainer( Class interfaceClass ) { - return createInterface(interfaceClass, new Trainer( this )); } private Object createInterface(Class interface_class, InvocationHandler handler) { --- ExpectedThrow.java DELETED --- --- ExpectedCall.java DELETED --- --- ExpectedReturn.java DELETED --- --- Trainer.java DELETED --- |
From: Nat P. <np...@us...> - 2002-10-31 17:03:50
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory usw-pr-cvs1:/tmp/cvs-serv16430/src/core/test/mockobjects/dynamic Modified Files: MockTest.java Added Files: CallCounterTest.java Removed Files: MockTrainerTest.java Log Message: Removed Trainer while refactoring Mock class Extracted MockCall interface from ExpectedCall abstract class Moved argument checking into ExpectedCall Changed uses of ExpectedCall to uses of MockCall Renamed ExpectedCall etc. to MockCall etc. Added CallCounter to decorator to show advantages of MockCall interface Cleaned up some javadoc --- NEW FILE: CallCounterTest.java --- /** Created on Oct 31, 2002 by npryce * Copyright (c) B13media Ltd. */ package test.mockobjects.dynamic; import junit.framework.AssertionFailedError; import com.mockobjects.dynamic.CallCounter; import com.mockobjects.dynamic.Mock; import com.mockobjects.dynamic.MockCall; import com.mockobjects.dynamic.P; import com.mockobjects.util.TestCaseMo; public class CallCounterTest extends TestCaseMo { public CallCounterTest( String test ) { super(test); } public void testCallCounterPassesArguments() throws Throwable { Mock mock_call = new Mock(); CallCounter counter = new CallCounter( 1, (MockCall)mock_call.createInterface(MockCall.class) ); final Object[] ARGS = { new Object() }; mock_call.expectVoid( "call", P.args( P.same(ARGS) ) ); counter.call( ARGS ); mock_call.verify(); counter.verify(); } public void testCallCounterReturnsValue() throws Throwable { Mock mock_call = new Mock(); CallCounter counter = new CallCounter( 1, (MockCall)mock_call.createInterface(MockCall.class) ); final Object RESULT = new Object(); mock_call.expectReturn( "call", P.ANY_ARGS, RESULT ); assertSame( RESULT, counter.call( new Object[0] ) ); mock_call.verify(); counter.verify(); } public void testCallCounterThrowsException() throws Throwable { Mock mock_call = new Mock(); CallCounter counter = new CallCounter( 1, (MockCall)mock_call.createInterface(MockCall.class) ); final Object RESULT = new Object(); mock_call.expectThrow( "call", P.ANY_ARGS, new ExampleException() ); try { counter.call( new Object[0] ); } catch( ExampleException ex ) { // expected } mock_call.verify(); counter.verify(); } public void testTooManyCalls() throws Throwable { Mock mock_call = new Mock(); final CallCounter counter = new CallCounter( 2, (MockCall)mock_call.createInterface(MockCall.class) ); counter.call( new Object[0] ); counter.call( new Object[0] ); try { counter.call( new Object[0] ); } catch( AssertionFailedError expected ) { return; } fail( "third call should have failed" ); } public void testTooFewCalls() throws Throwable { Mock mock_call = new Mock(); final CallCounter counter = new CallCounter( 2, (MockCall)mock_call.createInterface(MockCall.class) ); counter.call( new Object[0] ); try { counter.verify(); } catch( AssertionFailedError expected ) { return; } fail( "verify should have failed because of too few calls" ); } class ExampleException extends Exception { } } Index: MockTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- MockTest.java 25 Oct 2002 22:07:48 -0000 1.1 +++ MockTest.java 31 Oct 2002 17:03:46 -0000 1.2 @@ -40,10 +40,6 @@ public static class DerivedMock extends Mock { - DerivedMock( String name ) { - super(name); - } - public boolean was_called = false; public void voidMethod() { @@ -82,11 +78,6 @@ _mock.verify(); } - public void testNamedMock() { - Mock mock = new Mock("Name"); - assertEquals( "Name", mock.toString() ); - } - public void testMockCallToNoArgMethod() { Object result = new Object(); @@ -155,21 +146,36 @@ public void testExpectCallWithSideEffect() { final StringBuffer buf = new StringBuffer(); - _mock.expect( - new ExpectedCall( "sideEffect", - new Predicate[]{ new IsSame(buf) } ) - { - public Object eval( Object[] args ) throws Throwable { - buf.append("hello"); - return Mock.VOID; - } - } ); + _mock.expect( "sideEffect", new MockCall() { + public Object call( Object[] args ) throws Throwable { + assertSame( "wrong buffer", buf, args[0] ); + buf.append("hello"); + return Mock.VOID; + } + } ); _interface.sideEffect( buf ); assertEquals( "hello", buf.toString() ); _mock.verify(); } + public void testFailingExpectationInCallWithSideEffect() { + final StringBuffer buf = new StringBuffer(); + _mock.expect( "sideEffect", new MockCall() { + public Object call( Object[] args ) throws Throwable { + assertSame( "wrong buffer", buf, args[0] ); + buf.append("hello"); + return Mock.VOID; + } + } ); + + assertFails( "should fail with wrong buffer", new Runnable() { + public void run() { + _interface.sideEffect( new StringBuffer() ); + } + } ); + } + public void testNotAllMethodsCalled() { _mock.expectVoid("noArgs", Mock.NO_ARGS); @@ -357,8 +363,8 @@ public void testSetupCallWithSideEffect() { final StringBuffer buf = new StringBuffer(); - _mock.setup( new ExpectedCall("sideEffect") { - public Object eval( Object[] args ) throws Throwable { + _mock.setup( "sideEffect", new MockCall() { + public Object call( Object[] args ) throws Throwable { buf.append("hello"); return Mock.VOID; } @@ -380,8 +386,8 @@ } public void testSetupCallWithSideEffectDoesNotRequireCall() { - _mock.setup( new ExpectedCall("sideEffect") { - public Object eval( Object[] args ) throws Throwable { + _mock.setup( "sideEffect", new MockVoidCall() { + public Object call( Object[] args ) throws Throwable { throw new RuntimeException("should not be called"); } } ); @@ -410,9 +416,9 @@ } fail("should have thrown AssertionFailedError when return from void method"); } - + public void testDerivedMockClass() { - DerivedMock mock = new DerivedMock("Derived"); + DerivedMock mock = new DerivedMock(); ExampleInterface i = (ExampleInterface)Proxy.newProxyInstance( getClass().getClassLoader(), new Class[]{ ExampleInterface.class }, @@ -426,7 +432,7 @@ } public void testDerivedClassPassingInvocationToMockCall() { - DerivedMock mock = new DerivedMock("Derived"); + DerivedMock mock = new DerivedMock(); ExampleInterface i = (ExampleInterface)Proxy.newProxyInstance( getClass().getClassLoader(), new Class[]{ ExampleInterface.class }, --- MockTrainerTest.java DELETED --- |
From: Griffin C. <gri...@ho...> - 2002-10-30 15:02:42
|
Great, thanks. As for Mono, I haven't even tried, so if anyone wants to take a stab, please let me know what you find. -Griffin >From: Jeff Martin <je...@mk...> >To: MockObjects <moc...@li...> >Subject: Re: [MO-java-dev] .NET Mock Objects - Release 0.2 >Date: 30 Oct 2002 10:37:57 +0000 > >I've added this item to the mo front page. > >Only problem is I can't overwrite the last version of the file that's up >at the moment. (Steve can you tweak the file perms for me) > >Just out of interest has anyone had any of the .NET stuff working with >mono? Can't seem to get anything to compile. > > >On Wed, 2002-10-30 at 05:00, Griffin Caprio wrote: > > This is announcing the second release of the .NET Mock Object library, > > version 0.2. > > > > Change log can be viewed here: > > >https://sourceforge.net/project/shownotes.php?group_id=54948&release_id=119404 > > > > Download the release here: > > >https://sourceforge.net/project/showfiles.php?group_id=54948&release_id=119404 > > > > As always, feedback is welcome. > > > > -Griffin > > > > > > > > _________________________________________________________________ > > Choose an Internet access plan right for you -- try MSN! > > http://resourcecenter.msn.com/access/plans/default.asp > > > > > > > > ------------------------------------------------------- > > 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 >-- >jeff martin >information technologist >mkodo limited > >mobile: 44 (0) 78 5547 8331 >phone: 44 (0) 20 2226 4545 >email: je...@mk... > >www.mkodo.com > > > >------------------------------------------------------- >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 _________________________________________________________________ Unlimited Internet access -- and 2 months free! Try MSN. http://resourcecenter.msn.com/access/plans/2monthsfree.asp |
From: Jeff M. <cus...@us...> - 2002-10-30 10:47:28
|
Update of /cvsroot/mockobjects/mockobjects-java/src/j2ee/common/com/mockobjects/servlet In directory usw-pr-cvs1:/tmp/cvs-serv16605/src/j2ee/common/com/mockobjects/servlet Modified Files: MockRequestDispatcher.java Log Message: Check both the request and response Index: MockRequestDispatcher.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/j2ee/common/com/mockobjects/servlet/MockRequestDispatcher.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- MockRequestDispatcher.java 21 Oct 2002 22:53:19 -0000 1.3 +++ MockRequestDispatcher.java 30 Oct 2002 10:47:25 -0000 1.4 @@ -1,7 +1,7 @@ package com.mockobjects.servlet; -import com.mockobjects.MockObject; import com.mockobjects.ExpectationValue; +import com.mockobjects.MockObject; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; @@ -13,11 +13,11 @@ private final ExpectationValue myRequest = new ExpectationValue("request"); private final ExpectationValue myResponse = new ExpectationValue("response"); - public void setExpectedRequest(ServletRequest aRequest){ + public void setExpectedRequest(ServletRequest aRequest) { myRequest.setExpected(aRequest); } - public void setExpectedResponse(ServletResponse aResponse){ + public void setExpectedResponse(ServletResponse aResponse) { myResponse.setExpected(aResponse); } @@ -25,11 +25,13 @@ throws ServletException, IOException { myRequest.setActual(aRequest); + myResponse.setActual(aResponse); } public void include(ServletRequest aRequest, ServletResponse aResponse) throws ServletException, IOException { + myRequest.setActual(aRequest); myResponse.setActual(aResponse); } } |