From: Francois B. <fb...@us...> - 2003-08-27 03:56:55
|
Hi, The following four test cases pass in 0.09, but fail in 0.10dev: package jobnudge; import com.mockobjects.dynamic.C; import com.mockobjects.dynamic.Mock; import com.mockobjects.dynamic.OrderedMock; import com.mockobjects.util.AssertMo; import junit.framework.AssertionFailedError; import junit.framework.TestCase; import java.util.Iterator; public class MockTest extends TestCase { private static final Object VALUE =3D new Object(); public void testOrderedMock_OrderedMethods() { final Mock mockIterator =3D new OrderedMock(Iterator.class); final Iterator iterator =3D (Iterator) mockIterator.proxy(); mockIterator.expectAndReturn("hasNext", C.NO_ARGS, Boolean.TRUE); mockIterator.expectAndReturn("next", C.NO_ARGS, VALUE); mockIterator.expectAndReturn("hasNext", C.NO_ARGS, Boolean.FALSE); assertTrue("first return value should be true", iterator.hasNext()); assertSame(VALUE, iterator.next()); assertFalse("next, return false", iterator.hasNext()); mockIterator.verify(); } public void testNonOrderedMock_OrderedMethods() { final Mock mockIterator =3D new Mock(Iterator.class); final Iterator iterator =3D (Iterator) mockIterator.proxy(); mockIterator.expectAndReturn("hasNext", C.NO_ARGS, Boolean.TRUE); mockIterator.expectAndReturn("next", C.NO_ARGS, VALUE); mockIterator.expectAndReturn("hasNext", C.NO_ARGS, Boolean.FALSE); assertTrue("first return value should be true", iterator.hasNext()); assertSame(VALUE, iterator.next()); assertFalse("next, return false", iterator.hasNext()); mockIterator.verify(); } public void testOrderedMock_OutOfOrderMethods() { final Mock mockIterator =3D new OrderedMock(Iterator.class); final Iterator iterator =3D (Iterator) mockIterator.proxy(); mockIterator.expectAndReturn("hasNext", C.NO_ARGS, Boolean.TRUE); mockIterator.expectAndReturn("hasNext", C.NO_ARGS, Boolean.FALSE); mockIterator.expectAndReturn("next", C.NO_ARGS, VALUE); assertTrue("first return value should be true", iterator.hasNext()); boolean failed =3D false; try { assertSame("expect failure", VALUE, iterator.next()); } catch (AssertionFailedError expected) { failed =3D true; } assertTrue("failure occured as expected", failed); failed =3D false; try { assertFalse("next, return false", iterator.hasNext()); } catch (AssertionFailedError expected) { failed =3D true; } assertTrue("failure occured as expected", failed); failed =3D false; try { assertSame("expect success this time around", VALUE, iterator.next()); } catch (AssertionFailedError expected) { failed =3D true; } AssertMo.assertVerifyFails(mockIterator); } public void testNonOrderedMock_OutOfOrderMethods() { final Mock mockIterator =3D new Mock(Iterator.class); final Iterator iterator =3D (Iterator) mockIterator.proxy(); mockIterator.expectAndReturn("hasNext", C.NO_ARGS, Boolean.TRUE); mockIterator.expectAndReturn("hasNext", C.NO_ARGS, Boolean.FALSE); mockIterator.expectAndReturn("next", C.NO_ARGS, VALUE); assertTrue("first return value should be true", iterator.hasNext()); assertSame(VALUE, iterator.next()); assertFalse("next, return false", iterator.hasNext()); mockIterator.verify(); } } I believed that with the regular Mock I could setup values to be returned from each methods, and that the values would be put in a List of some kind. That is, the return values of each methods would be returned in order. OrderedMock on the other hand would expect the methods to be called in the order that the expectations were set. Is my understanding of the DynaMock framework correct ? BTW, I forgot to say that this is terrific work ! I like the DynaMock API quite a bit. Thanks ! Fran=E7ois Developer of Java Gui Builder http://jgb.sourceforge.net/ |
From: Nat P. <nat...@b1...> - 2003-08-27 09:59:41
|
From: "Francois Beausoleil" <fb...@us...> > I believed that with the regular Mock I could setup values to be returned > from each methods, and that the values would be put in a List of some > kind. That is, the return values of each methods would be returned in > order. A regular mock does not guarantee that method invocationsare dispatched to stubs/expectations in any order. A stub/expectation is found for an invocation that matches the signature of the method and actual arguments of the invocation. If you set up two expectations that both match the same signature and actual arguments, they will *not* be executed in the order that you set them up on the Mock. In fact, expectations that were specified later should take precedence over those that were specified earlier, although that behaviour might have been missing from v0.09. If you want to stub or expect a sequence of calls you should create a CallSequence and add it to the mock (or use an OrderedMock). > OrderedMock on the other hand would expect the methods to be > called in the order that the expectations were set. That is correct. > Is my understanding of the DynaMock framework correct ? Not quite (see above). > BTW, I forgot to say that this is terrific work ! I like the DynaMock > API quite a bit. Thanks. Cheers, Nat. |
From: Francois B. <fb...@us...> - 2003-08-27 14:17:19
|
Ok then, I undestand. Will switch to OrderedMock. Thanks ! Fran=E7ois On Wed, 27 Aug 2003 10:49:03 +0100, "Nat Pryce" <nat...@b1...> said: > From: "Francois Beausoleil" <fb...@us...> > > I believed that with the regular Mock I could setup values to be return= ed > > from each methods, and that the values would be put in a List of some > > kind. That is, the return values of each methods would be returned in > > order. [snip] Developer of Java Gui Builder http://jgb.sourceforge.net/ |