From: Nat P. <np...@us...> - 2002-11-07 17:45:37
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory usw-pr-cvs1:/tmp/cvs-serv7280/src/core/test/mockobjects/dynamic Modified Files: MockTest.java CallCounterTest.java CallSequenceTest.java Log Message: Added more checks to catch wrong method names earlier and give meaningful failure messages Refactoring: renamed expect... methods in Mock class to match Joe's better naming convention Fixed and extended Javadoc comments. Index: MockTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockTest.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- MockTest.java 7 Nov 2002 13:04:20 -0000 1.6 +++ MockTest.java 7 Nov 2002 17:45:03 -0000 1.7 @@ -62,7 +62,7 @@ public void testMockCallToNoArgMethod() { Object result = new Object(); - _mock.expectReturn( "noArgs", Mock.NO_ARGS, result ); + _mock.expectAndReturn( "noArgs", Mock.NO_ARGS, result ); assertSame( result, _interface.noArgs() ); @@ -78,7 +78,7 @@ } public void testObjectTypes() { - _mock.expectReturn( "objectTypes", + _mock.expectAndReturn( "objectTypes", new Predicate[] { new IsEqual( new Integer(1) ) }, "1" ); @@ -87,7 +87,7 @@ } public void testPrimitiveTypes() { - _mock.expectReturn( "primitiveTypes", + _mock.expectAndReturn( "primitiveTypes", new Predicate[] { new IsEqual( new Integer(2) ), new IsEqual( new Integer(3) ) }, new Integer(6) ); @@ -100,8 +100,8 @@ Object result1 = new Object(); Object result2 = new Object(); - _mock.expectReturn( "noArgs", Mock.NO_ARGS, result1 ); - _mock.expectReturn( "noArgs", Mock.NO_ARGS, result2 ); + _mock.expectAndReturn( "noArgs", Mock.NO_ARGS, result1 ); + _mock.expectAndReturn( "noArgs", Mock.NO_ARGS, result2 ); assertSame( result2, _interface.noArgs() ); assertSame( result2, _interface.noArgs() ); @@ -109,7 +109,7 @@ } public void testThrow() { - _mock.expectThrow( "primitiveTypes", + _mock.expectAndThrow( "primitiveTypes", new Predicate[] { new IsEqual( new Integer(2) ), new IsEqual( new Integer(3) ) }, new ArithmeticException("message") ); @@ -233,7 +233,7 @@ Predicate p = new IsEqual( new Integer(2) ); Predicate q = new IsAnything(); - _mock.expectReturn( "objectTypes", new Predicate[]{p,q}, "2" ); + _mock.expectAndReturn( "objectTypes", new Predicate[]{p,q}, "2" ); assertFails( "mock did not fail when wrong number of arguments passed", new Runnable() { @@ -259,7 +259,7 @@ public void testPredicateFailure() { Predicate p = new IsEqual( new Integer(2) ); - _mock.expectReturn( "objectTypes", new Predicate[]{p}, "2" ); + _mock.expectAndReturn( "objectTypes", new Predicate[]{p}, "2" ); assertTrue( !p.eval( new Integer(1) ) ); try { @@ -387,7 +387,7 @@ } public void testErrorWhenMockedVoidMethodReturnsAValue() { - _mock.expectReturn( "voidMethod", Mock.NO_ARGS, Boolean.TRUE ); + _mock.expectAndReturn( "voidMethod", Mock.NO_ARGS, Boolean.TRUE ); try { _interface.voidMethod(); @@ -483,6 +483,32 @@ } ); } + public void testFailureWhenExpectNotCalledMethodNotOnMockedInterfaces() { + final Mock mock = new Mock( Interface1.class, Interface2.class ); + + assertFails( "should fail with bad method name", new Runnable() { + public void run() { + mock.expectNotCalled( "CeciNestPasUneMethode" ); + } + } ); + } + + public void testFailureWhenOrderMethodNotOnMockedInterfaces() { + final Mock mock = new Mock( Interface1.class, Interface2.class ); + + assertFails( "should fail with bad first method name", new Runnable() { + public void run() { + mock.order( "CeciNestPasUneMethode", "method2" ); + } + } ); + assertFails( "should fail with bad second method name", new Runnable() { + public void run() { + mock.order( "method1", "CeciNestPasUneMethode" ); + } + } ); + } + + public static class DerivedMock extends Mock @@ -524,7 +550,7 @@ new Class[]{ ExampleInterface.class }, mock ); - mock.expectReturn( "objectTypes", + mock.expectAndReturn( "objectTypes", new Predicate[] { new IsAnything() }, "result" ); Index: CallCounterTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/CallCounterTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- CallCounterTest.java 6 Nov 2002 15:54:35 -0000 1.2 +++ CallCounterTest.java 7 Nov 2002 17:45:04 -0000 1.3 @@ -28,7 +28,7 @@ final Object[] ARGS = { new Object() }; final Object RESULT = new Object(); - mock_call.expectReturn( "call", ARGS, RESULT ); + mock_call.expectAndReturn( "call", ARGS, RESULT ); assertSame( RESULT, counter.call(ARGS) ); @@ -44,7 +44,7 @@ 1, (MockCall)mock_call.proxy() ); final Object RESULT = new Object(); - mock_call.expectThrow( "call", P.ANY_ARGS, new ExampleException() ); + mock_call.expectAndThrow( "call", P.ANY_ARGS, new ExampleException() ); try { counter.call( new Object[0] ); Index: CallSequenceTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/CallSequenceTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- CallSequenceTest.java 6 Nov 2002 15:54:35 -0000 1.2 +++ CallSequenceTest.java 7 Nov 2002 17:45:04 -0000 1.3 @@ -50,10 +50,10 @@ final Object[] ARGS_2 = { new Object() }; final Object RESULT_2 = new Object(); - mock_call_1.expectReturn( "call", ARGS_1, RESULT_1 ); + mock_call_1.expectAndReturn( "call", ARGS_1, RESULT_1 ); call_list.expect( (MockCall)mock_call_1.proxy() ); - mock_call_2.expectReturn( "call", ARGS_2, RESULT_2 ); + mock_call_2.expectAndReturn( "call", ARGS_2, RESULT_2 ); call_list.expect( (MockCall)mock_call_2.proxy() ); assertSame( RESULT_1, call_list.call( ARGS_1 ) ); @@ -75,11 +75,11 @@ final ExampleException EXCEPTION_1 = new ExampleException(); final ExampleException EXCEPTION_2 = new ExampleException(); - mock_call_1.expectThrow( "call", P.args(P.same(ARGS_1)), EXCEPTION_1 ); + mock_call_1.expectAndThrow( "call", P.args(P.same(ARGS_1)), EXCEPTION_1 ); call_list.expect( (MockCall)mock_call_1.proxy() ); - mock_call_2.expectThrow( "call", P.args(P.eq(ARGS_2)), EXCEPTION_2 ); + mock_call_2.expectAndThrow( "call", P.args(P.eq(ARGS_2)), EXCEPTION_2 ); call_list.expect( (MockCall)mock_call_2.proxy() ); try { |