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/ |