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: Steve F. <sm...@us...> - 2003-09-11 21:39:06
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv7270/src/core/test/mockobjects/dynamic Modified Files: MockTest.java CoreMockTest.java Added Files: MockInvocationDispatcher.java MockInvokableFactory.java LIFOInvocationDispatcherTest.java Removed Files: InvocationDispatcherTest.java CallBagTest.java MockCallFactory.java MockCallableCollection.java MockCallableFactory.java MockCallableList.java Log Message: Changed CoreMock to use InvocationDispatcher instead of CallableCollection, and propagated changes. Removed OrderedMock and other unused types. --- NEW FILE: MockInvocationDispatcher.java --- /* * 11-Sep-2003 * Copyright mockobjects.com */ package test.mockobjects.dynamic; import junit.framework.AssertionFailedError; import com.mockobjects.ExpectationCounter; import com.mockobjects.ExpectationValue; import com.mockobjects.MockObject; import com.mockobjects.dynamic.Invocation; import com.mockobjects.dynamic.InvocationDispatcher; import com.mockobjects.dynamic.Invokable; public class MockInvocationDispatcher extends MockObject implements InvocationDispatcher { public ExpectationValue dispatchInvocation = new ExpectationValue("dispatchInvocation"); public Object dispatchResult; public Throwable dispatchThrowable; public ExpectationValue addInvokable = new ExpectationValue("addInvokable"); public ExpectationCounter clearCalls = new ExpectationCounter("clear calls"); public ExpectationCounter verifyCalls = new ExpectationCounter("verify calls"); public AssertionFailedError verifyFailure; public void add(Invokable invokable) { addInvokable.setActual(invokable); } public void clear() { clearCalls.inc(); } public Object dispatch(Invocation invocation) throws Throwable { dispatchInvocation.setActual(invocation); if (null != dispatchThrowable) { throw dispatchThrowable; } return dispatchResult; } /** * @deprecated Use verifyExpectations to verify this object */ public void verify() { verifyCalls.inc(); if (null != verifyFailure) { throw verifyFailure; } } public void verifyExpectations() { super.verify(); } } --- NEW FILE: MockInvokableFactory.java --- /* * Copyright mockobjects.com 11-Sep-2003 * */ package test.mockobjects.dynamic; import com.mockobjects.ExpectationList; import com.mockobjects.ExpectationValue; import com.mockobjects.MockObject; import com.mockobjects.dynamic.InvokableFactory; import com.mockobjects.dynamic.ConstraintMatcher; import com.mockobjects.dynamic.Invokable; public class MockInvokableFactory extends MockObject implements InvokableFactory { public Invokable createCallExpectationResult; public Invokable createReturnCallableResult; public Invokable createThrowableCallableResult; public Invokable createVoidCallableResult; public ExpectationValue createCallExpectation = new ExpectationValue("createCallExpectation"); public ExpectationList parameters = new ExpectationList("parameters"); public Invokable createCallExpectation(Invokable invokable) { createCallExpectation.setActual(invokable); return createCallExpectationResult; } public void expectCreateReturnCallable( String methodName, ConstraintMatcher constraints, Object result) { parameters.addExpectedMany( new Object[] { "createReturnCallable", methodName, constraints, result }); } public Invokable createReturnCallable( String methodName, ConstraintMatcher constraints, Object result) { parameters.addActualMany( new Object[] { "createReturnCallable", methodName, constraints, result }); return createReturnCallableResult; } public void expectCreateThrowableCallable( String methodName, ConstraintMatcher constraints, Throwable throwable) { parameters.addExpectedMany( new Object[] { "createThrowableCallable", methodName, constraints, throwable }); } public Invokable createThrowableCallable( String methodName, ConstraintMatcher constraints, Throwable throwable) { parameters.addActualMany( new Object[] { "createThrowableCallable", methodName, constraints, throwable }); return createThrowableCallableResult; } public void expectCreateVoidCallable( String methodName, ConstraintMatcher constraints) { parameters.addExpectedMany( new Object[] { "createVoidCallable", methodName, constraints }); } public Invokable createVoidCallable( String methodName, ConstraintMatcher constraints) { parameters.addActualMany( new Object[] { "createVoidCallable", methodName, constraints }); return createVoidCallableResult; } } --- NEW FILE: LIFOInvocationDispatcherTest.java --- /* * Created on 20-Aug-2003 * Copyright mockobjects.com */ package test.mockobjects.dynamic; import java.lang.reflect.Method; import junit.framework.TestCase; import com.mockobjects.dynamic.DynamicMockError; import com.mockobjects.dynamic.Invocation; import com.mockobjects.dynamic.LIFOInvocationDispatcher; public class LIFOInvocationDispatcherTest extends TestCase { private Invocation invocation; private LIFOInvocationDispatcher dispatcher; private MockInvokable invokable1 = new MockInvokable(); private MockInvokable invokable2 = new MockInvokable(); public void setUp() throws NoSuchMethodException { invocation = new Invocation(getDummyMethod(), null); dispatcher = new LIFOInvocationDispatcher(); } public void dummyMethod() {}; public void testInvokeFailsWhenEmpty() throws Throwable { try { dispatcher.dispatch(invocation); } catch( DynamicMockError ex ) { assertSame("should be same invocation", invocation, ex.invocation); return; } fail("expected AssertionFailedError"); } public void testInvokesInvokableThatMatches() throws Throwable { Object result = "invoke result"; invokable1.matchesInvocation.setExpected(invocation); invokable1.matchesResult = true; invokable1.invokeInvocation.setExpected(invocation); invokable1.invokeResult = result; dispatcher.add( invokable1 ); dispatcher.dispatch(invocation); invokable1.verifyExpectations(); } public void testReturnsValueFromInvokable() throws Throwable { Object result = "invoke result"; invokable1.matchesResult = true; invokable1.invokeResult = result; dispatcher.add( invokable1 ); assertSame( "should be same result", result, dispatcher.dispatch(invocation) ); } public void testPropagatesExceptionFromInvokable() throws Throwable { Throwable exception = new Throwable("test throwable"); invokable1.matchesResult = true; invokable1.invokeThrow = exception; dispatcher.add( invokable1 ); try { dispatcher.dispatch(invocation); fail("expected exception"); } catch( Throwable t ) { assertSame( "should be same exception", exception, t ); } } public void testInvokeFailsWhenNoInvokablesMatch() throws Throwable { invokable1.matchesResult = false; invokable2.matchesResult = false; dispatcher.add( invokable1 ); dispatcher.add( invokable2 ); try { dispatcher.dispatch(invocation); } catch( DynamicMockError ex ) { assertSame("should be same invocation", invocation, ex.invocation); return; } fail("expected AssertionFailedError"); } public void testLaterInvokablesOverrideEarlierInvokables() throws Throwable { invokable1.matchesInvocation.setExpectNothing(); invokable1.matchesResult = true; invokable1.invokeInvocation.setExpectNothing(); invokable2.matchesInvocation.setExpected(invocation); invokable2.matchesResult = true; invokable2.invokeInvocation.setExpected(invocation); dispatcher.add( invokable1 ); dispatcher.add( invokable2 ); dispatcher.dispatch( invocation ); verifyInvokables(); } public void testSearchesForMatchInLIFOOrder() throws Throwable { invokable1.matchesInvocation.setExpected(invocation); invokable1.matchesResult = true; invokable1.invokeInvocation.setExpected(invocation); invokable1.invokeResult = "one"; invokable2.matchesInvocation.setExpected(invocation); invokable2.matchesResult = false; invokable2.invokeInvocation.setExpectNothing(); dispatcher.add( invokable1 ); dispatcher.add( invokable2 ); assertEquals("Should be invokable1", "one", dispatcher.dispatch( invocation )); verifyInvokables(); } public void testVerifiesAllInvokables() { invokable1.verifyCalls.setExpected(1); invokable2.verifyCalls.setExpected(1); dispatcher.add( invokable1 ); dispatcher.add( invokable2 ); dispatcher.verify(); verifyInvokables(); } public void testClearRemovesAllInvokables() throws Throwable { invokable1.matchesResult = true; dispatcher.add( invokable1 ); dispatcher.clear(); testInvokeFailsWhenEmpty(); } private Method getDummyMethod() throws NoSuchMethodException { return getClass().getDeclaredMethod("dummyMethod", new Class[0]); } private void verifyInvokables() { invokable1.verifyExpectations(); invokable2.verifyExpectations(); } } Index: MockTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockTest.java,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- MockTest.java 9 Jul 2003 23:54:20 -0000 1.18 +++ MockTest.java 11 Sep 2003 21:39:01 -0000 1.19 @@ -1,11 +1,12 @@ package test.mockobjects.dynamic; +import junit.framework.TestCase; + import com.mockobjects.constraint.Constraint; import com.mockobjects.constraint.IsEqual; -import com.mockobjects.dynamic.*; -import com.mockobjects.util.*; - -import junit.framework.*; +import com.mockobjects.dynamic.C; +import com.mockobjects.dynamic.ConstraintMatcher; +import com.mockobjects.dynamic.Mock; public class MockTest extends TestCase { @@ -15,11 +16,10 @@ final ConstraintMatcher METHOD_ONEARG_CONSTRAINTS = C.args(C.eq("oneP1")); final ConstraintMatcher METHOD_TWOARG_CONSTRAINTS = C.args(C.eq("twoP1"), C.eq("twoP2")); - private MockCallableFactory mockCallableFactory = new MockCallableFactory(); - private MockCallableCollection mockCallables = new MockCallableCollection(); - private MockCallable mockCall = new MockCallable("call match"); + private MockInvokableFactory mockCallableFactory = new MockInvokableFactory(); + private MockInvocationDispatcher mockDispatcher = new MockInvocationDispatcher(); + private MockInvokable mockInvokable = new MockInvokable(); - private DummyInterface proxy; private Mock mock; public MockTest(String name) throws Exception { @@ -27,220 +27,227 @@ } public void setUp() { - mock = new Mock(mockCallableFactory, mockCallables, DummyInterface.class, MOCK_NAME); - proxy = (DummyInterface)mock.proxy(); - mockCallableFactory.setupCreateCallExpectation(mockCall); + mock = new Mock(mockCallableFactory, mockDispatcher, DummyInterface.class, MOCK_NAME); + mockCallableFactory.createCallExpectationResult = mockInvokable; } public void testExpectManyAndVoid() throws Throwable { - mockCallableFactory.addExpectedCreateVoidCallable(DummyInterface.METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS); - mockCallableFactory.setupCreateVoidCallable(mockCall); - mockCallableFactory.addExpectedCreateCallExpectation(mockCall); - mockCallables.addExpectedExpect(mockCall); + mockCallableFactory.createVoidCallableResult = mockInvokable; + + mockCallableFactory.expectCreateVoidCallable(DummyInterface.METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS); + mockCallableFactory.createCallExpectation.setExpected(mockInvokable); + + mockDispatcher.addInvokable.setExpected(mockInvokable); mock.expect(DummyInterface.METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS); - Verifier.verifyObject(this); + verifyThis(); } - public void testExpectNoneAndReturn() throws Throwable { - mockCallableFactory.addExpectedCreateReturnCallable(DummyInterface.METHOD_NOARG_NAME, C.NO_ARGS, DummyInterface.METHOD_NOARG_RESULT); - mockCallableFactory.setupCreateReturnCallable(mockCall); - mockCallableFactory.addExpectedCreateCallExpectation(mockCall); - mockCallables.addExpectedExpect(mockCall); + private void verifyThis() { + mockCallableFactory.verify(); + mockDispatcher.verifyExpectations(); + mockInvokable.verifyExpectations(); + } + + public void testExpectNoneAndReturn() throws Throwable { + mockCallableFactory.expectCreateReturnCallable(DummyInterface.METHOD_NOARG_NAME, C.NO_ARGS, DummyInterface.METHOD_NOARG_RESULT); + mockCallableFactory.createReturnCallableResult = mockInvokable; + mockCallableFactory.createCallExpectation.setExpected(mockInvokable); + mockDispatcher.addInvokable.setExpected(mockInvokable); mock.expectAndReturn(DummyInterface.METHOD_NOARG_NAME, DummyInterface.METHOD_NOARG_RESULT); - Verifier.verifyObject(this); + verifyThis(); } public void testExpectNoneAndThrow() throws Throwable { - mockCallableFactory.addExpectedCreateThrowableCallable(DummyInterface.METHOD_NOARG_NAME, C.NO_ARGS, METHOD_EXCEPTION); - mockCallableFactory.setupCreateThrowableCallable(mockCall); - mockCallableFactory.addExpectedCreateCallExpectation(mockCall); - mockCallables.addExpectedExpect(mockCall); + mockCallableFactory.expectCreateThrowableCallable(DummyInterface.METHOD_NOARG_NAME, C.NO_ARGS, METHOD_EXCEPTION); + mockCallableFactory.createThrowableCallableResult = mockInvokable; + mockCallableFactory.createCallExpectation.setExpected(mockInvokable); + mockDispatcher.addInvokable.setExpected(mockInvokable); mock.expectAndThrow(DummyInterface.METHOD_NOARG_NAME, METHOD_EXCEPTION); - Verifier.verifyObject(this); + verifyThis(); } public void testExpectOneAndThrow() throws Throwable { - mockCallableFactory.addExpectedCreateThrowableCallable(DummyInterface.METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, METHOD_EXCEPTION); - mockCallableFactory.setupCreateThrowableCallable(mockCall); - mockCallableFactory.addExpectedCreateCallExpectation(mockCall); - mockCallables.addExpectedExpect(mockCall); + mockCallableFactory.expectCreateThrowableCallable(DummyInterface.METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, METHOD_EXCEPTION); + mockCallableFactory.createThrowableCallableResult = mockInvokable; + mockCallableFactory.createCallExpectation.setExpected(mockInvokable); + mockDispatcher.addInvokable.setExpected(mockInvokable); mock.expectAndThrow(DummyInterface.METHOD_ONEARG_NAME, DummyInterface.METHOD_ONEARG_ARGS[0], METHOD_EXCEPTION); - Verifier.verifyObject(this); + verifyThis(); } public void testExpectNoneAndVoid() throws Throwable { - mockCallableFactory.addExpectedCreateVoidCallable(DummyInterface.METHOD_NOARG_NAME, C.NO_ARGS); - mockCallableFactory.setupCreateVoidCallable(mockCall); - mockCallableFactory.addExpectedCreateCallExpectation(mockCall); - mockCallables.addExpectedExpect(mockCall); + mockCallableFactory.expectCreateVoidCallable(DummyInterface.METHOD_NOARG_NAME, C.NO_ARGS); + mockCallableFactory.createVoidCallableResult = mockInvokable; + mockCallableFactory.createCallExpectation.setExpected(mockInvokable); + mockDispatcher.addInvokable.setExpected(mockInvokable); mock.expect(DummyInterface.METHOD_NOARG_NAME); - Verifier.verifyObject(this); + verifyThis(); } public void testExpectOneAndVoid() throws Throwable { - mockCallableFactory.addExpectedCreateVoidCallable(DummyInterface.METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS); - mockCallableFactory.setupCreateVoidCallable(mockCall); - mockCallableFactory.addExpectedCreateCallExpectation(mockCall); - mockCallables.addExpectedExpect(mockCall); + mockCallableFactory.expectCreateVoidCallable(DummyInterface.METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS); + mockCallableFactory.createVoidCallableResult = mockInvokable; + mockCallableFactory.createCallExpectation.setExpected(mockInvokable); + mockDispatcher.addInvokable.setExpected(mockInvokable); mock.expect(DummyInterface.METHOD_ONEARG_NAME, DummyInterface.METHOD_ONEARG_ARGS[0]); - Verifier.verifyObject(this); + verifyThis(); } public void testExpectManyAndReturn() throws Throwable { - mockCallableFactory.addExpectedCreateReturnCallable(DummyInterface.METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, DummyInterface.METHOD_TWOARG_RESULT); - mockCallableFactory.setupCreateReturnCallable(mockCall); - mockCallableFactory.addExpectedCreateCallExpectation(mockCall); - mockCallables.addExpectedExpect(mockCall); + mockCallableFactory.expectCreateReturnCallable(DummyInterface.METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, DummyInterface.METHOD_TWOARG_RESULT); + mockCallableFactory.createReturnCallableResult = mockInvokable; + mockCallableFactory.createCallExpectation.setExpected(mockInvokable); + mockDispatcher.addInvokable.setExpected(mockInvokable); mock.expectAndReturn(DummyInterface.METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, DummyInterface.METHOD_TWOARG_RESULT); - Verifier.verifyObject(this); + verifyThis(); } public void testExpectManyAndThrow() throws Throwable { - mockCallableFactory.addExpectedCreateThrowableCallable(DummyInterface.METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, METHOD_EXCEPTION); - mockCallableFactory.setupCreateThrowableCallable(mockCall); - mockCallableFactory.addExpectedCreateCallExpectation(mockCall); - mockCallables.addExpectedExpect(mockCall); + mockCallableFactory.expectCreateThrowableCallable(DummyInterface.METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, METHOD_EXCEPTION); + mockCallableFactory.createThrowableCallableResult = mockInvokable; + mockCallableFactory.createCallExpectation.setExpected(mockInvokable); + mockDispatcher.addInvokable.setExpected(mockInvokable); mock.expectAndThrow(DummyInterface.METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, METHOD_EXCEPTION); - Verifier.verifyObject(this); + verifyThis(); } public void testExpectOneAndReturn() throws Throwable { - mockCallableFactory.addExpectedCreateReturnCallable(DummyInterface.METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, DummyInterface.METHOD_ONEARG_RESULT); - mockCallableFactory.setupCreateReturnCallable(mockCall); - mockCallableFactory.addExpectedCreateCallExpectation(mockCall); - mockCallables.addExpectedExpect(mockCall); + mockCallableFactory.expectCreateReturnCallable(DummyInterface.METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, DummyInterface.METHOD_ONEARG_RESULT); + mockCallableFactory.createReturnCallableResult = mockInvokable; + mockCallableFactory.createCallExpectation.setExpected(mockInvokable); + mockDispatcher.addInvokable.setExpected(mockInvokable); mock.expectAndReturn(DummyInterface.METHOD_ONEARG_NAME, DummyInterface.METHOD_ONEARG_ARGS[0], DummyInterface.METHOD_ONEARG_RESULT); - Verifier.verifyObject(this); + verifyThis(); } public void testMatchNoneAndVoid() throws Throwable { - mockCallableFactory.addExpectedCreateVoidCallable(DummyInterface.METHOD_NOARG_NAME, C.NO_ARGS); - mockCallableFactory.setupCreateVoidCallable(mockCall); - mockCallables.addExpectedMatch(mockCall); + mockCallableFactory.expectCreateVoidCallable(DummyInterface.METHOD_NOARG_NAME, C.NO_ARGS); + mockCallableFactory.createVoidCallableResult = mockInvokable; + mockDispatcher.addInvokable.setExpected(mockInvokable); mock.match(DummyInterface.METHOD_NOARG_NAME); - Verifier.verifyObject(this); + verifyThis(); } public void testMatchNoneAndReturn() throws Throwable { - mockCallableFactory.addExpectedCreateReturnCallable(DummyInterface.METHOD_NOARG_NAME, C.NO_ARGS, DummyInterface.METHOD_NOARG_RESULT); - mockCallableFactory.setupCreateReturnCallable(mockCall); - mockCallables.addExpectedMatch(mockCall); + mockCallableFactory.expectCreateReturnCallable(DummyInterface.METHOD_NOARG_NAME, C.NO_ARGS, DummyInterface.METHOD_NOARG_RESULT); + mockCallableFactory.createReturnCallableResult = mockInvokable; + mockDispatcher.addInvokable.setExpected(mockInvokable); mock.matchAndReturn(DummyInterface.METHOD_NOARG_NAME, DummyInterface.METHOD_NOARG_RESULT); - Verifier.verifyObject(this); + verifyThis(); } public void testMatchNoneAndThrow() throws Throwable { - mockCallableFactory.addExpectedCreateThrowableCallable(DummyInterface.METHOD_NOARG_NAME, C.NO_ARGS, METHOD_EXCEPTION); - mockCallableFactory.setupCreateThrowableCallable(mockCall); - mockCallables.addExpectedMatch(mockCall); + mockCallableFactory.expectCreateThrowableCallable(DummyInterface.METHOD_NOARG_NAME, C.NO_ARGS, METHOD_EXCEPTION); + mockCallableFactory.createThrowableCallableResult = mockInvokable; + mockDispatcher.addInvokable.setExpected(mockInvokable); mock.matchAndThrow(DummyInterface.METHOD_NOARG_NAME, METHOD_EXCEPTION); - Verifier.verifyObject(this); + verifyThis(); } public void testMatchOneAndVoid() throws Throwable { - mockCallableFactory.addExpectedCreateVoidCallable(DummyInterface.METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS); - mockCallableFactory.setupCreateVoidCallable(mockCall); - mockCallables.addExpectedMatch(mockCall); + mockCallableFactory.expectCreateVoidCallable(DummyInterface.METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS); + mockCallableFactory.createVoidCallableResult = mockInvokable; + mockDispatcher.addInvokable.setExpected(mockInvokable); mock.match(DummyInterface.METHOD_ONEARG_NAME, DummyInterface.METHOD_ONEARG_ARGS[0]); - Verifier.verifyObject(this); + verifyThis(); } public void testMatchOneAndReturn() throws Throwable { - mockCallableFactory.addExpectedCreateReturnCallable(DummyInterface.METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, DummyInterface.METHOD_ONEARG_RESULT); - mockCallableFactory.setupCreateReturnCallable(mockCall); - mockCallables.addExpectedMatch(mockCall); + mockCallableFactory.expectCreateReturnCallable(DummyInterface.METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, DummyInterface.METHOD_ONEARG_RESULT); + mockCallableFactory.createReturnCallableResult = mockInvokable; + mockDispatcher.addInvokable.setExpected(mockInvokable); mock.matchAndReturn(DummyInterface.METHOD_ONEARG_NAME, DummyInterface.METHOD_ONEARG_ARGS[0], DummyInterface.METHOD_ONEARG_RESULT); - Verifier.verifyObject(this); + verifyThis(); } public void testMatchOneAndThrow() throws Throwable { - mockCallableFactory.addExpectedCreateThrowableCallable(DummyInterface.METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, METHOD_EXCEPTION); - mockCallableFactory.setupCreateThrowableCallable(mockCall); - mockCallables.addExpectedMatch(mockCall); + mockCallableFactory.expectCreateThrowableCallable(DummyInterface.METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, METHOD_EXCEPTION); + mockCallableFactory.createThrowableCallableResult = mockInvokable; + mockDispatcher.addInvokable.setExpected(mockInvokable); mock.matchAndThrow(DummyInterface.METHOD_ONEARG_NAME, DummyInterface.METHOD_ONEARG_ARGS[0], METHOD_EXCEPTION); - Verifier.verifyObject(this); + verifyThis(); } public void testMatchManyAndVoid() throws Throwable { - mockCallableFactory.addExpectedCreateVoidCallable(DummyInterface.METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS); - mockCallableFactory.setupCreateVoidCallable(mockCall); - mockCallables.addExpectedMatch(mockCall); + mockCallableFactory.expectCreateVoidCallable(DummyInterface.METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS); + mockCallableFactory.createVoidCallableResult = mockInvokable; + mockDispatcher.addInvokable.setExpected(mockInvokable); mock.match(DummyInterface.METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS); - Verifier.verifyObject(this); + verifyThis(); } public void testMatchManyAndReturn() throws Throwable { - mockCallableFactory.addExpectedCreateReturnCallable(DummyInterface.METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, DummyInterface.METHOD_TWOARG_RESULT); - mockCallableFactory.setupCreateReturnCallable(mockCall); - mockCallables.addExpectedMatch(mockCall); + mockCallableFactory.expectCreateReturnCallable(DummyInterface.METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, DummyInterface.METHOD_TWOARG_RESULT); + mockCallableFactory.createReturnCallableResult = mockInvokable; + mockDispatcher.addInvokable.setExpected(mockInvokable); mock.matchAndReturn(DummyInterface.METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, DummyInterface.METHOD_TWOARG_RESULT); - Verifier.verifyObject(this); + verifyThis(); } public void testMatchManyAndThrow() throws Throwable { - mockCallableFactory.addExpectedCreateThrowableCallable(DummyInterface.METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, METHOD_EXCEPTION); - mockCallableFactory.setupCreateThrowableCallable(mockCall); - mockCallables.addExpectedMatch(mockCall); + mockCallableFactory.expectCreateThrowableCallable(DummyInterface.METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, METHOD_EXCEPTION); + mockCallableFactory.createThrowableCallableResult = mockInvokable; + mockDispatcher.addInvokable.setExpected(mockInvokable); mock.matchAndThrow(DummyInterface.METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, METHOD_EXCEPTION); - Verifier.verifyObject(this); + verifyThis(); } public void testExpectWithConstraint() throws Throwable { - mockCallableFactory.addExpectedCreateVoidCallable(DummyInterface.METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS); - mockCallableFactory.setupCreateVoidCallable(mockCall); - mockCallableFactory.addExpectedCreateCallExpectation(mockCall); - mockCallables.addExpectedExpect(mockCall); + mockCallableFactory.expectCreateVoidCallable(DummyInterface.METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS); + mockCallableFactory.createVoidCallableResult = mockInvokable; + mockCallableFactory.createCallExpectation.setExpected(mockInvokable); + mockDispatcher.addInvokable.setExpected(mockInvokable); mock.expect(DummyInterface.METHOD_ONEARG_NAME, new IsEqual(DummyInterface.METHOD_ONEARG_ARGS[0])); - Verifier.verifyObject(this); + verifyThis(); } public void testExpectWithConstraintArray() throws Throwable { - mockCallableFactory.addExpectedCreateVoidCallable(DummyInterface.METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS); - mockCallableFactory.setupCreateVoidCallable(mockCall); - mockCallableFactory.addExpectedCreateCallExpectation(mockCall); - mockCallables.addExpectedExpect(mockCall); + mockCallableFactory.expectCreateVoidCallable(DummyInterface.METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS); + mockCallableFactory.createVoidCallableResult = mockInvokable; + mockCallableFactory.createCallExpectation.setExpected(mockInvokable); + mockDispatcher.addInvokable.setExpected(mockInvokable); mock.expect(DummyInterface.METHOD_ONEARG_NAME, new Constraint[] { new IsEqual(DummyInterface.METHOD_ONEARG_ARGS[0])}); - Verifier.verifyObject(this); - mockCallables.verifyExpectations(); + verifyThis(); + mockDispatcher.verifyExpectations(); } } Index: CoreMockTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/CoreMockTest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- CoreMockTest.java 20 Aug 2003 21:51:27 -0000 1.4 +++ CoreMockTest.java 11 Sep 2003 21:39:01 -0000 1.5 @@ -3,13 +3,13 @@ */ package test.mockobjects.dynamic; +import junit.framework.AssertionFailedError; +import junit.framework.TestCase; + import com.mockobjects.dynamic.CoreMock; import com.mockobjects.dynamic.DynamicUtil; +import com.mockobjects.dynamic.Invocation; import com.mockobjects.util.AssertMo; -import com.mockobjects.util.Verifier; - -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; public class CoreMockTest extends TestCase { @@ -17,15 +17,15 @@ private DummyInterface proxy; private CoreMock coreMock; - private MockCallableCollection mockCallables = new MockCallableCollection(); - private MockCallable mockCallable = new MockCallable("coreMock mockCallable"); + private MockInvocationDispatcher mockDispatcher = new MockInvocationDispatcher(); + private MockInvokable mockInvokable = new MockInvokable(); public CoreMockTest(String name) { super(name); } public void setUp() { - coreMock = new CoreMock(DummyInterface.class, MOCK_NAME, mockCallables); + coreMock = new CoreMock(DummyInterface.class, MOCK_NAME, mockDispatcher); try { proxy = (DummyInterface)coreMock.proxy(); @@ -39,7 +39,7 @@ final String originalMessage = "original message"; Object arg = new AssertionFailedError(originalMessage); - mockCallables.callResult = arg; + mockDispatcher.dispatchResult = arg; try { proxy.noArgVoidMethod(); @@ -52,36 +52,15 @@ public void testProxyReturnsConfiguredResult() throws Throwable { final String RESULT = "configured result"; - mockCallables.callResult = RESULT; + mockDispatcher.dispatchResult = RESULT; assertSame("result is returned by coreMock", RESULT, proxy.oneArgMethod("arg")); } - public void testProxySendsAllArgument() throws Throwable { - mockCallables.addExpectedCall(DummyInterface.METHOD_TWOARG_NAME, DummyInterface.METHOD_TWOARG_ARGS); - - proxy.twoArgMethod(DummyInterface.METHOD_TWOARG_ARGS[0], DummyInterface.METHOD_TWOARG_ARGS[1]); - - // Can't use Verifier as we are verifying "verify" - mockCallables.verifyExpectations(); - } - - public void testProxySendsEmptyArrayWhenNoArguments() throws Throwable { - mockCallables.callResult = "result ignored"; - - mockCallables.addExpectedCall(DummyInterface.METHOD_NOARGVOID_NAME, DummyInterface.METHOD_NOARGVOID_ARGS); - - proxy.noArgVoidMethod(); - - Verifier.verifyObject(this); - // Can't use Verifier as we are verifying "verify" - mockCallables.verifyExpectations(); - } - public void testExceptionsPropagatedThroughProxy() throws Throwable { final Throwable throwable = new DummyThrowable(); - mockCallables.callException = throwable; + mockDispatcher.dispatchThrowable = throwable; try { proxy.noArgVoidMethod(); @@ -93,49 +72,50 @@ } public void testMockVerifies() throws Exception { - mockCallables.setExpectedVerifyCalls(1); + mockDispatcher.verifyCalls.setExpected(1); coreMock.verify(); // Can't use Verifier as we are verifying "verify" - mockCallables.verifyExpectations(); + mockDispatcher.verifyExpectations(); } public void testProxyEquality() throws Exception { - mockCallables.callResult = new Boolean(false); + mockDispatcher.dispatchResult = new Boolean(false); - mockCallables.setExpectedCallCalls(0); + mockDispatcher.dispatchInvocation.setExpectNothing(); assertTrue("Proxy equality is implemented directly", proxy.equals(proxy)); - - Verifier.verifyObject(this); + mockDispatcher.verifyExpectations(); } public void testProxyInequality() throws Exception { - mockCallables.callResult = new Boolean(false); + mockDispatcher.dispatchResult = new Boolean(false); - mockCallables.addExpectedCall("equals", new Object[] {"not a proxy"}); + mockDispatcher.dispatchInvocation.setExpected( + new Invocation("equals", new Class[] { Object.class }, boolean.class, + new Object[] { "not a proxy" })); assertFalse("Should handle proxy inequality by calling through", proxy.equals("not a proxy")); - - Verifier.verifyObject(this); + mockDispatcher.verifyExpectations(); } public void testProxyEqualityWithNull() throws Exception { - mockCallables.callResult = new Boolean(true); - mockCallables.addExpectedCall("equals", new Object[] {null}); + mockDispatcher.dispatchResult = new Boolean(true); + mockDispatcher.dispatchInvocation.setExpected( + new Invocation("equals", new Class[] { Object.class }, boolean.class, + new Object[] { null })); assertTrue("Proxy should handle null equality", proxy.equals(null)); - - Verifier.verifyObject(this); + mockDispatcher.verifyExpectations(); } public void testCallingGetMockNameOnProxyReturnsNameOfUnderlyingMock() { - mockCallables.setExpectedCallCalls(0); + mockDispatcher.dispatchInvocation.setExpectNothing(); assertEquals("proxy.getMockName() returns name of underlying mock", MOCK_NAME, proxy.getMockName()); - Verifier.verifyObject(this); + mockDispatcher.verifyExpectations(); } public void testGeneratesMockNameFromInterfaceNameIfNoNameSpecified() throws Exception { @@ -151,40 +131,33 @@ coreMock.verify(); // should not fail on a proxyToString call } - public void testAddAnExpectation() { - mockCallables.addExpectedExpect(mockCallable); + public void testAddAnInvokable() { + mockDispatcher.addInvokable.setExpected(mockInvokable); - coreMock.expect(mockCallable); + coreMock.expect(mockInvokable); - mockCallables.verifyExpectations(); + mockDispatcher.verifyExpectations(); } - public void testAddAStub() { - mockCallables.addExpectedMatch(mockCallable); - - coreMock.stub(mockCallable); - - mockCallables.verifyExpectations(); - } public void testReset() { - mockCallables.resetCalls.setExpected(1); + mockDispatcher.clearCalls.setExpected(1); coreMock.reset(); - mockCallables.verifyExpectations(); + mockDispatcher.verifyExpectations(); } public void testVerifyFailuresIncludeMockName() { - mockCallables.verifyFailure = new AssertionFailedError("verify failure"); + mockDispatcher.verifyFailure = new AssertionFailedError("verify failure"); - mockCallables.setExpectedVerifyCalls(1); + mockDispatcher.verifyCalls.setExpected(1); try { coreMock.verify(); } catch (AssertionFailedError expected) { AssertMo.assertIncludes("Should include mock name", MOCK_NAME, expected.getMessage()); - mockCallables.verifyExpectations(); + mockDispatcher.verifyExpectations(); return; } fail("Should have thrown exception"); --- InvocationDispatcherTest.java DELETED --- --- CallBagTest.java DELETED --- --- MockCallFactory.java DELETED --- --- MockCallableCollection.java DELETED --- --- MockCallableFactory.java DELETED --- --- MockCallableList.java DELETED --- |
From: Steve F. <sm...@us...> - 2003-09-11 21:39:05
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv7270/src/core/com/mockobjects/dynamic Modified Files: CoreMock.java InvocationDispatcher.java Mock.java Added Files: LIFOInvocationDispatcher.java InvokableFactory.java DefaultInvokableFactory.java Removed Files: CallBag.java CallableFactory.java DefaultCallFactory.java OrderedMock.java Log Message: Changed CoreMock to use InvocationDispatcher instead of CallableCollection, and propagated changes. Removed OrderedMock and other unused types. --- NEW FILE: LIFOInvocationDispatcher.java --- /* * Created on 20-Aug-2003 * Copyright mockobjects.com * */ package com.mockobjects.dynamic; import java.util.ArrayList; import java.util.Iterator; import java.util.ListIterator; import com.mockobjects.Verifiable; public class LIFOInvocationDispatcher implements InvocationDispatcher { private ArrayList invokables = new ArrayList(); public Object dispatch(Invocation invocation) throws Throwable { ListIterator i = invokables.listIterator(invokables.size()); while (i.hasPrevious()) { Invokable invokable = (Invokable)i.previous(); if (invokable.matches(invocation)) { return invokable.invoke(invocation); } } throw new DynamicMockError(invocation, "Nothing matches on this mock"); } public void add(Invokable invokable) { invokables.add(invokable); } public void verify() { Iterator i = invokables.iterator(); while (i.hasNext()) { ((Verifiable)i.next()).verify(); } } public void clear() { invokables.clear(); } } --- NEW FILE: InvokableFactory.java --- package com.mockobjects.dynamic; public interface InvokableFactory { Invokable createCallExpectation( Invokable invokable ); Invokable createReturnCallable( String methodName, ConstraintMatcher constraints, Object result ); Invokable createThrowableCallable( String methodName, ConstraintMatcher constraints, Throwable throwable); Invokable createVoidCallable( String methodName, ConstraintMatcher constraints); } --- NEW FILE: DefaultInvokableFactory.java --- package com.mockobjects.dynamic; public class DefaultInvokableFactory implements InvokableFactory { public Invokable createCallExpectation(Invokable callable) { return new CallOnceExpectation(callable); } public Invokable createReturnCallable(String methodName, ConstraintMatcher constraints, Object result) { return createCallSignature(methodName, constraints, createReturnStub(result)); } public Invokable createThrowableCallable(String methodName, ConstraintMatcher constraints, Throwable throwable) { return createCallSignature(methodName, constraints, createThrowStub(throwable)); } public Invokable createVoidCallable(String methodName, ConstraintMatcher constraints) { return createCallSignature(methodName, constraints, createVoidStub()); } private Invokable createCallSignature(String methodName, ConstraintMatcher constraints, Invokable callable) { return new CallSignature( methodName, constraints, callable ); } private Invokable createReturnStub(Object result) { return new ReturnStub(result); } private Invokable createThrowStub( Throwable exception ) { return new ThrowStub(exception); } private Invokable createVoidStub() { return new VoidStub(); } } Index: CoreMock.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CoreMock.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- CoreMock.java 20 Aug 2003 21:51:27 -0000 1.9 +++ CoreMock.java 11 Sep 2003 21:39:01 -0000 1.10 @@ -7,14 +7,14 @@ public class CoreMock implements DynamicMock { - private CallableCollection invocationMatchers; + private InvocationDispatcher invocationDispatcher; private Object proxy; private String name; - public CoreMock(Class mockedClass, String name, CallableCollection callables) { + public CoreMock(Class mockedClass, String name, InvocationDispatcher invocationDispatcher) { this.proxy = Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { mockedClass }, this); this.name = name; - this.invocationMatchers = callables; + this.invocationDispatcher = invocationDispatcher; // callables.addStub(new ProxyIsEqual(this.proxy)); } @@ -33,7 +33,7 @@ } else if (invocation.isMockNameGetter()) { return this.getMockName(); } else { - return invocationMatchers.invoke(invocation); + return invocationDispatcher.dispatch(invocation); } } catch (AssertionFailedError ex) { throw new AssertionFailedError(name + ": " + ex.getMessage()); @@ -42,7 +42,7 @@ public void verify() { try { - invocationMatchers.verify(); + invocationDispatcher.verify(); } catch (AssertionFailedError ex) { throw new AssertionFailedError(name + ": " + ex.getMessage()); } @@ -57,15 +57,15 @@ } public void expect(Invokable invocationMatcher) { - invocationMatchers.addExpect(invocationMatcher); + invocationDispatcher.add(invocationMatcher); } public void stub(Invokable invocationMatcher) { - invocationMatchers.addStub(invocationMatcher); + invocationDispatcher.add(invocationMatcher); } public void reset() { - invocationMatchers.reset(); + invocationDispatcher.clear(); } public static String mockNameFromClass(Class c) { Index: InvocationDispatcher.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/InvocationDispatcher.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- InvocationDispatcher.java 20 Aug 2003 22:38:40 -0000 1.2 +++ InvocationDispatcher.java 11 Sep 2003 21:39:01 -0000 1.3 @@ -1,44 +1,14 @@ /* - * Created on 20-Aug-2003 + * 11-Sep-2003 * Copyright mockobjects.com - * + * */ package com.mockobjects.dynamic; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.ListIterator; - import com.mockobjects.Verifiable; -public class InvocationDispatcher implements Verifiable { - - private ArrayList invokables = new ArrayList(); - - public Object dispatch(Invocation invocation) throws Throwable { - ListIterator i = invokables.listIterator(invokables.size()); - while (i.hasPrevious()) { - Invokable invokable = (Invokable)i.previous(); - if (invokable.matches(invocation)) { - return invokable.invoke(invocation); - } - } - throw new DynamicMockError(invocation, "Nothing matches on this mock"); - } - - public void add(Invokable invokable) { - invokables.add(invokable); - } - - public void verify() { - Iterator i = invokables.iterator(); - while (i.hasNext()) { - ((Verifiable)i.next()).verify(); - } - } - - public void clear() { - invokables.clear(); - } - -} +public interface InvocationDispatcher extends Verifiable { + Object dispatch(Invocation invocation) throws Throwable; + void add(Invokable invokable); + void clear(); +} \ No newline at end of file Index: Mock.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Mock.java,v retrieving revision 1.33 retrieving revision 1.34 diff -u -r1.33 -r1.34 --- Mock.java 9 Aug 2003 13:17:48 -0000 1.33 +++ Mock.java 11 Sep 2003 21:39:01 -0000 1.34 @@ -6,17 +6,17 @@ import com.mockobjects.constraint.Constraint; public class Mock implements Verifiable { - private CallableFactory callableFactory; + private InvokableFactory callableFactory; private DynamicMock coreMock; - public Mock(CallableFactory callableFactory, CallableCollection callables, Class mockedClass, String name) { - coreMock = new CoreMock(mockedClass, name, callables); + public Mock(InvokableFactory callableFactory, InvocationDispatcher invocationDispatcher, Class mockedClass, String name) { + coreMock = new CoreMock(mockedClass, name, invocationDispatcher); this.callableFactory = callableFactory; } public Mock(Class mockedClass, String nonDefaultName) { - this(new DefaultCallFactory(), new CallBag(), mockedClass, nonDefaultName); + this(new DefaultInvokableFactory(), new LIFOInvocationDispatcher(), mockedClass, nonDefaultName); } public Mock(Class mockedClass) { @@ -47,8 +47,8 @@ coreMock.expect(callableFactory.createCallExpectation(callableFactory.createReturnCallable(methodName, args, result))); } - public void expectAndThrow(String methodName, ConstraintMatcher args, Throwable exception) { - coreMock.expect(callableFactory.createCallExpectation(callableFactory.createThrowableCallable(methodName, args, exception))); + public void expectAndThrow(String methodName, ConstraintMatcher args, Throwable throwable) { + coreMock.expect(callableFactory.createCallExpectation(callableFactory.createThrowableCallable(methodName, args, throwable))); } public void match(String methodName, ConstraintMatcher args) { --- CallBag.java DELETED --- --- CallableFactory.java DELETED --- --- DefaultCallFactory.java DELETED --- --- OrderedMock.java DELETED --- |
From: Steve F. <sm...@us...> - 2003-09-11 21:37:53
|
Update of /cvsroot/mockobjects/mockobjects-java In directory sc8-pr-cvs1:/tmp/cvs-serv7061 Modified Files: make_mocks.sh Log Message: changed my jvm version Index: make_mocks.sh =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/make_mocks.sh,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- make_mocks.sh 14 Oct 2002 23:10:26 -0000 1.1 +++ make_mocks.sh 11 Sep 2003 21:37:49 -0000 1.2 @@ -11,7 +11,7 @@ cd mockobjects-java rm -f lib/junit.jar -cp /cygdrive/d/java/junit/3.7/junit.jar lib +cp /cygdrive/d/java/junit/3.8.1/junit.jar lib export PATH=$ANT_HOME/bin:$PATH ant.bat clean |
From: Steve F. <sm...@us...> - 2003-09-11 21:37:38
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects In directory sc8-pr-cvs1:/tmp/cvs-serv6981/src/core/com/mockobjects Modified Files: AbstractExpectationCollection.java ExpectationSet.java Log Message: Fixed bug where use of HashSets meant that ExpectationLists didn't verify properly Index: AbstractExpectationCollection.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/AbstractExpectationCollection.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- AbstractExpectationCollection.java 11 Aug 2003 09:29:37 -0000 1.8 +++ AbstractExpectationCollection.java 11 Sep 2003 21:37:30 -0000 1.9 @@ -3,7 +3,6 @@ import java.util.Collection; import java.util.Enumeration; import java.util.Iterator; -import java.util.HashSet; abstract public class AbstractExpectationCollection extends AbstractExpectation implements ExpectationCollection { @@ -94,8 +93,8 @@ public void verify() { assertEquals( "did not receive the expected collection items.", - new HashSet(getExpectedCollection()), - new HashSet(getActualCollection())); + getExpectedCollection(), + getActualCollection()); } public void addActual(long actual) { Index: ExpectationSet.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/ExpectationSet.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ExpectationSet.java 14 May 2003 14:59:34 -0000 1.3 +++ ExpectationSet.java 11 Sep 2003 21:37:30 -0000 1.4 @@ -26,4 +26,12 @@ protected Collection getExpectedCollection() { return myExpectedItems; } + + public void verify() { + assertEquals( + "did not receive the expected collection items.", + new HashSet(getExpectedCollection()), + new HashSet(getActualCollection())); + } + } |
From: Francois B. <fb...@us...> - 2003-09-11 14:09:12
|
Hello Veny, Just return a Float instance: mock.expectAndReturn("method", C.ANY_ARGS, new Float(4.4f)); You must remember that expectAndReturn returns uses the reflection mechanism and as such cannot return integral values. If you check the documentation for InvocationHandler.invoke(), you will see that Sun says to wrap the returned value in the corresponding wrapper class. This trick also works for any other primitive values: doubles, floats, longs, ints, shorts, bytes and characters. Hope that helps ! Fran=E7ois On Thu, 11 Sep 2003 19:09:38 +0800, "veny" <ve...@p2...> said: > Hi all, >=20 > I am new to mock object. > I am writing some test using DynaMock and wondering what is a good > practice > in returning a float value using Mock.expectAndReturn(String methodName, > Object obj) method. >=20 > Hope to hear from you soon. >=20 > Thanks. >=20 > Veny Developer of Java Gui Builder http://jgb.sourceforge.net/ |
From: veny <ve...@p2...> - 2003-09-11 11:09:40
|
Hi all, I am new to mock object. I am writing some test using DynaMock and wondering what is a good practice in returning a float value using Mock.expectAndReturn(String methodName, Object obj) method. Hope to hear from you soon. Thanks. Veny |
From: Nat P. <nat...@b1...> - 2003-09-09 10:44:32
|
Yes, but with a bit of effort. The trick is to create a Callable decorator that matches a method invocation only when it is called in the correct order. I've attached a test and support classes that implement this which should make things more clear. We are currently working on providing more convenient support for sequences across multiple mocks in the next version of the dynamic mocks. Cheers, Nat. _______________________ Dr. Nathaniel Pryce B13media Ltd. http://www.b13media.com +44 (0)7712 526 661 ----- Original Message ----- From: "François Beausoleil" <fb...@us...> To: <moc...@li...> Sent: Monday, September 08, 2003 2:57 AM Subject: [MO-java-dev] Is it possible to verify call sequence between two or more Mocks ? Hi, I'm using DynaMocks 0.09 and would like to know if one can check the sequence of calls between more than one mock. For example, I am writing tests for an object that should retry operations once on the object, but must call another one in the mean time: public void method() throws FailureException { try { obj.operation(); } catch (FailureException e) { obj = obj2.factory(); obj.operation(); } } So, both mocks should cooperate to determine if the correct sequence of operations was executed. Thanks for any tips or pointers. Bye ! François ------------------------------------------------------- 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 |
From: Steve F. <st...@m3...> - 2003-09-08 06:58:35
|
There's a constructor in Mock (for the release) and CoreMock (for the=20 CVS head) that allows you to pass in the collection that gathers=20 expectations. I think you can achieve what you want by making both mock=20 implementations share a common expectation collection. We have some ideas about how to specify precedence but we have to do=20 some more clean-up first. S. Fran=E7ois Beausoleil wrote: > I'm using DynaMocks 0.09 and would like to know if one can check the=20 > sequence of calls between more than one mock. >=20 > For example, I am writing tests for an object that should retry=20 > operations once on the object, but must call another one in the mean ti= me: >=20 > public void method() throws FailureException { > try { > obj.operation(); > } catch (FailureException e) { > obj =3D obj2.factory(); > obj.operation(); > } > } >=20 > So, both mocks should cooperate to determine if the correct sequence of= =20 > operations was executed. |
From: <fb...@us...> - 2003-09-08 02:06:52
|
Hi, I'm using DynaMocks 0.09 and would like to know if one can check the= =20 sequence of calls between more than one mock. For example, I am writing tests for an object that should retry=20 operations once on the object, but must call another one in the mean = time: public void method() throws FailureException { try { obj.operation(); } catch (FailureException e) { obj =3D obj2.factory(); obj.operation(); } } So, both mocks should cooperate to determine if the correct sequence = of=20 operations was executed. Thanks for any tips or pointers. Bye ! Fran=E7ois |
From: Steven B. <el_...@ho...> - 2003-08-28 15:48:15
|
Hey, I was wondering if you guys are using the patch system because I've submitted a patch to it for CommonMockMultiRowResultSet. I have another that adds support for null values for primitives as well. I can send it to the list if that is the best way to handle these sorts of submissions. Steve "lif is læne" - life is transitory (literally, "life is on loan") Anglo-Saxon proverb _________________________________________________________________ Enter for your chance to IM with Bon Jovi, Seal, Bow Wow, or Mary J Blige using MSN Messenger http://entertainment.msn.com/imastar |
From: Nat P. <nat...@b1...> - 2003-08-27 23:04:14
|
Yes, there should be "match" methods that setup stubs for invocations of void methods. You can work around this by using matchAndReturn and setting the return value as null. Note: returning Void.TYPE from a void method will result in an invocation error because it is a reference to an actual object, and so not void. Cheers, Nat. _______________________ Dr. Nathaniel Pryce B13media Ltd. http://www.b13media.com +44 (0)7712 526 661 ----- Original Message ----- From: "Francois Beausoleil" <fb...@us...> To: <moc...@li...> Sent: Wednesday, August 27, 2003 3:20 PM Subject: [MO-java-dev] Possible match method missing in Mock/OrderedMock Hi, There is expect(), expectAndReturn() and expectAndThrow. For the match methods we have matchAndReturn() and matchAndThrow(). There are no match() methods. It is possible to simulate this by using matchAndReturn() and returning Void.TYPE though. Should the Mock/OrderedMock implementations have simple match() methods ? Even though the methods return no element, they might be called anyway. For example, Hibernate has a Session object. In one test, I expect() that disconnect() will be called. Then, in other tests, I know this method will be called, so I simply match("disconnect", C.NO_ARGS). Currently, I need to matchAndReturn("disconnect", C.NO_ARGS, Void.TYPE). Thanks ! François Developer of Java Gui Builder http://jgb.sourceforge.net/ ------------------------------------------------------- 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 |
From: Francois B. <fb...@us...> - 2003-08-27 14:20:19
|
Hi, There is expect(), expectAndReturn() and expectAndThrow. For the match methods we have matchAndReturn() and matchAndThrow(). There are no match() methods. It is possible to simulate this by using matchAndReturn() and returning Void.TYPE though. Should the Mock/OrderedMock implementations have simple match() methods ? Even though the methods return no element, they might be called anyway. For example, Hibernate has a Session object. In one test, I expect() that disconnect() will be called. Then, in other tests, I know this method will be called, so I simply match("disconnect", C.NO_ARGS).=20 Currently, I need to matchAndReturn("disconnect", C.NO_ARGS, Void.TYPE). Thanks ! Fran=E7ois Developer of Java Gui Builder http://jgb.sourceforge.net/ |
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/ |
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 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-26 21:38:44
|
If you want to mock the behaviour of a *sequence* of calls to a Mock you should have used an OrderedMock (or a CallSequence that you add to a normal Mock), in both v0.09 and the current CVS version. The fact that your tests passed in 0.09 sounds like a lucky outcome of the internal implementation rather than documented/tested behaviour of the API itself. Warning: don't rely on the current CVS version being stable. The dynamic API is still being worked out by the mockobjects team. Cheers, Nat. _______________________ Dr. Nathaniel Pryce B13media Ltd. http://www.b13media.com +44 (0)7712 526 661 ----- Original Message ----- From: "Francois Beausoleil" <fb...@us...> To: <moc...@li...> Sent: Tuesday, August 26, 2003 10:10 PM Subject: [MO-java-dev] expectAndReturn does not behave the same as in 0.09 ? Hi, Here's my test implementation: private final Mock mockNewsIterator = new Mock(Iterator.class); private final Iterator newsIterator = (Iterator) mockNewsIterator.proxy(); public void testInstructsTheCallerToPrintTheBodyAgainWhenMoreItemsRemain() throws JspException { mockNewsIterator.expectAndReturn("hasNext", C.NO_ARGS, Boolean.TRUE); mockNewsIterator.expectAndReturn("next", C.NO_ARGS, new NewsItem()); mockNewsIterator.expectAndReturn("hasNext", C.NO_ARGS, Boolean.FALSE); assertEquals(TagSupport.EVAL_BODY_AGAIN, tag.doAfterBody()); assertEquals(TagSupport.SKIP_BODY, tag.doAfterBody()); mockNewsIterator.verify(); } When I had 0.09 installed, this test was not failing. Now, I have 0.10dev (CVS pserver as of 2003/08/26 ~ 15:30), and the test fails. Does this mean that I should switch to using OrderedMock for such tests ? What I am trying to achieve here is to have the mockIterator return true once, and false once. If it is called any more times, it should fail. In the mean time, there should be one call to the next() method. Thanks, François Developer of Java Gui Builder http://jgb.sourceforge.net/ ------------------------------------------------------- This SF.net email is sponsored by: VM Ware With VMware you can run multiple operating systems on a single machine. WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines at the same time. Free trial click here:http://www.vmware.com/wl/offer/358/0 _______________________________________________ Mockobjects-java-dev mailing list Moc...@li... https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev |
From: Francois B. <fb...@us...> - 2003-08-26 21:10:20
|
Hi, Here's my test implementation: private final Mock mockNewsIterator =3D new Mock(Iterator.class); private final Iterator newsIterator =3D (Iterator) mockNewsIterator.proxy(); public void testInstructsTheCallerToPrintTheBodyAgainWhenMoreItemsRemain() throws JspException { mockNewsIterator.expectAndReturn("hasNext", C.NO_ARGS, Boolean.TRUE); mockNewsIterator.expectAndReturn("next", C.NO_ARGS, new NewsItem()); mockNewsIterator.expectAndReturn("hasNext", C.NO_ARGS, Boolean.FALSE); assertEquals(TagSupport.EVAL_BODY_AGAIN, tag.doAfterBody()); assertEquals(TagSupport.SKIP_BODY, tag.doAfterBody()); mockNewsIterator.verify(); } When I had 0.09 installed, this test was not failing. Now, I have 0.10dev (CVS pserver as of 2003/08/26 ~ 15:30), and the test fails. Does this mean that I should switch to using OrderedMock for such tests ? What I am trying to achieve here is to have the mockIterator return true once, and false once. If it is called any more times, it should fail.=20 In the mean time, there should be one call to the next() method. Thanks, Fran=E7ois Developer of Java Gui Builder http://jgb.sourceforge.net/ |
From: Francois B. <fb...@us...> - 2003-08-26 19:46:52
|
Hi ! I was using MockPrintWriter and had quite a bit of NullPointerExceptions. So, I corrected them using the following tests and implementation. Thanks ! Fran=E7ois PS: My log message requires a fixed-width font to make it understandable... Log Message: Made com.mockobjects.util.AssertMo more robust to null values by adding code to explicitely check for null values. assertIncludes, assertExcludes and assertStartsWith now behave according to this table: targetString null not-null expectedString |--------------------------- null | pass fail not-null | fail compare & pass/fail Patch included and attached in case mailer breaks it Index: src/core/com/mockobjects/util/AssertMo.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/util/AssertM= o.java,v retrieving revision 1.3 diff -U6 -r1.3 AssertMo.java --- src/core/com/mockobjects/util/AssertMo.java 18 May 2003 20:59:40 -0000 1.3 +++ src/core/com/mockobjects/util/AssertMo.java 26 Aug 2003 19:38:42 -0000 @@ -28,12 +28,30 @@ } =20 public static void assertExcludes( String description, String excludeString, String targetString) { + if (excludeString =3D=3D null) { + if (targetString =3D=3D null) { + return; + } + + fail(description + + "\nExclude String: <null>" + + "\n Target String: " + + targetString); + } + + if (null =3D=3D targetString) { + fail(description + + "\nExclude String: " + + excludeString + + "\n Target String: <null>"); + } + assertTrue( description + "\nExclude String: " + excludeString + "\n Target String: " + targetString, @@ -41,12 +59,30 @@ } =20 public static void assertIncludes( String description, String includeString, String targetString) { + if (includeString =3D=3D null) { + if (targetString =3D=3D null) { + return; + } + + fail(description + + "\nInclude String: <null>" + + "\n Target String: " + + targetString); + } + + if (null =3D=3D targetString) { + fail(description + + "\nInclude String: " + + includeString + + "\n Target String: <null>"); + } + assertTrue( description + "\nInclude String: " + includeString + "\n Target String: " + targetString, @@ -54,12 +90,30 @@ } =20 public static void assertStartsWith( String description, String startString, String targetString) { + if (startString =3D=3D null) { + if (targetString =3D=3D null) { + return; + } + + fail(description + + "\nInclude String: <null>" + + "\n Target String: " + + targetString); + } + + if (null =3D=3D targetString) { + fail(description + + "\n Start String: " + + startString + + "\nTarget String: <null>"); + } + assertTrue( description + "\n Start String: " + startString + "\nTarget String: " + targetString, Index: src/core/test/mockobjects/TestAssertMo.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/TestAssertM= o.java,v retrieving revision 1.3 diff -U6 -r1.3 TestAssertMo.java --- src/core/test/mockobjects/TestAssertMo.java 27 Oct 2002 22:24:13 -0000 1.3 +++ src/core/test/mockobjects/TestAssertMo.java 26 Aug 2003 19:38:47 -0000 @@ -172,7 +172,78 @@ assertEquals(TEST_MESSAGE, expected.getMessage()); return; } fail("Should have thrown an exception"); } =20 + public void testStartsWithNull() { + try { + AssertMo.assertStartsWith("description", null, "blabla"); + } catch (AssertionFailedError expected) { + return; + } + + fail("Should have failed"); + } + + public void testStartsWithAndTargetNull() { + try { + AssertMo.assertStartsWith("description", "abc", null); + } catch (AssertionFailedError expected) { + return; + } + + fail("Should have failed"); + } + + public void testIncludesNull() { + try { + AssertMo.assertIncludes("description", null, "blabla"); + } catch (AssertionFailedError expected) { + return; + } + + fail("Should have failed"); + } + + public void testIncludesAndTargetNull() { + try { + AssertMo.assertIncludes("description", "abc", null); + } catch (AssertionFailedError expected) { + return; + } + + fail("Should have failed"); + } + + public void testExcludesNull() { + try { + AssertMo.assertExcludes("description", null, "blabla"); + } catch (AssertionFailedError expected) { + return; + } + + fail("Should have failed"); + } + + public void testExcludesAndTargetNull() { + try { + AssertMo.assertExcludes("description", "abc", null); + } catch (AssertionFailedError expected) { + return; + } + + fail("Should have failed"); + } + + public void testExcludesNullNullSucceeds() { + AssertMo.assertExcludes("description", null, null); + } + + public void testIncludesNullNullSucceeds() { + AssertMo.assertExcludes("description", null, null); + } + + public void teststartsWithNullNullSucceeds() { + AssertMo.assertExcludes("description", null, null); + } } Developer of Java Gui Builder http://jgb.sourceforge.net/ |
From: Steve F. <sm...@us...> - 2003-08-23 08:14:19
|
Update of /cvsroot/mockobjects/mockobjects-java/src/jdk/common/com/mockobjects/sql In directory sc8-pr-cvs1:/tmp/cvs-serv21886/src/jdk/common/com/mockobjects/sql Modified Files: CommonMockConnection.java Log Message: Added comment to explain deprecation Index: CommonMockConnection.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/jdk/common/com/mockobjects/sql/CommonMockConnection.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- CommonMockConnection.java 21 Feb 2003 12:17:38 -0000 1.7 +++ CommonMockConnection.java 21 Aug 2003 21:14:54 -0000 1.8 @@ -141,7 +141,8 @@ /** * @deprecated - * Add an SQL string to use with a prepared staement. + * Add an SQL string to use with a prepared statement. + * Use setupAddPreparedStatement() instead */ public void addExpectedPreparedStatementString(String sql) { myPreparedStatementStrings.addExpected(sql); |
From: Barry K. <bk...@in...> - 2003-08-22 22:05:41
|
Nat Pryce wrote: > That's a good idea. Can you submit that as a feature request via > Sourceforge? Done (793507). -bk |
From: Nat P. <nat...@b1...> - 2003-08-22 19:51:58
|
That's a good idea. Can you submit that as a feature request via Sourceforge? Request 4 is impossible for most constraints (because a Constraint has no concept of "type") unless we extend the Constraint interface with methods that to perform early checks. However, I would rather keep the Constraint interface as simple as possible to make it trivially easy to write new Constraints. That approach has helped make the Constraint concept very easy for new users to understand and use, and also kept the Constraint interface very stable (it hasn't changed since first introduced). Cheers, Nat. _______________________ Dr. Nathaniel Pryce B13media Ltd. http://www.b13media.com +44 (0)7712 526 661 ----- Original Message ----- From: "Barry Kaplan" <bk...@in...> To: "mockobjects" <moc...@li...> Sent: Friday, August 22, 2003 2:29 PM Subject: [MO-java-dev] expect() validations? > (Steve) > > As part of the latest DM overhual, is the issue of performing some > validation (ie, fail fast) of expectations? For example, given: > > public interface Foo { > public void bar(Blob blob); > } > ... > // 1. no method tweetle on interface > mockFoo.expect("tweetle", aBlob); > // 2. no bar method that takes two arguments > mockFoo.expect("bar", C.args(C.eq(aBlob), C.eq(aTweetle))); > // 3. no bar method that returns a Tweetle > mockFoo.expectAndReturn("bar", aBlob, aTweetle); > // 4. no bar method that takes a Tweetle argument > mockFoo.expect("bar", C.eq(aTweetle)); > > ---- > > 1, 2, 3 /could/ be done with the current design. It just isnt' resulting > strange test executions that could have failed immediatly at setup time. > > 4 would require some method of "knowing" a constraint's type. That is > the type of its argument. Of course this may not always be possible, but > when it is could be used to help validate the expectations. > > -bk > > > > > > > ------------------------------------------------------- > This SF.net email is sponsored by: VM Ware > With VMware you can run multiple operating systems on a single machine. > WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines > at the same time. Free trial click here:http://www.vmware.com/wl/offer/358/0 > _______________________________________________ > Mockobjects-java-dev mailing list > Moc...@li... > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev |
From: Barry K. <bk...@in...> - 2003-08-22 13:26:48
|
(Steve) As part of the latest DM overhual, is the issue of performing some validation (ie, fail fast) of expectations? For example, given: public interface Foo { public void bar(Blob blob); } ... // 1. no method tweetle on interface mockFoo.expect("tweetle", aBlob); // 2. no bar method that takes two arguments mockFoo.expect("bar", C.args(C.eq(aBlob), C.eq(aTweetle))); // 3. no bar method that returns a Tweetle mockFoo.expectAndReturn("bar", aBlob, aTweetle); // 4. no bar method that takes a Tweetle argument mockFoo.expect("bar", C.eq(aTweetle)); ---- 1, 2, 3 /could/ be done with the current design. It just isnt' resulting strange test executions that could have failed immediatly at setup time. 4 would require some method of "knowing" a constraint's type. That is the type of its argument. Of course this may not always be possible, but when it is could be used to help validate the expectations. -bk |
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv30075/src/core/com/mockobjects/dynamic Modified Files: Invocation.java AbstractCallableCollection.java CallBag.java CallableArrayList.java DefaultCallFactory.java CallableFactory.java VoidStub.java CallOnceExpectation.java CallSequence.java CoreMock.java ReturnStub.java CallableList.java CallableCollection.java DynamicMock.java CallStub.java ThrowStub.java CallSignature.java Removed Files: Callable.java Log Message: First move towards Invokable-based refactoring Index: Invocation.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Invocation.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- Invocation.java 6 Jul 2003 23:24:09 -0000 1.1 +++ Invocation.java 20 Aug 2003 21:51:27 -0000 1.2 @@ -1,27 +1,103 @@ -/* - * Copyright mockobjects.com 05-Jul-2003 - */ package com.mockobjects.dynamic; import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; -public class Invocation extends Object { - final public String methodName; - final public Object[] args; - - public Invocation(Method method, Object[] args) { - this(method.getName(), args == null ? new Object[0] : args); - } - - public Invocation(String methodName, Object[] args) { - this.methodName = methodName; - this.args = args; - } - public String getMethodName() { - return methodName; - } - public String toString() { - return DynamicUtil.methodToString(getMethodName(), args); - } +/** An object that holds information about a call dispatched to + * a Mock object for err... mocking. + */ +// TODO Simplify this (smgf) +public class Invocation +{ + private String name; + private List parameterTypes; + private Class returnType; + private List parameterValues; + + public Invocation( String name, Class[] parameterTypes, + Class returnType, Object[] parameterValues ) + { + this.name = name; + this.parameterTypes = Arrays.asList(parameterTypes); + this.returnType = returnType; + if( parameterValues == null ) { + this.parameterValues = new ArrayList(0); + } else { + this.parameterValues = Arrays.asList(parameterValues); + } + } + + public Invocation( Method method, Object[] parameterValues ) { + this( method.getName(), method.getParameterTypes(), + method.getReturnType(), parameterValues ); + } + + public String getMethodName() { + return name; + } + + public List getParameterTypes() { + return Collections.unmodifiableList(parameterTypes); + } + + public List getParameterValues() { + return Collections.unmodifiableList(parameterValues); + } + + public Class getReturnType() { + return returnType; + } + + public String toString() { + return DynamicUtil.methodToString( name, parameterValues.toArray() ); + } + + public boolean equals( Object o ) { + if( o instanceof Invocation ) { + return this.equals((Invocation)o); + } else { + return false; + } + } + + public int hashCode() { + return name.hashCode() ^ + listHashCode(parameterTypes) ^ + returnType.hashCode() ^ + listHashCode(parameterValues); + } + + private int listHashCode( List array ) { + int hashCode = 0; + for( Iterator i = array.iterator(); i.hasNext(); ) { + hashCode ^= i.next().hashCode(); + } + return hashCode; + } + + public boolean equals( Invocation call ) { + return call != null + && name.equals(call.name) + && parameterTypes.equals( call.parameterTypes ) + && returnType.equals( call.returnType ) + && parameterValues.equals( call.parameterValues ); + } + + boolean isCheckingEqualityOnProxy() { + return name.equals("equals") + && parameterValues.size() == 1 + && parameterValues.get(0) != null + && Proxy.isProxyClass(parameterValues.get(0).getClass()); + } + + boolean isMockNameGetter() { + return name.equals("getMockName") + && parameterValues.size() == 0; + } } Index: AbstractCallableCollection.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/AbstractCallableCollection.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- AbstractCallableCollection.java 9 Aug 2003 13:18:30 -0000 1.5 +++ AbstractCallableCollection.java 20 Aug 2003 21:51:27 -0000 1.6 @@ -17,7 +17,7 @@ } abstract public String getDescription(); - abstract public Object call(Invocation invocation) throws Throwable; + abstract public Object invoke(Invocation invocation) throws Throwable; public boolean matches(Invocation invocation) { throw new AssertionFailedError("matches() operation not supported in CallCollection"); @@ -28,11 +28,11 @@ stubCalls.clear(); } - public void addExpect(Callable call) { + public void addExpect(Invokable call) { expectedCalls.add(call); } - public void addStub(Callable call) { + public void addStub(Invokable call) { stubCalls.add(call); } @@ -40,8 +40,8 @@ expectedCalls.verify(); } - protected Callable lastStubCall(Invocation invocation) throws AssertionFailedError { - Callable foundCall = stubCalls.lastMatchingCall(invocation); + protected Invokable lastStubCall(Invocation invocation) throws AssertionFailedError { + Invokable foundCall = stubCalls.lastMatchingCall(invocation); if (foundCall == null) { throw createUnexpectedCallError(invocation); } Index: CallBag.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallBag.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- CallBag.java 9 Jul 2003 02:14:00 -0000 1.9 +++ CallBag.java 20 Aug 2003 21:51:27 -0000 1.10 @@ -13,13 +13,13 @@ super(expectedCalls, stubCalls); } - public Object call(Invocation invocation) throws Throwable { - Callable foundCall = expectedCalls.lastMatchingCall(invocation); + public Object invoke(Invocation invocation) throws Throwable { + Invokable foundCall = expectedCalls.lastMatchingCall(invocation); if (foundCall == null) { foundCall = lastStubCall(invocation); } - return foundCall.call(invocation); + return foundCall.invoke(invocation); } public String getDescription() { @@ -32,7 +32,7 @@ expectedCalls.apply( new CallableList.Handler() { - public Callable handle(int index, Callable callable) { + public Invokable handle(int index, Invokable callable) { buf.append(callable.getDescription()); buf.append("\n"); return null; Index: CallableArrayList.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallableArrayList.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- CallableArrayList.java 9 Jul 2003 02:14:00 -0000 1.2 +++ CallableArrayList.java 20 Aug 2003 21:51:27 -0000 1.3 @@ -7,7 +7,7 @@ public class CallableArrayList implements CallableList { private ArrayList callables = new ArrayList(); - public void add(Callable callable) { + public void add(Invokable callable) { callables.add(callable); } @@ -15,8 +15,8 @@ return callables.isEmpty(); } - public Callable get(int index) { - return (Callable)callables.get(index); + public Invokable get(int index) { + return (Invokable)callables.get(index); } public int size() { @@ -27,14 +27,14 @@ callables.clear(); } - public Callable lastMatchingCall(Invocation invocation) { + public Invokable lastMatchingCall(Invocation invocation) { int index = callables.lastIndexOf(new MatcherHack(invocation)); return index > -1 ? get(index) : null; } - public Callable apply(final CallableList.Handler handler) { + public Invokable apply(final CallableList.Handler handler) { for (int i = 0; i < callables.size(); i++) { - Callable result = handler.handle(i, (Callable)callables.get(i)); + Invokable result = handler.handle(i, (Invokable)callables.get(i)); if (null != result) { return result; } @@ -44,7 +44,7 @@ public void verify() { apply(new Handler() { - public Callable handle(int index, Callable callable) { + public Invokable handle(int index, Invokable callable) { callable.verify(); return null; } @@ -54,6 +54,6 @@ private class MatcherHack { private Invocation invocation; public MatcherHack(Invocation invocation) {this.invocation = invocation; } - public boolean equals(Object obj) { return ((Callable)obj).matches(invocation); } + public boolean equals(Object obj) { return ((Invokable)obj).matches(invocation); } } } Index: DefaultCallFactory.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/DefaultCallFactory.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- DefaultCallFactory.java 9 Aug 2003 13:18:15 -0000 1.7 +++ DefaultCallFactory.java 20 Aug 2003 21:51:27 -0000 1.8 @@ -2,35 +2,35 @@ public class DefaultCallFactory implements CallableFactory { - public Callable createCallExpectation(Callable callable) { + public Invokable createCallExpectation(Invokable callable) { return new CallOnceExpectation(callable); } - public Callable createReturnCallable(String methodName, ConstraintMatcher constraints, Object result) { + public Invokable createReturnCallable(String methodName, ConstraintMatcher constraints, Object result) { return createCallSignature(methodName, constraints, createReturnStub(result)); } - public Callable createThrowableCallable(String methodName, ConstraintMatcher constraints, Throwable throwable) { + public Invokable createThrowableCallable(String methodName, ConstraintMatcher constraints, Throwable throwable) { return createCallSignature(methodName, constraints, createThrowStub(throwable)); } - public Callable createVoidCallable(String methodName, ConstraintMatcher constraints) { + public Invokable createVoidCallable(String methodName, ConstraintMatcher constraints) { return createCallSignature(methodName, constraints, createVoidStub()); } - private Callable createCallSignature(String methodName, ConstraintMatcher constraints, Callable callable) { + private Invokable createCallSignature(String methodName, ConstraintMatcher constraints, Invokable callable) { return new CallSignature( methodName, constraints, callable ); } - private Callable createReturnStub(Object result) { + private Invokable createReturnStub(Object result) { return new ReturnStub(result); } - private Callable createThrowStub( Throwable exception ) { + private Invokable createThrowStub( Throwable exception ) { return new ThrowStub(exception); } - private Callable createVoidStub() { + private Invokable createVoidStub() { return new VoidStub(); } Index: CallableFactory.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallableFactory.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- CallableFactory.java 6 Jul 2003 02:31:37 -0000 1.1 +++ CallableFactory.java 20 Aug 2003 21:51:27 -0000 1.2 @@ -1,9 +1,9 @@ package com.mockobjects.dynamic; public interface CallableFactory { - Callable createCallExpectation( Callable callable ); + Invokable createCallExpectation( Invokable callable ); - Callable createReturnCallable( String methodName, ConstraintMatcher constraints, Object result ); - Callable createThrowableCallable( String methodName, ConstraintMatcher constraints, Throwable throwable); - Callable createVoidCallable( String methodName, ConstraintMatcher constraints); + Invokable createReturnCallable( String methodName, ConstraintMatcher constraints, Object result ); + Invokable createThrowableCallable( String methodName, ConstraintMatcher constraints, Throwable throwable); + Invokable createVoidCallable( String methodName, ConstraintMatcher constraints); } Index: VoidStub.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/VoidStub.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- VoidStub.java 6 Jul 2003 23:24:09 -0000 1.5 +++ VoidStub.java 20 Aug 2003 21:51:27 -0000 1.6 @@ -10,7 +10,7 @@ return "returns <void>"; } - public Object call(Invocation invocation) throws Throwable { + public Object invoke(Invocation invocation) throws Throwable { return null; } Index: CallOnceExpectation.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallOnceExpectation.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- CallOnceExpectation.java 9 Aug 2003 13:16:17 -0000 1.6 +++ CallOnceExpectation.java 20 Aug 2003 21:51:27 -0000 1.7 @@ -2,11 +2,11 @@ import junit.framework.*; -public class CallOnceExpectation implements Callable { - private Callable delegateCall; +public class CallOnceExpectation implements Invokable { + private Invokable delegateCall; private boolean wasCalled = false; - public CallOnceExpectation( Callable delegateCall ) { + public CallOnceExpectation( Invokable delegateCall ) { this.delegateCall = delegateCall; } @@ -14,9 +14,9 @@ return delegateCall.getDescription() + " [" + (wasCalled ? "" : "not ") + "called]"; } - public Object call(Invocation invocation) throws Throwable { + public Object invoke(Invocation invocation) throws Throwable { wasCalled = true; - return delegateCall.call( invocation ); + return delegateCall.invoke( invocation ); } public boolean matches(Invocation invocation) { Index: CallSequence.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallSequence.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- CallSequence.java 9 Jul 2003 02:14:00 -0000 1.11 +++ CallSequence.java 20 Aug 2003 21:51:27 -0000 1.12 @@ -6,19 +6,19 @@ int callIndex = 0; - public Object call(Invocation invocation) throws Throwable { + public Object invoke(Invocation invocation) throws Throwable { if (expectedCalls.isEmpty()) throw new AssertionFailedError("no methods defined on mock, received: " + invocation.toString()); if (callIndex == expectedCalls.size()) throw new AssertionFailedError("mock called too many times, received: " + invocation.toString()); - Callable callable = expectedCalls.get(callIndex++); + Invokable callable = expectedCalls.get(callIndex++); if (callable.matches(invocation)) { //TODO shouldn't callIndex be incremented here? - return callable.call(invocation); + return callable.invoke(invocation); } - return lastStubCall(invocation).call(invocation); + return lastStubCall(invocation).invoke(invocation); } public String getDescription() { @@ -30,7 +30,7 @@ expectedCalls.apply( new CallableList.Handler() { - public Callable handle(int index, Callable callable) { + public Invokable handle(int index, Invokable callable) { buf.append(callable.getDescription()); if (index == (callIndex - 1)) buf.append(" <<< Next Expected Call"); Index: CoreMock.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CoreMock.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- CoreMock.java 11 Aug 2003 21:25:06 -0000 1.8 +++ CoreMock.java 20 Aug 2003 21:51:27 -0000 1.9 @@ -28,12 +28,12 @@ try { Invocation invocation = new Invocation(method, args); - if (isCheckingEqualityOnProxy(invocation)) { + if (invocation.isCheckingEqualityOnProxy()) { return new Boolean(args[0] == this.proxy); - } else if (isMockNameGetter(invocation)) { + } else if (invocation.isMockNameGetter()) { return this.getMockName(); } else { - return invocationMatchers.call(invocation); + return invocationMatchers.invoke(invocation); } } catch (AssertionFailedError ex) { throw new AssertionFailedError(name + ": " + ex.getMessage()); @@ -56,25 +56,14 @@ return this.name; } - public void expect(Callable invocationMatcher) { + public void expect(Invokable invocationMatcher) { invocationMatchers.addExpect(invocationMatcher); } - public void stub(Callable invocationMatcher) { + public void stub(Invokable invocationMatcher) { invocationMatchers.addStub(invocationMatcher); } - private boolean isCheckingEqualityOnProxy(Invocation invocation) { - return invocation.getMethodName().equals("equals") - && invocation.args.length == 1 - && invocation.args[0] != null - && Proxy.isProxyClass(invocation.args[0].getClass()); - } - - private boolean isMockNameGetter(Invocation invocation) { - return (invocation.getMethodName().equals("getMockName")) && (invocation.args.length == 0); - } - public void reset() { invocationMatchers.reset(); } @@ -82,39 +71,9 @@ public static String mockNameFromClass(Class c) { return "mock" + className(c); } - + public static String className(Class c) { String name = c.getName(); - int dotIndex = name.lastIndexOf('.'); - - if (dotIndex >= 0) { - return name.substring(dotIndex + 1); - } else { - return name; - } + return name.substring(name.lastIndexOf('.') + 1); } - - public static class ProxyIsEqual implements Callable { - final Object proxy; - - public ProxyIsEqual(Object proxy) { - this.proxy = proxy; - } - - public String getDescription() { - return "Proxy is equal"; - } - - public Object call(Invocation invocation) throws Throwable { - return new Boolean(invocation.args[0] == proxy); - } - - public boolean matches(Invocation invocation) { - return (invocation.getMethodName().equals("equals")) && (invocation.args.length == 1) && - (Proxy.isProxyClass(invocation.args[0].getClass())); - } - - public void verify() { /* no op */ } - } - } Index: ReturnStub.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/ReturnStub.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- ReturnStub.java 6 Jul 2003 23:24:09 -0000 1.6 +++ ReturnStub.java 20 Aug 2003 21:51:27 -0000 1.7 @@ -12,7 +12,7 @@ this.result = result; } - public Object call(Invocation invocation) throws Throwable { + public Object invoke(Invocation invocation) throws Throwable { return result; } Index: CallableList.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallableList.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- CallableList.java 9 Jul 2003 02:14:00 -0000 1.4 +++ CallableList.java 20 Aug 2003 21:51:27 -0000 1.5 @@ -9,15 +9,15 @@ public interface CallableList extends Verifiable { public interface Handler { - Callable handle(int index, Callable callable); + Invokable handle(int index, Invokable callable); } - void add(Callable callable); + void add(Invokable callable); boolean isEmpty(); - Callable get(int index); + Invokable get(int index); int size(); void clear(); - Callable lastMatchingCall(Invocation invocation); - Callable apply(final Handler handler); + Invokable lastMatchingCall(Invocation invocation); + Invokable apply(final Handler handler); } Index: CallableCollection.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallableCollection.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- CallableCollection.java 9 Aug 2003 13:18:30 -0000 1.2 +++ CallableCollection.java 20 Aug 2003 21:51:27 -0000 1.3 @@ -1,8 +1,8 @@ package com.mockobjects.dynamic; -public interface CallableCollection extends Callable { - void addExpect(Callable call); - void addStub(Callable call); +public interface CallableCollection extends Invokable { + void addExpect(Invokable call); + void addStub(Invokable call); /** * Resets all expected calls and expected matches. Index: DynamicMock.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/DynamicMock.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- DynamicMock.java 7 Jul 2003 01:17:57 -0000 1.2 +++ DynamicMock.java 20 Aug 2003 21:51:27 -0000 1.3 @@ -4,10 +4,13 @@ import com.mockobjects.Verifiable; -public interface DynamicMock extends Verifiable, InvocationHandler { - void expect(Callable invocationMatcher); - void stub(Callable invocationMatcher); - Object proxy(); +public interface DynamicMock + extends Verifiable, InvocationHandler +{ + void expect(Invokable invokable); + void stub(Invokable invokable); + + Object proxy(); void reset(); } Index: CallStub.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallStub.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- CallStub.java 6 Jul 2003 23:24:09 -0000 1.5 +++ CallStub.java 20 Aug 2003 21:51:27 -0000 1.6 @@ -4,7 +4,7 @@ package com.mockobjects.dynamic; public abstract class CallStub - implements Callable + implements Invokable { public boolean matches(Invocation invocation) { return true; Index: ThrowStub.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/ThrowStub.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- ThrowStub.java 6 Jul 2003 23:24:09 -0000 1.6 +++ ThrowStub.java 20 Aug 2003 21:51:27 -0000 1.7 @@ -12,7 +12,7 @@ this.throwable = throwable; } - public Object call(Invocation invocation) throws Throwable { + public Object invoke(Invocation invocation) throws Throwable { throw throwable; } Index: CallSignature.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallSignature.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- CallSignature.java 9 Aug 2003 13:18:30 -0000 1.7 +++ CallSignature.java 20 Aug 2003 21:51:27 -0000 1.8 @@ -1,21 +1,21 @@ package com.mockobjects.dynamic; -public class CallSignature implements Callable +public class CallSignature implements Invokable { private String methodName; private ConstraintMatcher constraints; - private Callable delegateCall; + private Invokable delegateCall; - public CallSignature( String methodName, ConstraintMatcher constraints, Callable delegateCall ) { + public CallSignature( String methodName, ConstraintMatcher constraints, Invokable delegateCall ) { this.methodName = methodName; this.constraints = constraints; this.delegateCall = delegateCall; } - public Object call( Invocation invocation ) + public Object invoke( Invocation invocation ) throws Throwable { - return delegateCall.call( invocation ); + return delegateCall.invoke( invocation ); } public void verify() { @@ -23,7 +23,8 @@ } public boolean matches(Invocation invocation) { - return this.methodName.equals(invocation.getMethodName()) && constraints.matches(invocation.args); + return this.methodName.equals(invocation.getMethodName()) && + constraints.matches(invocation.getParameterValues().toArray()); } public String getDescription() { --- Callable.java DELETED --- |
From: Steve F. <sm...@us...> - 2003-08-22 04:56:53
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv29581/src/core/test/mockobjects/dynamic Added Files: InvocationDispatcherTest.java MockInvokable.java InvocationTest.java Log Message: New classes for Invocation-based refactoring --- NEW FILE: InvocationDispatcherTest.java --- /* * Created on 20-Aug-2003 * Copyright mockobjects.com */ package test.mockobjects.dynamic; import java.lang.reflect.Method; import junit.framework.TestCase; import com.mockobjects.dynamic.DynamicMockError; import com.mockobjects.dynamic.Invocation; import com.mockobjects.dynamic.InvocationDispatcher; public class InvocationDispatcherTest extends TestCase { private Invocation invocation; private InvocationDispatcher dispatcher; private MockInvokable invokable = new MockInvokable(); public void setUp() throws NoSuchMethodException { invocation = new Invocation(getDummyMethod(), null); dispatcher = new InvocationDispatcher(); } public void dummyMethod() {}; public void testInvokeFailsWhenEmpty() throws Throwable { try { dispatcher.dispatch(invocation); } catch( DynamicMockError ex ) { assertSame("should be same invocation", invocation, ex.invocation); return; } fail("expected AssertionFailedError"); } public void testInvokesOneMatchingInvokable() throws Throwable { Object result = "invoke result"; invokable.matchesInvocation.setExpected(invocation); invokable.matchesResult = true; invokable.invokeInvocation.setExpected(invocation); invokable.invokeResult = result; dispatcher.add( invokable ); dispatcher.dispatch(invocation); invokable.verify(); } public void testReturnsValueFromInvokable() throws Throwable { Object result = "invoke result"; invokable.matchesResult = true; invokable.invokeResult = result; dispatcher.add( invokable ); assertSame( "should be same result", result, dispatcher.dispatch(invocation) ); } private Method getDummyMethod() throws NoSuchMethodException { return getClass().getDeclaredMethod("dummyMethod", new Class[0]); } } --- NEW FILE: MockInvokable.java --- /* * Created on 20-Aug-2003 * Copyright mockobjects.com */ package test.mockobjects.dynamic; import com.mockobjects.ExpectationValue; import com.mockobjects.MockObject; import com.mockobjects.dynamic.Invocation; import com.mockobjects.dynamic.Invokable; public class MockInvokable extends MockObject implements Invokable { public boolean matchesResult; public ExpectationValue matchesInvocation = new ExpectationValue("matches.invocation"); public Object invokeResult; public ExpectationValue invokeInvocation = new ExpectationValue("invoke.invocation"); public String getDescription() { return null; } public boolean matches(Invocation invocation) { matchesInvocation.setActual(invocation); return matchesResult; } public Object invoke(Invocation invocation) throws Throwable { invokeInvocation.setActual(invocation); return invokeResult; } } --- NEW FILE: InvocationTest.java --- /** Created on Jun 17, 2003 by npryce * Copyright (c) B13media Ltd. */ package test.mockobjects.dynamic; import java.lang.reflect.Method; import java.util.Arrays; import junit.framework.TestCase; import com.mockobjects.dynamic.Invocation; public class InvocationTest extends TestCase { public String exampleMethod( int number, boolean flag ) { return "hello, world"; } final String METHOD_NAME = "exampleMethod"; final Class[] ARG_TYPES = { int.class, boolean.class }; final Class RETURN_TYPE = String.class; final Object[] ARG_VALUES = { new Integer(0), Boolean.TRUE }; public InvocationTest(String name) { super(name); } public void testCanBeConstructedWithExplicitCallDetails() { Invocation call = new Invocation( METHOD_NAME, ARG_TYPES, RETURN_TYPE, ARG_VALUES ); assertEquals( "name", METHOD_NAME, call.getMethodName() ); assertEquals( "parameter types", Arrays.asList(ARG_TYPES), call.getParameterTypes() ); assertEquals( "return type", RETURN_TYPE, call.getReturnType() ); assertEquals( "argument values", Arrays.asList(ARG_VALUES), call.getParameterValues() ); } public void testCanBeConstructedFromAMethodObject() throws Exception { Method method = getClass().getMethod( METHOD_NAME, ARG_TYPES ); Invocation call = new Invocation( method, ARG_VALUES ); assertEquals( "name", method.getName(), call.getMethodName() ); assertEquals( "parameter types", Arrays.asList(method.getParameterTypes()), call.getParameterTypes() ); assertEquals( "return type", method.getReturnType(), call.getReturnType() ); assertEquals( "argument values", Arrays.asList(ARG_VALUES), call.getParameterValues() ); } public void testConstructorInterpretsNullParameterValueArrayAsZeroArguments() { Invocation call = new Invocation( METHOD_NAME, new Class[0], RETURN_TYPE, null ); assertEquals( "expected no parameters values", 0, call.getParameterValues().size() ); } public void testTestsForEqualityOnMethodSignatureAndArguments() { Invocation call1 = new Invocation( METHOD_NAME, ARG_TYPES, RETURN_TYPE, ARG_VALUES ); Invocation call2 = new Invocation( METHOD_NAME, ARG_TYPES, RETURN_TYPE, ARG_VALUES ); Invocation differentName = new Invocation( "other" + METHOD_NAME, ARG_TYPES, RETURN_TYPE, ARG_VALUES ); Invocation differentReturnType = new Invocation( "other" + METHOD_NAME, ARG_TYPES, int.class, ARG_VALUES ); Invocation differentArgTypes = new Invocation( "other" + METHOD_NAME, new Class[]{double.class}, RETURN_TYPE, ARG_VALUES ); Invocation differentArgValues = new Invocation( "other" + METHOD_NAME, ARG_TYPES, RETURN_TYPE, new Object[] { new Integer(1), Boolean.FALSE } ); assertTrue( "should be equal to itself", call1.equals(call1) ); assertTrue( "identical calls should be equal", call1.equals(call2) ); assertFalse( "should not be equal to object that is not an ActiveCall", call1.equals(new Object()) ); assertFalse( "should not be equal to null", call1.equals(null) ); assertFalse( "should not be equal if different name", call1.equals(differentName) ); assertFalse( "should not be equal if different parameter types", call1.equals(differentArgTypes) ); assertFalse( "should not be equal if different return type", call1.equals(differentReturnType) ); assertFalse( "should not be equal if different argumentValues", call1.equals(differentArgValues) ); } public void testFollowsEqualsHashcodeProtocol() { Invocation call1 = new Invocation( METHOD_NAME, ARG_TYPES, RETURN_TYPE, ARG_VALUES ); Invocation call2 = new Invocation( METHOD_NAME, ARG_TYPES, RETURN_TYPE, ARG_VALUES ); assertEquals( "should have equal hash codes", call1.hashCode(), call2.hashCode() ); } } |
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv30075/src/core/test/mockobjects/dynamic Modified Files: CallOnceExpectationTest.java CallSignatureTest.java CallBagTest.java CallableArrayListTest.java MockCallableFactory.java MockCallableList.java StubTest.java CoreMockTest.java MockCallableCollection.java MockCallFactory.java MockConstraintMatcher.java CallSequenceTest.java MockCallable.java Removed Files: CTest.java Log Message: First move towards Invokable-based refactoring Index: CallOnceExpectationTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/CallOnceExpectationTest.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- CallOnceExpectationTest.java 9 Jul 2003 02:13:59 -0000 1.6 +++ CallOnceExpectationTest.java 20 Aug 2003 21:51:27 -0000 1.7 @@ -10,10 +10,12 @@ final String RESULT = "result!"; final String METHOD_NAME = "methodName"; - final Object[] ARGS = { "arg1", "arg2" }; - final Invocation INVOCATION = new Invocation(METHOD_NAME, ARGS) ; + final Object[] ARG_VALUES = { "arg1", "arg2" }; + final Class[] ARG_TYPES = { ARG_VALUES[0].getClass(), ARG_VALUES[1].getClass() }; + final Class RETURN_TYPE = void.class; + final Invocation INVOCATION = new Invocation(METHOD_NAME, ARG_TYPES, RETURN_TYPE, ARG_VALUES) ; - final String DECORATED_DESCRIPTION = DynamicUtil.methodToString( METHOD_NAME, ARGS ); + final String DECORATED_DESCRIPTION = DynamicUtil.methodToString( METHOD_NAME, ARG_VALUES ); Mock ignoredMock = null; MockCallable mockCallable = new MockCallable(DECORATED_DESCRIPTION); @@ -47,14 +49,14 @@ mockCallable.setupCallReturn( RESULT ); mockCallable.setExpectedVerifyCalls(1); - call.call( INVOCATION ); + call.invoke( INVOCATION ); call.verify(); mockCallable.verifyExpectations(); } public void testMatchesDelegated() throws Throwable { - mockCallable.setExpectedMatches( METHOD_NAME, ARGS ); + mockCallable.setExpectedMatches( METHOD_NAME, ARG_VALUES ); mockCallable.matches = true; assertTrue( "returns matches to be true", call.matches( INVOCATION ) ); mockCallable.verifyExpectations(); @@ -64,7 +66,7 @@ mockCallable.callInvocation.setExpected(INVOCATION); mockCallable.setupCallReturn(RESULT); - call.call( INVOCATION ); + call.invoke( INVOCATION ); mockCallable.verifyExpectations(); } @@ -74,7 +76,7 @@ mockCallable.setupCallReturn(RESULT); assertTrue( "First time should match", call.matches( INVOCATION )); - call.call( INVOCATION ); + call.invoke( INVOCATION ); assertFalse( "Second time should not match", call.matches( INVOCATION )); } @@ -82,7 +84,7 @@ mockCallable.setupCallReturn(RESULT); assertSame( "should return decorated's result", - RESULT, call.call( INVOCATION ) ); + RESULT, call.invoke( INVOCATION ) ); mockCallable.verifyExpectations(); } @@ -93,7 +95,7 @@ mockCallable.setupCallThrow(exception); try { - call.call( INVOCATION ); + call.invoke( INVOCATION ); fail("expected decorated's throwable to be thrown"); } catch( DummyThrowable ex ) { Index: CallSignatureTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/CallSignatureTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- CallSignatureTest.java 9 Jul 2003 02:14:00 -0000 1.3 +++ CallSignatureTest.java 20 Aug 2003 21:51:27 -0000 1.4 @@ -11,7 +11,9 @@ public class CallSignatureTest extends TestCase { final String METHOD_NAME = "methodName"; final Object[] IGNORED_ARGS = new Object[0]; - final Invocation INVOCATION = new Invocation(METHOD_NAME, IGNORED_ARGS); + final Class[] IGNORED_ARG_TYPES = new Class[0]; + final Class IGNORED_RETURN_TYPE = void.class; + final Invocation INVOCATION = new Invocation(METHOD_NAME, IGNORED_ARG_TYPES, IGNORED_RETURN_TYPE, IGNORED_ARGS); Mock mock = new Mock(DummyInterface.class, "mock"); MockCallable mockCallable = new MockCallable("mock callable"); @@ -29,7 +31,7 @@ mockCallable.callInvocation.setExpected(INVOCATION); mockCallable.setupCallReturn(result); - callSignature.call(INVOCATION); + callSignature.invoke(INVOCATION); mockCallable.verifyExpectations(); } @@ -46,7 +48,7 @@ mockCallable.setExpectedVerifyCalls(1); mockCallable.setupCallReturn("result"); - callSignature.call(INVOCATION); + callSignature.invoke(INVOCATION); callSignature.verify(); mockCallable.verifyExpectations(); @@ -55,8 +57,8 @@ public void testMultipleCallsSucceed() throws Throwable { mockCallable.setupCallReturn("result"); - callSignature.call(INVOCATION); - callSignature.call(INVOCATION); + callSignature.invoke(INVOCATION); + callSignature.invoke(INVOCATION); mockCallable.verifyExpectations(); } @@ -66,7 +68,8 @@ } public void testCallDoesNotMatchWhenWrongName() throws Throwable { - assertFalse("call does not match", callSignature.matches(new Invocation("anotherName", IGNORED_ARGS))); + assertFalse("call does not match", callSignature.matches( + new Invocation("anotherName", IGNORED_ARG_TYPES, IGNORED_RETURN_TYPE, IGNORED_ARGS))); mockCallable.verifyExpectations(); } @@ -76,22 +79,26 @@ mockConstraintMatcher.setupMatches(true); - callSignature.call(INVOCATION); + callSignature.invoke(INVOCATION); assertTrue("matches after first call", callSignature.matches( INVOCATION )); - callSignature.call(INVOCATION); + callSignature.invoke(INVOCATION); assertTrue("matches after further calls", callSignature.matches( INVOCATION )); mockCallable.verifyExpectations(); } - public void testMatchesDelegatesToContraintMatcher() - throws Throwable { + public void testMatchesDelegatesToConstraintMatcher() + throws Throwable + { final String[] args = new String[] { "a1", "a2" }; - + final Class[] argTypes = new Class[] { String.class, String.class }; + final Class returnType = void.class; + mockConstraintMatcher.addExpectedMatches(args); mockConstraintMatcher.setupMatches(true); - assertTrue("matches delegated to constraint matcher", callSignature.matches(new Invocation(METHOD_NAME, args))); + assertTrue("matches delegated to constraint matcher", callSignature.matches( + new Invocation(METHOD_NAME, argTypes, returnType, args))); mockConstraintMatcher.verify(); } Index: CallBagTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/CallBagTest.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- CallBagTest.java 9 Aug 2003 13:18:45 -0000 1.11 +++ CallBagTest.java 20 Aug 2003 21:51:27 -0000 1.12 @@ -18,7 +18,7 @@ private MockCallable mockCallable = new MockCallable("mock callable"); private MockCallableList mockExpected = new MockCallableList(); private MockCallableList mockStubs = new MockCallableList(); - private Invocation dummyInvocation = new Invocation("missingMethod", new Object[0]); + private Invocation dummyInvocation = new Invocation("missingMethod", new Class[0], void.class, new Object[0]); private CallBag callBag = new CallBag(mockExpected, mockStubs); @@ -58,7 +58,7 @@ mockStubs.lastMatchingCallInvocation.setExpected(dummyInvocation); try { - callBag.call(dummyInvocation); + callBag.invoke(dummyInvocation); } catch (AssertionFailedError ex) { AssertMo.assertIncludes("reports empty list", "no methods", ex.getMessage()); verifyAll(); @@ -76,7 +76,7 @@ mockStubs.lastMatchingCallInvocation.setExpected(dummyInvocation); try { - callBag.call(dummyInvocation); + callBag.invoke(dummyInvocation); } catch (AssertionFailedError ex) { AssertMo.assertIncludes("reports missing method", mockCallable.getDescription(), ex.getMessage()); verifyAll(); @@ -94,7 +94,7 @@ mockStubs.lastMatchingCallInvocation.setExpectNothing(); mockCallable.callInvocation.setExpected(dummyInvocation); - assertEquals("Call should return", "call result", callBag.call(dummyInvocation)); + assertEquals("Call should return", "call result", callBag.invoke(dummyInvocation)); verifyAll(); } @@ -108,7 +108,7 @@ mockStubs.lastMatchingCallInvocation.setExpected(dummyInvocation); mockCallable.callInvocation.setExpected(dummyInvocation); - assertEquals("Call should return", "call result", callBag.call(dummyInvocation)); + assertEquals("Call should return", "call result", callBag.invoke(dummyInvocation)); verifyAll(); } @@ -119,7 +119,7 @@ mockCallable.setupCallThrow(throwable); try { - callBag.call(dummyInvocation); + callBag.invoke(dummyInvocation); } catch (Throwable ex) { Assert.assertEquals("Should have caught throwable", throwable, ex); return; Index: CallableArrayListTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/CallableArrayListTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- CallableArrayListTest.java 9 Jul 2003 02:13:59 -0000 1.1 +++ CallableArrayListTest.java 20 Aug 2003 21:51:27 -0000 1.2 @@ -3,7 +3,7 @@ */ package test.mockobjects.dynamic; -import com.mockobjects.dynamic.Callable; +import com.mockobjects.dynamic.Invokable; import com.mockobjects.dynamic.CallableArrayList; import com.mockobjects.dynamic.CallableList; import com.mockobjects.dynamic.Invocation; @@ -11,7 +11,7 @@ import junit.framework.TestCase; public class CallableArrayListTest extends TestCase { - private Invocation dummyInvocation = new Invocation("dummy", new Object[0]); + private Invocation dummyInvocation = new Invocation("dummy", new Class[0], void.class, new Object[0]); public CallableArrayListTest(String name) { super(name); @@ -66,7 +66,7 @@ allElements.addExpected(otherCallable); list.apply(new CallableList.Handler() { - public Callable handle(int index, Callable callable) { + public Invokable handle(int index, Invokable callable) { allElements.addActual(callable); return null; } Index: MockCallableFactory.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockCallableFactory.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- MockCallableFactory.java 7 Jul 2003 02:24:26 -0000 1.1 +++ MockCallableFactory.java 20 Aug 2003 21:51:27 -0000 1.2 @@ -2,7 +2,7 @@ import com.mockobjects.*; import com.mockobjects.dynamic.CallableFactory; -import com.mockobjects.dynamic.Callable; +import com.mockobjects.dynamic.Invokable; import com.mockobjects.dynamic.ConstraintMatcher; public class MockCallableFactory implements CallableFactory{ @@ -28,24 +28,24 @@ myCreateCallExpectationCalls.setExpected(calls); } - public void addExpectedCreateCallExpectation(Callable arg0){ + public void addExpectedCreateCallExpectation(Invokable arg0){ myCreateCallExpectationParameter0Values.addExpected(arg0); } - public Callable createCallExpectation(Callable arg0){ + public Invokable createCallExpectation(Invokable arg0){ myCreateCallExpectationCalls.inc(); myCreateCallExpectationParameter0Values.addActual(arg0); Object nextReturnValue = myActualCreateCallExpectationReturnValues.getNext(); if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException) throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException(); - return (Callable) nextReturnValue; + return (Invokable) nextReturnValue; } public void setupExceptionCreateCallExpectation(Throwable arg){ myActualCreateCallExpectationReturnValues.add(new ExceptionalReturnValue(arg)); } - public void setupCreateCallExpectation(Callable arg){ + public void setupCreateCallExpectation(Invokable arg){ myActualCreateCallExpectationReturnValues.add(arg); } @@ -59,7 +59,7 @@ myCreateReturnCallableParameter2Values.addExpected(arg2); } - public Callable createReturnCallable(String arg0, ConstraintMatcher arg1, Object arg2){ + public Invokable createReturnCallable(String arg0, ConstraintMatcher arg1, Object arg2){ myCreateReturnCallableCalls.inc(); myCreateReturnCallableParameter0Values.addActual(arg0); myCreateReturnCallableParameter1Values.addActual(arg1); @@ -67,14 +67,14 @@ Object nextReturnValue = myActualCreateReturnCallableReturnValues.getNext(); if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException) throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException(); - return (Callable) nextReturnValue; + return (Invokable) nextReturnValue; } public void setupExceptionCreateReturnCallable(Throwable arg){ myActualCreateReturnCallableReturnValues.add(new ExceptionalReturnValue(arg)); } - public void setupCreateReturnCallable(Callable arg){ + public void setupCreateReturnCallable(Invokable arg){ myActualCreateReturnCallableReturnValues.add(arg); } @@ -88,7 +88,7 @@ myCreateThrowableCallableParameter2Values.addExpected(arg2); } - public Callable createThrowableCallable(String arg0, ConstraintMatcher arg1, Throwable arg2){ + public Invokable createThrowableCallable(String arg0, ConstraintMatcher arg1, Throwable arg2){ myCreateThrowableCallableCalls.inc(); myCreateThrowableCallableParameter0Values.addActual(arg0); myCreateThrowableCallableParameter1Values.addActual(arg1); @@ -96,14 +96,14 @@ Object nextReturnValue = myActualCreateThrowableCallableReturnValues.getNext(); if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException) throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException(); - return (Callable) nextReturnValue; + return (Invokable) nextReturnValue; } public void setupExceptionCreateThrowableCallable(Throwable arg){ myActualCreateThrowableCallableReturnValues.add(new ExceptionalReturnValue(arg)); } - public void setupCreateThrowableCallable(Callable arg){ + public void setupCreateThrowableCallable(Invokable arg){ myActualCreateThrowableCallableReturnValues.add(arg); } @@ -116,21 +116,21 @@ myCreateVoidCallableParameter1Values.addExpected(arg1); } - public Callable createVoidCallable(String arg0, ConstraintMatcher arg1){ + public Invokable createVoidCallable(String arg0, ConstraintMatcher arg1){ myCreateVoidCallableCalls.inc(); myCreateVoidCallableParameter0Values.addActual(arg0); myCreateVoidCallableParameter1Values.addActual(arg1); Object nextReturnValue = myActualCreateVoidCallableReturnValues.getNext(); if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException) throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException(); - return (Callable) nextReturnValue; + return (Invokable) nextReturnValue; } public void setupExceptionCreateVoidCallable(Throwable arg){ myActualCreateVoidCallableReturnValues.add(new ExceptionalReturnValue(arg)); } - public void setupCreateVoidCallable(Callable arg){ + public void setupCreateVoidCallable(Invokable arg){ myActualCreateVoidCallableReturnValues.add(arg); } Index: MockCallableList.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockCallableList.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- MockCallableList.java 9 Jul 2003 02:14:00 -0000 1.1 +++ MockCallableList.java 20 Aug 2003 21:51:27 -0000 1.2 @@ -3,7 +3,7 @@ import com.mockobjects.ExpectationCounter; import com.mockobjects.ExpectationValue; import com.mockobjects.ExpectationList; -import com.mockobjects.dynamic.Callable; +import com.mockobjects.dynamic.Invokable; import com.mockobjects.dynamic.CallableList; import com.mockobjects.dynamic.Invocation; import com.mockobjects.util.Verifier; @@ -16,12 +16,12 @@ public ExpectationList addedCallables = new ExpectationList("added callables"); public ExpectationCounter clearCalls = new ExpectationCounter("clear calls"); public ExpectationCounter verifyCalls = new ExpectationCounter("verify calls"); - public Callable lastMatchingCall; - public Callable applied; - public Callable apply; + public Invokable lastMatchingCall; + public Invokable applied; + public Invokable apply; public boolean isEmpty; - public void add(Callable callable) { + public void add(Invokable callable) { addedCallables.addActual(callable); } @@ -29,7 +29,7 @@ return isEmpty; } - public Callable get(int index) { + public Invokable get(int index) { return null; } @@ -41,16 +41,16 @@ clearCalls.inc(); } - public Callable firstMatchingCall(Invocation invocation) { + public Invokable firstMatchingCall(Invocation invocation) { return null; } - public Callable lastMatchingCall(Invocation invocation) { + public Invokable lastMatchingCall(Invocation invocation) { lastMatchingCallInvocation.setActual(invocation); return lastMatchingCall; } - public Callable apply(CallableList.Handler handler) { + public Invokable apply(CallableList.Handler handler) { handler.handle(0, applied); return null; } Index: StubTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/StubTest.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- StubTest.java 6 Jul 2003 23:24:09 -0000 1.5 +++ StubTest.java 20 Aug 2003 21:51:27 -0000 1.6 @@ -15,19 +15,19 @@ super(name); } - Invocation invocation = new Invocation("ignoredName", new Object[0]); + Invocation invocation = new Invocation("ignoredName", new Class[0], void.class, new Object[0]); public void testReturnStub() throws Throwable { final String RESULT = "result"; - assertSame( "Should be the same result object", RESULT, new ReturnStub(RESULT).call( invocation) ); + assertSame( "Should be the same result object", RESULT, new ReturnStub(RESULT).invoke( invocation) ); } public void testThrowStub() { final Throwable throwable = new DummyThrowable(); try { - new ThrowStub(throwable).call( invocation ); + new ThrowStub(throwable).invoke( invocation ); } catch( Throwable t ) { assertSame( "Should be the same throwable", throwable, t ); Index: CoreMockTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/CoreMockTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- CoreMockTest.java 11 Aug 2003 21:25:07 -0000 1.3 +++ CoreMockTest.java 20 Aug 2003 21:51:27 -0000 1.4 @@ -138,11 +138,11 @@ Verifier.verifyObject(this); } - public void testMockNameFromClass() throws Exception { + public void testGeneratesMockNameFromInterfaceNameIfNoNameSpecified() throws Exception { assertEquals("mockString", CoreMock.mockNameFromClass(String.class)); } - public void testMockToStringContainsName() { + public void testResultOfToStringContainsName() { AssertMo.assertIncludes("result of toString() should include name", MOCK_NAME, coreMock.toString()); } Index: MockCallableCollection.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockCallableCollection.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- MockCallableCollection.java 9 Aug 2003 13:19:25 -0000 1.6 +++ MockCallableCollection.java 20 Aug 2003 21:51:27 -0000 1.7 @@ -2,7 +2,7 @@ import com.mockobjects.*; import com.mockobjects.dynamic.Invocation; -import com.mockobjects.dynamic.Callable; +import com.mockobjects.dynamic.Invokable; import com.mockobjects.dynamic.CallableCollection; import com.mockobjects.util.Verifier; import junit.framework.AssertionFailedError; @@ -31,19 +31,19 @@ resetCalls.inc(); } - public void addStub(Callable callable) { + public void addStub(Invokable callable) { matchedCallables.addActual(callable); } - public void addExpectedMatch(Callable callable) { + public void addExpectedMatch(Invokable callable) { matchedCallables.addExpected(callable); } - public void addExpect(Callable callable) { + public void addExpect(Invokable callable) { expectedCallables.addActual(callable); } - public void addExpectedExpect(Callable callable) { + public void addExpectedExpect(Invokable callable) { expectedCallables.addExpected(callable); } @@ -59,7 +59,7 @@ public boolean matches(Invocation invocation) { myMatchesCalls.inc(); myMatchesParameter0Values.addActual(invocation.getMethodName()); - myMatchesParameter1Values.addActual(invocation.args); + myMatchesParameter1Values.addActual(invocation.getParameterValues().toArray()); Object nextReturnValue = myActualMatchesReturnValues.getNext(); @@ -95,10 +95,10 @@ myCallArguments.addExpectedMany(args); } - public Object call(Invocation invocation) throws Throwable { + public Object invoke(Invocation invocation) throws Throwable { myCallCalls.inc(); myCallMethodNames.addActual(invocation.getMethodName()); - myCallArguments.addActualMany(invocation.args); + myCallArguments.addActualMany(invocation.getParameterValues().toArray()); if (callException != null) throw callException; return callResult; Index: MockCallFactory.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockCallFactory.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- MockCallFactory.java 6 Jul 2003 02:31:37 -0000 1.5 +++ MockCallFactory.java 20 Aug 2003 21:51:27 -0000 1.6 @@ -2,7 +2,7 @@ import com.mockobjects.*; import com.mockobjects.dynamic.CallableFactory; -import com.mockobjects.dynamic.Callable; +import com.mockobjects.dynamic.Invokable; import com.mockobjects.dynamic.ConstraintMatcher; import com.mockobjects.util.Verifier; @@ -22,31 +22,31 @@ private ExpectationList myCreateCallSignatureParameter1Values = new ExpectationList("MockCallFactory.createCallMatch(String, ConstraintMatcher, Callable) com.mockobjects.dynamic.ConstraintMatcher"); private ExpectationList myCreateCallSignatureParameter2Values = new ExpectationList("MockCallFactory.createCallMatch(String, ConstraintMatcher, Callable) com.mockobjects.dynamic.Callable"); - private Callable createReturnStub(Object arg0){ + private Invokable createReturnStub(Object arg0){ createReturnStub.setActual(arg0); Object nextReturnValue = myActualCreateReturnStubReturnValues.getNext(); if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException) throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException(); - return (Callable) nextReturnValue; + return (Invokable) nextReturnValue; } - public void setupCreateReturnStub(Callable arg){ + public void setupCreateReturnStub(Invokable arg){ myActualCreateReturnStubReturnValues.add(arg); } - private Callable createThrowStub(Throwable arg0){ + private Invokable createThrowStub(Throwable arg0){ createThrowStub.setActual(arg0); Object nextReturnValue = myActualCreateThrowStubReturnValues.getNext(); if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException) throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException(); - return (Callable) nextReturnValue; + return (Invokable) nextReturnValue; } public void setupExceptionCreateThrowStub(Throwable arg){ myActualCreateThrowStubReturnValues.add(new ExceptionalReturnValue(arg)); } - public void setupCreateThrowStub(Callable arg){ + public void setupCreateThrowStub(Invokable arg){ myActualCreateThrowStubReturnValues.add(arg); } @@ -54,19 +54,19 @@ myCreateVoidStubCalls.setExpected(calls); } - private Callable createVoidStub(){ + private Invokable createVoidStub(){ myCreateVoidStubCalls.inc(); Object nextReturnValue = myActualCreateVoidStubReturnValues.getNext(); if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException) throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException(); - return (Callable) nextReturnValue; + return (Invokable) nextReturnValue; } public void setupExceptionCreateVoidStub(Throwable arg){ myActualCreateVoidStubReturnValues.add(new ExceptionalReturnValue(arg)); } - public void setupCreateVoidStub(Callable arg){ + public void setupCreateVoidStub(Invokable arg){ myActualCreateVoidStubReturnValues.add(arg); } @@ -74,24 +74,24 @@ myCreateCallExpectationCalls.setExpected(calls); } - public void addExpectedCreateCallExpectation(Callable arg0){ + public void addExpectedCreateCallExpectation(Invokable arg0){ myCreateCallExpectationParameter0Values.addExpected(arg0); } - public Callable createCallExpectation(Callable arg0){ + public Invokable createCallExpectation(Invokable arg0){ myCreateCallExpectationCalls.inc(); myCreateCallExpectationParameter0Values.addActual(arg0); Object nextReturnValue = myActualCreateCallExpectationReturnValues.getNext(); if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException) throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException(); - return (Callable) nextReturnValue; + return (Invokable) nextReturnValue; } public void setupExceptionCreateCallExpectation(Throwable arg){ myActualCreateCallExpectationReturnValues.add(new ExceptionalReturnValue(arg)); } - public void setupCreateCallExpectation(Callable arg){ + public void setupCreateCallExpectation(Invokable arg){ myActualCreateCallExpectationReturnValues.add(arg); } @@ -99,13 +99,13 @@ myCreateCallSignatureCalls.setExpected(calls); } - public void addExpectedCreateCallSignature(String arg0, ConstraintMatcher arg1, Callable arg2){ + public void addExpectedCreateCallSignature(String arg0, ConstraintMatcher arg1, Invokable arg2){ myCreateCallSignatureParameter0Values.addExpected(arg0); myCreateCallSignatureParameter1Values.addExpectedMany(arg1.getConstraints()); myCreateCallSignatureParameter2Values.addExpected(arg2); } - private Callable createCallSignature(String arg0, ConstraintMatcher arg1, Callable arg2){ + private Invokable createCallSignature(String arg0, ConstraintMatcher arg1, Invokable arg2){ myCreateCallSignatureCalls.inc(); myCreateCallSignatureParameter0Values.addActual(arg0); myCreateCallSignatureParameter1Values.addActualMany(arg1.getConstraints()); @@ -113,27 +113,27 @@ Object nextReturnValue = myActualCreateCallSignatureReturnValues.getNext(); if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException) throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException(); - return (Callable) nextReturnValue; + return (Invokable) nextReturnValue; } public void setupExceptionCreateCallSignature(Throwable arg){ myActualCreateCallSignatureReturnValues.add(new ExceptionalReturnValue(arg)); } - public void setupCreateCallSignature(Callable arg){ + public void setupCreateCallSignature(Invokable arg){ myActualCreateCallSignatureReturnValues.add(arg); } - public Callable createReturnCallable(String methodName, ConstraintMatcher constraints, Object result) { + public Invokable createReturnCallable(String methodName, ConstraintMatcher constraints, Object result) { return createCallSignature(methodName, constraints, createReturnStub(result)); } - public Callable createThrowableCallable(String methodName, ConstraintMatcher constraints, Throwable throwable) { + public Invokable createThrowableCallable(String methodName, ConstraintMatcher constraints, Throwable throwable) { return createCallSignature(methodName, constraints, createThrowStub(throwable)); } - public Callable createVoidCallable(String methodName, ConstraintMatcher constraints) { + public Invokable createVoidCallable(String methodName, ConstraintMatcher constraints) { return createCallSignature(methodName, constraints, createVoidStub()); } Index: MockConstraintMatcher.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockConstraintMatcher.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- MockConstraintMatcher.java 18 May 2003 20:59:39 -0000 1.2 +++ MockConstraintMatcher.java 20 Aug 2003 21:51:27 -0000 1.3 @@ -15,12 +15,12 @@ } public void addExpectedMatches(Object[] arg0){ - myMatchesParameter0Values.addExpected(arg0); + myMatchesParameter0Values.addExpectedMany(arg0); } public boolean matches(Object[] arg0){ myMatchesCalls.inc(); - myMatchesParameter0Values.addActual(arg0); + myMatchesParameter0Values.addActualMany(arg0); Object nextReturnValue = myActualMatchesReturnValues.getNext(); if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException) throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException(); Index: CallSequenceTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/CallSequenceTest.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- CallSequenceTest.java 9 Aug 2003 13:19:25 -0000 1.14 +++ CallSequenceTest.java 20 Aug 2003 21:51:27 -0000 1.15 @@ -7,7 +7,7 @@ import com.mockobjects.dynamic.C; import com.mockobjects.dynamic.CallSignature; import com.mockobjects.dynamic.CallSequence; -import com.mockobjects.dynamic.Callable; +import com.mockobjects.dynamic.Invokable; import com.mockobjects.dynamic.CallOnceExpectation; import com.mockobjects.dynamic.ReturnStub; @@ -24,11 +24,13 @@ 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 Invocation METHOD_A_INVOCATION = new Invocation(METHOD_A_NAME, METHOD_A_ARGS); + final Class[] METHOD_A_ARG_TYPES = new Class[] { String.class, String.class }; + final Invocation METHOD_A_INVOCATION = new Invocation(METHOD_A_NAME, METHOD_A_ARG_TYPES, void.class, METHOD_A_ARGS); final ConstraintMatcher METHOD_A_CONSTRAINTS = C.args(C.eq("a1"), C.eq("a2")); final String[] METHOD_B_ARGS = new String[] { "b1", "b2" }; - final Invocation METHOD_B_INVOCATION = new Invocation(METHOD_B_NAME, METHOD_B_ARGS); + final Class[] METHOD_B_ARG_TYPES = new Class[] { String.class, String.class }; + final Invocation METHOD_B_INVOCATION = new Invocation(METHOD_B_NAME, METHOD_B_ARG_TYPES, void.class, METHOD_B_ARGS); private CallSequence callSequence = new CallSequence(); private MockCallable methodA = new MockCallable("method a"); @@ -48,7 +50,7 @@ callSequence.addExpect(mockCallable); try { - callSequence.call(new Invocation("hello", new String[0])); + callSequence.invoke(new Invocation("hello", new Class[0], void.class, new String[0])); } catch (Throwable ex) { assertSame("exception is caught by mock", throwable, ex); } @@ -56,7 +58,7 @@ public void testCallFailsOnEmptyList() throws Throwable { try { - callSequence.call(new Invocation("missingMethod", new Object[0])); + callSequence.invoke(new Invocation("missingMethod", new Class[0], void.class, new Object[0])); } catch (AssertionFailedError ex) { AssertMo.assertIncludes("reports empty set in error message", "no methods", ex.getMessage()); @@ -70,10 +72,10 @@ mockCallable.matches = true; mockCallable.setupCallReturn(METHOD_A_RESULT); callSequence.addExpect(mockCallable); - callSequence.call(new Invocation("willdefinitelyMatch", new Object[0])); + callSequence.invoke(new Invocation("willdefinitelyMatch", new Class[0], void.class, new Object[0])); try { - callSequence.call(new Invocation("oneMethodTooMany", new Object[0])); + callSequence.invoke(new Invocation("oneMethodTooMany", new Class[0], void.class, new Object[0])); } catch (AssertionFailedError ex) { AssertMo.assertIncludes("reports one method call too many", "too many", ex.getMessage()); @@ -94,7 +96,7 @@ callSequence.addExpect(methodA); callSequence.addExpect(methodB); - assertSame("expected result from method A", METHOD_A_RESULT, callSequence.call(METHOD_A_INVOCATION)); + assertSame("expected result from method A", METHOD_A_RESULT, callSequence.invoke(METHOD_A_INVOCATION)); methodA.verifyExpectations(); methodB.verifyExpectations(); @@ -108,7 +110,7 @@ callSequence.addExpect(methodB); try { - assertSame("expected result from method B", METHOD_B_RESULT, callSequence.call(METHOD_B_INVOCATION)); + assertSame("expected result from method B", METHOD_B_RESULT, callSequence.invoke(METHOD_B_INVOCATION)); } catch (AssertionFailedError ex) { String message = ex.getMessage(); AssertMo.assertIncludes("Should have expected error message", "Unexpected call: methodB", message); @@ -134,7 +136,7 @@ callSequence.addExpect(mockCallable); - assertSame("result is returned by mock", result, callSequence.call(new Invocation("method", new Object[0]))); + assertSame("result is returned by mock", result, callSequence.invoke(new Invocation("method", new Class[0], void.class, new Object[0]))); } public void testEmptySetVerifies() throws Exception { @@ -144,7 +146,9 @@ public void testFailureIfNoElementMatches() throws Throwable { final String methodCName = "methodC"; final String[] methodCArgs = { "c1", "c2" }; - final Invocation methodCInvocation = new Invocation(methodCName, methodCArgs); + final Class[] methodCArgTypes = { String.class, String.class }; + final Class methodCReturnType = void.class; + final Invocation methodCInvocation = new Invocation(methodCName, methodCArgTypes, methodCReturnType, methodCArgs); methodA.setExpectedMatches(methodCName, methodCArgs); methodA.matches = false; @@ -157,7 +161,7 @@ callSequence.addExpect(methodB); try { - callSequence.call(methodCInvocation); + callSequence.invoke(methodCInvocation); } 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()); @@ -204,13 +208,13 @@ public void testExpectOverridesMatch() throws Throwable { - Callable methodASignature = new CallSignature(METHOD_A_NAME,METHOD_A_CONSTRAINTS, new ReturnStub("result1")); - Callable anotherMethodASignature = new CallSignature(METHOD_A_NAME,METHOD_A_CONSTRAINTS, new ReturnStub("result2")); + Invokable methodASignature = new CallSignature(METHOD_A_NAME,METHOD_A_CONSTRAINTS, new ReturnStub("result1")); + Invokable anotherMethodASignature = new CallSignature(METHOD_A_NAME,METHOD_A_CONSTRAINTS, new ReturnStub("result2")); callSequence.addStub(methodASignature); callSequence.addExpect(new CallOnceExpectation(anotherMethodASignature)); assertSame("expected result from method B, as expect has precendence over match", "result2", - callSequence.call(METHOD_A_INVOCATION)); + callSequence.invoke(METHOD_A_INVOCATION)); } } Index: MockCallable.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockCallable.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- MockCallable.java 9 Jul 2003 02:14:00 -0000 1.7 +++ MockCallable.java 20 Aug 2003 21:51:27 -0000 1.8 @@ -7,10 +7,10 @@ import com.mockobjects.ExpectationValue; import com.mockobjects.ReturnValue; import com.mockobjects.dynamic.Invocation; -import com.mockobjects.dynamic.Callable; +import com.mockobjects.dynamic.Invokable; import com.mockobjects.util.Verifier; -public class MockCallable implements Callable { +public class MockCallable implements Invokable { final public String name; @@ -39,7 +39,7 @@ callThrow = thrown; } - public Object call(Invocation anInvocation) throws Throwable { + public Object invoke(Invocation anInvocation) throws Throwable { callInvocation.setActual(anInvocation); if( callThrow != null ) { @@ -60,7 +60,7 @@ public boolean matches(Invocation invocation) { matchesMethodName.setActual(invocation.getMethodName()); - matchesArgs.addActualMany(invocation.args); + matchesArgs.addActualMany(invocation.getParameterValues().toArray()); matchesCount.inc(); return matches; } --- CTest.java DELETED --- |