From: Steve F. <sm...@us...> - 2003-10-01 16:04:25
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv12892/src/core/test/mockobjects/dynamic Modified Files: CoreMockTest.java Log Message: Index: CoreMockTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/CoreMockTest.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- CoreMockTest.java 23 Sep 2003 23:04:33 -0000 1.6 +++ CoreMockTest.java 1 Oct 2003 16:04:19 -0000 1.7 @@ -4,13 +4,18 @@ package test.mockobjects.dynamic; import test.mockobjects.dynamic.support.*; + +import test.mockobjects.dynamic.support.*; 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 { @@ -18,15 +23,15 @@ private DummyInterface proxy; private CoreMock coreMock; - private MockInvocationDispatcher mockDispatcher = new MockInvocationDispatcher(); - private MockInvokable mockInvokable = new MockInvokable(); + private MockCallableCollection mockCallables = new MockCallableCollection(); + private MockCallable mockCallable = new MockCallable("coreMock mockCallable"); public CoreMockTest(String name) { super(name); } public void setUp() { - coreMock = new CoreMock(DummyInterface.class, MOCK_NAME, mockDispatcher); + coreMock = new CoreMock(DummyInterface.class, MOCK_NAME, mockCallables); try { proxy = (DummyInterface)coreMock.proxy(); @@ -40,7 +45,7 @@ final String originalMessage = "original message"; Object arg = new AssertionFailedError(originalMessage); - mockDispatcher.dispatchResult = arg; + mockCallables.callResult = arg; try { proxy.noArgVoidMethod(); @@ -53,15 +58,36 @@ public void testProxyReturnsConfiguredResult() throws Throwable { final String RESULT = "configured result"; - mockDispatcher.dispatchResult = RESULT; + mockCallables.callResult = 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(); - mockDispatcher.dispatchThrowable = throwable; + mockCallables.callException = throwable; try { proxy.noArgVoidMethod(); @@ -73,50 +99,49 @@ } public void testMockVerifies() throws Exception { - mockDispatcher.verifyCalls.setExpected(1); + mockCallables.setExpectedVerifyCalls(1); coreMock.verify(); // Can't use Verifier as we are verifying "verify" - mockDispatcher.verifyExpectations(); + mockCallables.verifyExpectations(); } public void testProxyEquality() throws Exception { - mockDispatcher.dispatchResult = new Boolean(false); + mockCallables.callResult = new Boolean(false); - mockDispatcher.dispatchInvocation.setExpectNothing(); + mockCallables.setExpectedCallCalls(0); assertTrue("Proxy equality is implemented directly", proxy.equals(proxy)); - mockDispatcher.verifyExpectations(); + + Verifier.verifyObject(this); } public void testProxyInequality() throws Exception { - mockDispatcher.dispatchResult = new Boolean(false); + mockCallables.callResult = new Boolean(false); - mockDispatcher.dispatchInvocation.setExpected( - new Invocation("equals", new Class[] { Object.class }, boolean.class, - new Object[] { "not a proxy" })); + mockCallables.addExpectedCall("equals", new Object[] {"not a proxy"}); assertFalse("Should handle proxy inequality by calling through", proxy.equals("not a proxy")); - mockDispatcher.verifyExpectations(); + + Verifier.verifyObject(this); } public void testProxyEqualityWithNull() throws Exception { - mockDispatcher.dispatchResult = new Boolean(true); - mockDispatcher.dispatchInvocation.setExpected( - new Invocation("equals", new Class[] { Object.class }, boolean.class, - new Object[] { null })); + mockCallables.callResult = new Boolean(true); + mockCallables.addExpectedCall("equals", new Object[] {null}); assertTrue("Proxy should handle null equality", proxy.equals(null)); - mockDispatcher.verifyExpectations(); + + Verifier.verifyObject(this); } public void testCallingGetMockNameOnProxyReturnsNameOfUnderlyingMock() { - mockDispatcher.dispatchInvocation.setExpectNothing(); + mockCallables.setExpectedCallCalls(0); assertEquals("proxy.getMockName() returns name of underlying mock", MOCK_NAME, proxy.getMockName()); - mockDispatcher.verifyExpectations(); + Verifier.verifyObject(this); } public void testGeneratesMockNameFromInterfaceNameIfNoNameSpecified() throws Exception { @@ -132,33 +157,40 @@ coreMock.verify(); // should not fail on a proxyToString call } - public void testAddAnInvokable() { - mockDispatcher.addInvokable.setExpected(mockInvokable); + public void testAddAnExpectation() { + mockCallables.addExpectedExpect(mockCallable); - coreMock.expect(mockInvokable); + coreMock.expect(mockCallable); - mockDispatcher.verifyExpectations(); + mockCallables.verifyExpectations(); } + public void testAddAStub() { + mockCallables.addExpectedMatch(mockCallable); + + coreMock.stub(mockCallable); + + mockCallables.verifyExpectations(); + } public void testReset() { - mockDispatcher.clearCalls.setExpected(1); + mockCallables.resetCalls.setExpected(1); coreMock.reset(); - mockDispatcher.verifyExpectations(); + mockCallables.verifyExpectations(); } public void testVerifyFailuresIncludeMockName() { - mockDispatcher.verifyFailure = new AssertionFailedError("verify failure"); + mockCallables.verifyFailure = new AssertionFailedError("verify failure"); - mockDispatcher.verifyCalls.setExpected(1); + mockCallables.setExpectedVerifyCalls(1); try { coreMock.verify(); } catch (AssertionFailedError expected) { AssertMo.assertIncludes("Should include mock name", MOCK_NAME, expected.getMessage()); - mockDispatcher.verifyExpectations(); + mockCallables.verifyExpectations(); return; } fail("Should have thrown exception"); |