From: Tim M. <ma...@us...> - 2003-07-07 00:19:36
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv26152/core/test/mockobjects/dynamic Modified Files: MockTest.java MockCallableCollection.java DummyInterface.java Added Files: CoreMockTest.java Log Message: Composition of DynamicMock step - 3 Separated CoreTests from MockTests --- NEW FILE: CoreMockTest.java --- /* * Created on 07-Jul-2003 */ package test.mockobjects.dynamic; import com.mockobjects.dynamic.CoreMock; import com.mockobjects.dynamic.DynamicUtil; import com.mockobjects.util.AssertMo; import com.mockobjects.util.Verifier; import junit.framework.AssertionFailedError; import junit.framework.TestCase; public class CoreMockTest extends TestCase { private static final String MOCK_NAME = "Test mock"; private DummyInterface proxy; private CoreMock mock; private MockCallableCollection mockCallables = new MockCallableCollection(); private MockCallable mockCallable = new MockCallable("mockCallable"); public CoreMockTest(String name) { super(name); } public void setUp() { mock = new CoreMock(DummyInterface.class, MOCK_NAME, mockCallables); try { proxy = (DummyInterface)mock.proxy(); } catch (ClassCastException ex) { fail("proxy is not of expected interface type"); } } public void testMockAnnotatesAssertionFailedErrors() throws Throwable { final String originalMessage = "original message"; mockCallables.setupCall(new AssertionFailedError(originalMessage)); try { proxy.noArgVoidMethod(); } catch (AssertionFailedError err) { AssertMo.assertIncludes("should contain original message", originalMessage, err.getMessage()); AssertMo.assertIncludes("should contain mock name", MOCK_NAME, err.getMessage()); } } public void testMockNameFromClass() throws Exception { assertEquals("mockString", CoreMock.mockNameFromClass(String.class)); } public void testMockProxyReturnsConfiguredResult() throws Throwable { final String result = "configured result"; mockCallables.setupCall(result); assertSame("result is returned by mock", result, proxy.oneArgMethod("arg")); } public void testMockProxySendsAllArgument() throws Throwable { mockCallables.addExpectedCall(DummyInterface.METHOD_TWOARG_NAME, DummyInterface.METHOD_TWOARG_ARGS); mockCallables.setupCall("result ignored"); 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 testMockProxySendsEmptyArrayWhenNoArguments() throws Exception { mockCallables.addExpectedCall(DummyInterface.METHOD_NOARGVOID_NAME, DummyInterface.METHOD_NOARGVOID_ARGS); mockCallables.setupCall("result ignored"); proxy.noArgVoidMethod(); Verifier.verifyObject(this); // Can't use Verifier as we are verifying "verify" mockCallables.verifyExpectations(); } public void testMockProxyThrowsConfiguredExceptions() throws Throwable { final Throwable throwable = new DummyThrowable(); mockCallable.setupCallThrow(throwable); mockCallables.setupCall(mockCallable); try { proxy.noArgVoidMethod(); } catch (Throwable ex) { assertSame("exception is caught by mock", throwable, ex); } } public void testMockToStringContainsName() { AssertMo.assertIncludes("result of toString() should include name", MOCK_NAME, mock.toString()); } public void testMockVerifies() throws Exception { mockCallables.setExpectedVerifyCalls(1); mock.verify(); // Can't use Verifier as we are verifying "verify" mockCallables.verifyExpectations(); } public void testProxyEquality() throws Exception { mockCallables.setupCall(new Boolean(false)); mockCallables.setExpectedCallCalls(0); assertTrue("Should handle proxy equality without checking expectations", proxy.equals(proxy)); Verifier.verifyObject(this); } public void testProxyInEquality() throws Exception { mockCallables.setupCall(new Boolean(false)); mockCallables.addExpectedCall("equals", new Object[] {"not a proxy"}); assertFalse("Should handle proxy inequality by calling through", proxy.equals("not a proxy")); Verifier.verifyObject(this); } public void testProxyToString() throws Exception { assertEquals("Should get a mock name without touching the underlying mock", MOCK_NAME, DynamicUtil.proxyToString(proxy)); mock.verify(); // should not fail on a proxyToString call } } Index: MockTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockTest.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- MockTest.java 6 Jul 2003 02:31:37 -0000 1.15 +++ MockTest.java 7 Jul 2003 00:19:33 -0000 1.16 @@ -359,98 +359,4 @@ Verifier.verifyObject(this); mockCallables.verifyExpectations(); } - - public void testMockAnnotatesAssertionFailedErrors() - throws Throwable { - final String originalMessage = "original message"; - - mockCallables.setupCall(new AssertionFailedError(originalMessage)); - - try { - proxy.noArgMethodVoid(); - } catch (AssertionFailedError err) { - AssertMo.assertIncludes("should contain original message", originalMessage, err.getMessage()); - AssertMo.assertIncludes("should contain mock name", MOCK_NAME, err.getMessage()); - } - } - - public void testMockNameFromClass() throws Exception { - assertEquals("mockString", Mock.mockNameFromClass(String.class)); - } - - public void testMockProxyReturnsConfiguredResult() - throws Throwable { - final String result = "configured result"; - - mockCallables.setupCall(result); - - assertSame("result is returned by mock", result, proxy.oneArgMethod(METHOD_TWOARG_ARGS[0])); - } - - public void testMockProxySendsAllArgument() throws Throwable { - mockCallables.addExpectedCall(METHOD_TWOARG_NAME, METHOD_TWOARG_ARGS); - mockCallables.setupCall("result ignored"); - - proxy.twoArgMethod(METHOD_TWOARG_ARGS[0], METHOD_TWOARG_ARGS[1]); - - mockCallables.verifyExpectations(); - } - - public void testMockProxySendsEmptyArrayWhenNoArguments() - throws Exception { - mockCallables.addExpectedCall(METHOD_NOARG_NAME, METHOD_NOARG_ARGS); - mockCallables.setupCall("result ignored"); - - proxy.noArgMethodVoid(); - - Verifier.verifyObject(this); - mockCallables.verifyExpectations(); - } - - public void testMockProxyThrowsConfiguredExceptions() - throws Throwable { - final Throwable throwable = new DummyThrowable(); - - mockCallables.setupCall(new ThrowStub(throwable)); - - try { - proxy.noArgMethodVoid(); - } catch (Throwable ex) { - assertSame("exception is caught by mock", throwable, ex); - } - } - - public void testMockToStringContainsName() { - AssertMo.assertIncludes("result of toString() should include name", MOCK_NAME, mock.toString()); - } - - public void testMockVerifies() throws Exception { - mockCallables.setExpectedVerifyCalls(1); - - mock.verify(); - - mockCallables.verifyExpectations(); - } - - public void testProxyEquality() throws Exception { - assertTrue("Should handle proxy equality without checking expectations", proxy.equals(proxy)); - } - - public void testProxyInEquality() throws Exception { - boolean IGNORED_RESULT = true; - CallStub ret = new ReturnStub(new Boolean(IGNORED_RESULT)); - mockCallFactory.setupCreateReturnStub(ret); - mockCallFactory.setupCreateCallSignature(new CallSignature("call",C.anyArgs(1),ret)); - mockCallables.setupCall(new Boolean(false)); - - mock.matchAndReturn("call", C.anyArgs(1), IGNORED_RESULT); - assertFalse("Should handle proxy inequality by calling through", proxy.equals("not a proxy")); - - Verifier.verifyObject(this); - } - - public void testProxyToString() throws Exception { - assertEquals("Should get a mock name without touching the underlying mock", MOCK_NAME, DynamicUtil.proxyToString(proxy)); - mock.verify(); // should not fail on a proxyToString call - } } Index: MockCallableCollection.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockCallableCollection.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- MockCallableCollection.java 6 Jul 2003 23:24:09 -0000 1.2 +++ MockCallableCollection.java 7 Jul 2003 00:19:33 -0000 1.3 @@ -15,13 +15,13 @@ public ExpectationList matchedCallables = new ExpectationList("CallableAddable matchedCallables"); public ExpectationList expectedCallables = new ExpectationList("CallableAddable expectedCallables"); private ExpectationCounter myMatchesCalls = new ExpectationCounter("com.mockobjects.dynamic.CallableAddable MatchesCalls"); - private ReturnValues myActualMatchesReturnValues = new ReturnValues(true); + private ReturnValues myActualMatchesReturnValues = new ReturnValues("Matches", true); private ExpectationList myMatchesParameter0Values = new ExpectationList("com.mockobjects.dynamic.CallableAddable MatchesParameter0Values"); private ExpectationList myMatchesParameter1Values = new ExpectationList("com.mockobjects.dynamic.CallableAddable MatchesParameter1Values"); private ExpectationCounter myGetDescriptionCalls = new ExpectationCounter("com.mockobjects.dynamic.CallableAddable GetDescriptionCalls"); - private ReturnValues myActualGetDescriptionReturnValues = new ReturnValues(true); + private ReturnValues myActualGetDescriptionReturnValues = new ReturnValues("GetDescription", true); private ExpectationCounter myCallCalls = new ExpectationCounter("com.mockobjects.dynamic.CallableAddable CallCalls"); - private ReturnValues myActualCallReturnValues = new ReturnValues(true); + private ReturnValues myActualCallReturnValues = new ReturnValues("CallReturn", true); private ExpectationList myCallMethodNames = new ExpectationList("com.mockobjects.dynamic.CallableAddable methodName"); private ExpectationList myCallArguments = new ExpectationList("com.mockobjects.dynamic.CallableAddable arguments"); private ExpectationCounter myVerifyCalls = new ExpectationCounter("com.mockobjects.dynamic.CallableAddable VerifyCalls"); Index: DummyInterface.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/DummyInterface.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- DummyInterface.java 18 May 2003 20:59:38 -0000 1.2 +++ DummyInterface.java 7 Jul 2003 00:19:33 -0000 1.3 @@ -1,15 +1,24 @@ -/* - * Created on 04-Apr-2003 - */ + package test.mockobjects.dynamic; -/** - * @author dev - */ public interface DummyInterface { - public String twoArgMethod( String arg1, String arg2 ) throws Throwable; - public String oneArgMethod( String arg1); + void noArgVoidMethod(); + String noArgMethod(); + String oneArgMethod( String arg1); + String twoArgMethod( String arg1, String arg2 ) throws Throwable; + + final String METHOD_NOARGVOID_NAME = "noArgVoidMethod"; + final Object[] METHOD_NOARGVOID_ARGS = new Object[0]; + + final String METHOD_NOARG_NAME = "noArgMethod"; + final Object[] METHOD_NOARG_ARGS = new Object[0]; + final String METHOD_NOARG_RESULT = "resultNoArgs"; + + final String METHOD_ONEARG_NAME = "oneArgMethod"; + final String[] METHOD_ONEARG_ARGS = new String[] { "oneP1" }; + final String METHOD_ONEARG_RESULT = "result1Args"; - public void noArgMethodVoid(); - public String noArgMethod(); + final String METHOD_TWOARG_NAME = "twoArgMethod"; + final String[] METHOD_TWOARG_ARGS = new String[] { "twoP1", "twoP2" }; + final String METHOD_TWOARG_RESULT = "resultTwoArgs"; } |