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-06-27 16:03:23
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv8319/src/core/test/mockobjects/dynamic Modified Files: Tag: Nat_reworks_dynamics_from_0_09 NameMatcherTest.java CallSelectionTest.java CallDecoratorTest.java CallCollectionBuilderTest.java MockCallFactory.java MockCompositeCallable.java DefaultReturnStubTest.java MockTest.java ArgumentMatcherTest.java Log Message: Further changes from Nat Index: NameMatcherTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/NameMatcherTest.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- NameMatcherTest.java 26 Jun 2003 17:33:12 -0000 1.1.2.2 +++ NameMatcherTest.java 27 Jun 2003 16:03:20 -0000 1.1.2.3 @@ -22,28 +22,34 @@ String.class, ARGS ); - - private final NameMatcher callName = new NameMatcher( METHOD_NAME, delegate ); + + private final NameMatcher nameMatcher = + new NameMatcher( METHOD_NAME, delegate ); public NameMatcherTest(String name) { super(name); } - public void testReturnsMethodNameAsDescription() { + public void testDescriptionIsMethodNamedPrefixedToDelegateDescription() { + String delegateDescription = "-delegate"; + + delegate.setupGetDescription(delegateDescription); + assertEquals( "expected method name as description", - METHOD_NAME, callName.getDescription() ); + METHOD_NAME + delegateDescription, + nameMatcher.getDescription() ); } public void testReturnsMethodNameFromGetMethodName() { assertEquals( "expected method name", - METHOD_NAME, callName.getMethodName() ); + METHOD_NAME, nameMatcher.getMethodName() ); } public void testPassesMatchToDelegateIfMethodHasTheSameName() { delegate.setExpectedMatches( CALL ); delegate.setupMatchesReturn(true); - boolean result = callName.matches( CALL ); + nameMatcher.matches( CALL ); delegate.verifyExpectations(); } @@ -52,14 +58,14 @@ delegate.setExpectedMatches( CALL ); delegate.setupMatchesReturn(true); assertTrue( "expected matches to return true", - callName.matches( CALL ) ); + nameMatcher.matches( CALL ) ); delegate.verifyExpectations(); delegate.setExpectedMatches( CALL ); delegate.setupMatchesReturn(false); assertFalse( "expected matches to return false", - callName.matches( CALL ) ); + nameMatcher.matches( CALL ) ); delegate.verifyExpectations(); } @@ -73,7 +79,7 @@ delegate.setExpectedMatchesCount(0); assertFalse( "expected matches to return false with other method name", - callName.matches( OTHER_CALL ) ); + nameMatcher.matches( OTHER_CALL ) ); delegate.verifyExpectations(); } @@ -87,7 +93,7 @@ String.class, new Object[0] ); assertTrue( "expected matches to return true", - callName.matches(CALL0) ); + nameMatcher.matches(CALL0) ); final ActiveCall CALL1 = new ActiveCall( METHOD_NAME, @@ -95,7 +101,7 @@ String.class, new Object[]{"arg1"} ); assertTrue( "expected matches to return true", - callName.matches(CALL1) ); + nameMatcher.matches(CALL1) ); final ActiveCall CALL2 = new ActiveCall( METHOD_NAME, @@ -103,7 +109,7 @@ String.class, new Object[]{"arg1","arg2"} ); assertTrue( "expected matches to return true", - callName.matches(CALL2) ); + nameMatcher.matches(CALL2) ); final ActiveCall CALL3 = new ActiveCall( METHOD_NAME, @@ -111,6 +117,6 @@ String.class, new Object[]{"arg1","arg2","arg3"} ); assertTrue( "expected matches to return true", - callName.matches(CALL3) ); + nameMatcher.matches(CALL3) ); } } Index: CallSelectionTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/CallSelectionTest.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- CallSelectionTest.java 21 Jun 2003 14:01:07 -0000 1.1.2.1 +++ CallSelectionTest.java 27 Jun 2003 16:03:20 -0000 1.1.2.2 @@ -8,30 +8,30 @@ import com.mockobjects.util.AssertMo; public class CallSelectionTest - extends TestCase + extends TestCase { final String METHOD_A_NAME = "methodA"; final String METHOD_A_RESULT = "resultA"; - final Throwable METHOD_A_EXCEPTION = - new DummyThrowable("Configured test throwable"); - final String[] METHOD_A_ARGS = new String[] { "a1", "a2" }; - final Constraint[] METHOD_A_CONSTRAINTS = C.args(C.eq("a1"), C.eq("a2")); - final ActiveCall CALL_A = new ActiveCall( - METHOD_A_NAME, new Class[]{String.class,String.class}, String.class, - METHOD_A_ARGS ); + final Throwable METHOD_A_EXCEPTION = + new DummyThrowable("Configured test throwable"); + final String[] METHOD_A_ARGS = new String[] { "a1", "a2" }; + final Constraint[] METHOD_A_CONSTRAINTS = C.args(C.eq("a1"), C.eq("a2")); + final ActiveCall CALL_A = new ActiveCall( + METHOD_A_NAME, new Class[]{String.class,String.class}, String.class, + METHOD_A_ARGS ); final String METHOD_B_NAME = "methodB"; final String METHOD_B_RESULT = "resultB"; final String[] METHOD_B_ARGS = new String[] { "b1", "b2" }; - final ActiveCall CALL_B = new ActiveCall( - METHOD_B_NAME, new Class[]{String.class,String.class}, String.class, - METHOD_B_ARGS ); - - final String METHOD_C_NAME = "methodC"; - final String[] METHOD_C_ARGS = { "c1", "c2" }; - final ActiveCall CALL_C = new ActiveCall( - METHOD_C_NAME, new Class[]{String.class,String.class}, Void.class, - METHOD_C_ARGS ); + final ActiveCall CALL_B = new ActiveCall( + METHOD_B_NAME, new Class[]{String.class,String.class}, String.class, + METHOD_B_ARGS ); + + final String METHOD_C_NAME = "methodC"; + final String[] METHOD_C_ARGS = { "c1", "c2" }; + final ActiveCall CALL_C = new ActiveCall( + METHOD_C_NAME, new Class[]{String.class,String.class}, Void.class, + METHOD_C_ARGS ); private CallSelection callSelection = new CallSelection(); @@ -47,32 +47,30 @@ public void testCallFailsOnEmptySet() throws Throwable { try { callSelection.call(CALL_A); - } catch (AssertionFailedError ex) { + fail("Should fail for a missing item"); + + } catch( AssertionFailedError ex ) { AssertMo.assertIncludes( "reports empty set in error message", - "no methods", ex.getMessage()); - - return; + "no method calls", ex.getMessage()); } - - fail("Should fail for a missing item"); } public void testCallPassedToContainedElementsInReverseOrderOfAddition() - throws Throwable - { + throws Throwable + { methodA.setExpectedMatches(CALL_A); methodA.setupMatchesReturn(true); methodA.setExpectedCall(CALL_A); methodA.setupCallReturn(METHOD_A_RESULT); - methodB.setExpectedMatches(CALL_A); - methodB.setupMatchesReturn(false); + methodB.setExpectedMatches(CALL_A); + methodB.setupMatchesReturn(false); - callSelection.addCallable(methodA); + callSelection.addCallable(methodA); callSelection.addCallable(methodB); assertSame("expected result from method A", METHOD_A_RESULT, - callSelection.call(CALL_A)); + callSelection.call(CALL_A)); methodA.verifyExpectations(); methodB.verifyExpectations(); @@ -80,43 +78,41 @@ public void testMatchedCallStopsSearch() throws Throwable - { - methodA.setExpectedCallCount(0); + { + methodA.setExpectedCallCount(0); methodB.setExpectedMatches(CALL_B); methodB.setupMatchesReturn(true); - methodB.setExpectedCall(CALL_B); - methodB.setupCallReturn(METHOD_B_RESULT); + methodB.setExpectedCall(CALL_B); + methodB.setupCallReturn(METHOD_B_RESULT); callSelection.addCallable(methodA); callSelection.addCallable(methodB); assertSame( "expected result from method B", - METHOD_B_RESULT, callSelection.call(CALL_B)); + METHOD_B_RESULT, callSelection.call(CALL_B)); methodA.verifyExpectations(); methodB.verifyExpectations(); } - public void testExpectationsOverrideEarlierMatchingExpectations() - throws Throwable - { - Callable methodASignature = - new ArgumentMatcher( METHOD_A_NAME, METHOD_A_CONSTRAINTS, - new ReturnStub("result1")); - Callable anotherMethodASignature = - new ArgumentMatcher( METHOD_A_NAME, METHOD_A_CONSTRAINTS, - new ReturnStub("result2")); - - callSelection.addCallable(methodASignature); - callSelection.addCallable(new CallOnceExpectation(anotherMethodASignature)); - - assertSame( "expected result from method A", - "result2", - callSelection.call(CALL_A)); + public void testExpectationsOverrideEarlierMatchingExpectations() + throws Throwable + { + Callable methodASignature = + new NameMatcher( METHOD_A_NAME, new ReturnStub("result1")); + Callable anotherMethodASignature = + new NameMatcher( METHOD_A_NAME, new ReturnStub("result2")); + + callSelection.addCallable(methodASignature); + callSelection.addCallable(new CallOnceExpectation(anotherMethodASignature)); + + assertSame( "expected result from method A", + "result2", + callSelection.call(CALL_A)); - callSelection.verify(); - } + callSelection.verify(); + } public void testConfiguredResultReturned() throws Throwable { mockCallable.setupCallReturn(METHOD_A_RESULT); @@ -125,12 +121,12 @@ callSelection.addCallable(mockCallable); assertSame( "result is returned by mock", - METHOD_A_RESULT, callSelection.call(CALL_A)); + METHOD_A_RESULT, callSelection.call(CALL_A)); } public void testCallableThrowableThrown() throws Throwable - { + { mockCallable.setupMatchesReturn(true); mockCallable.setupCallThrow(METHOD_A_EXCEPTION); @@ -191,7 +187,7 @@ public void testVerifyFailsIfContainedElementDoesNotVerify() throws Exception - { + { methodA.setExpectedVerifyCalls(1); methodA.setupVerifyThrow(new AssertionFailedError("verify failed")); callSelection.addCallable(methodA); @@ -207,47 +203,47 @@ fail("Should have got a failure for contained element failing"); } - public void testDoesNotMatchIfEmpty() { - assertTrue( "empty selection does not match", - !callSelection.matches(CALL_A) ); - } - - public void testPassesMatchesParametersToAllElements() { - callSelection.addCallable( methodA ); - callSelection.addCallable( methodB ); - - methodA.setExpectedMatches(CALL_A); - methodA.setupMatchesReturn(true); - methodB.setExpectedMatches(CALL_A); - methodA.setupMatchesReturn(true); - - assertTrue( "should match", callSelection.matches(CALL_A) ); - - callSelection.verify(); - } - - public void testMatchesIfAnyExpectedElementMatches() { - callSelection.addCallable( methodA ); - callSelection.addCallable( methodB ); - - methodA.setupMatchesReturn(true); - methodB.setupMatchesReturn(false); - assertTrue( "should match methodA", callSelection.matches(CALL_A) ); - - methodA.setupMatchesReturn(false); - methodB.setupMatchesReturn(true); - assertTrue( "should match methodB", callSelection.matches(CALL_B) ); - } - - public void testDoesNotMatchIfNoElementsMatch() { - callSelection.addCallable( methodA ); - callSelection.addCallable( methodB ); - - methodA.setExpectedMatches(CALL_C); - methodA.setupMatchesReturn(false); - methodB.setExpectedMatches(CALL_C); - methodB.setupMatchesReturn(false); + public void testDoesNotMatchIfEmpty() { + assertTrue( "empty selection does not match", + !callSelection.matches(CALL_A) ); + } + + public void testPassesMatchesParametersToAllElements() { + callSelection.addCallable( methodA ); + callSelection.addCallable( methodB ); + + methodA.setExpectedMatches(CALL_A); + methodA.setupMatchesReturn(true); + methodB.setExpectedMatches(CALL_A); + methodA.setupMatchesReturn(true); - assertFalse( "no method should match", callSelection.matches(CALL_C) ); - } + assertTrue( "should match", callSelection.matches(CALL_A) ); + + callSelection.verify(); + } + + public void testMatchesIfAnyExpectedElementMatches() { + callSelection.addCallable( methodA ); + callSelection.addCallable( methodB ); + + methodA.setupMatchesReturn(true); + methodB.setupMatchesReturn(false); + assertTrue( "should match methodA", callSelection.matches(CALL_A) ); + + methodA.setupMatchesReturn(false); + methodB.setupMatchesReturn(true); + assertTrue( "should match methodB", callSelection.matches(CALL_B) ); + } + + public void testDoesNotMatchIfNoElementsMatch() { + callSelection.addCallable( methodA ); + callSelection.addCallable( methodB ); + + methodA.setExpectedMatches(CALL_C); + methodA.setupMatchesReturn(false); + methodB.setExpectedMatches(CALL_C); + methodB.setupMatchesReturn(false); + + assertFalse( "no method should match", callSelection.matches(CALL_C) ); + } } Index: CallDecoratorTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/CallDecoratorTest.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- CallDecoratorTest.java 26 Jun 2003 17:33:12 -0000 1.1.2.2 +++ CallDecoratorTest.java 27 Jun 2003 16:03:20 -0000 1.1.2.3 @@ -91,7 +91,7 @@ mockCallable.setExpectedMatches(CALL); mockCallable.setupMatchesReturn(true); - boolean result = callDecorator.matches(CALL); + callDecorator.matches(CALL); mockCallable.verifyExpectations(); } Index: CallCollectionBuilderTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/CallCollectionBuilderTest.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- CallCollectionBuilderTest.java 21 Jun 2003 14:01:07 -0000 1.1.2.1 +++ CallCollectionBuilderTest.java 27 Jun 2003 16:03:20 -0000 1.1.2.2 @@ -6,7 +6,6 @@ import junit.framework.TestCase; import com.mockobjects.constraint.Constraint; -import com.mockobjects.constraint.IsEqual; import com.mockobjects.dynamic.C; import com.mockobjects.dynamic.CallCollectionBuilder; import com.mockobjects.util.Verifier; @@ -33,6 +32,7 @@ private MockCallFactory mockCallFactory = new MockCallFactory(); private MockCallable mockCallable = new MockCallable(); + private MockCallable mockNameMatcher = new MockCallable(); private MockCallable mockArgumentMatcher = new MockCallable(); private MockCallable mockCallOnceExpectation = new MockCallable(); private MockCallable mockReturnStub = new MockCallable(); @@ -52,7 +52,7 @@ builder = new CallCollectionBuilder( mockCallFactory, mockCompositeCallable ); } - + public void testAddsCallablesToComposite() throws Throwable { @@ -67,15 +67,20 @@ throws Throwable { mockCallFactory.addExpectedCreateArgumentMatcherValues( - METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, - mockCallable ); + METHOD_TWOARG_CONSTRAINTS, mockCallable ); mockCallFactory.setupCreateArgumentMatcher( mockArgumentMatcher ); + mockCallFactory.addExpectedCreateNameMatcherValues( + METHOD_TWOARG_NAME, mockArgumentMatcher ); + mockCallFactory.setupCreateNameMatcher(mockNameMatcher); + mockCallFactory.addExpectedCreateCallOnceExpectationValues( - mockArgumentMatcher ); - mockCallFactory.setupCreateCallOnceExpectation( mockCallOnceExpectation ); + mockNameMatcher ); + mockCallFactory.setupCreateCallOnceExpectation( + mockCallOnceExpectation ); - mockCompositeCallable.addExpectedAddCallableValues(mockCallOnceExpectation); + mockCompositeCallable.addExpectedAddCallableValues( + mockCallOnceExpectation); builder.expect( METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockCallable ); @@ -89,11 +94,17 @@ { mockCallFactory.setExpectedCreateVoidStubCalls(1); mockCallFactory.setupCreateVoidStub(mockVoidStub); + mockCallFactory.addExpectedCreateArgumentMatcherValues( - METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockVoidStub ); + METHOD_TWOARG_CONSTRAINTS, mockVoidStub ); mockCallFactory.setupCreateArgumentMatcher(mockArgumentMatcher); - mockCallFactory.addExpectedCreateCallOnceExpectationValues( - mockArgumentMatcher ); + + mockCallFactory.addExpectedCreateNameMatcherValues( + METHOD_TWOARG_NAME, mockArgumentMatcher ); + mockCallFactory.setupCreateNameMatcher(mockNameMatcher); + + mockCallFactory.addExpectedCreateCallOnceExpectationValues( + mockNameMatcher ); mockCallFactory.setupCreateCallOnceExpectation( mockCallOnceExpectation); @@ -113,10 +124,13 @@ METHOD_NOARGANDRETURN_RESULT); mockCallFactory.setupCreateReturnStub(mockReturnStub); mockCallFactory.addExpectedCreateArgumentMatcherValues( - METHOD_NOARGANDRETURN_NAME, C.NO_ARGS, mockReturnStub); + C.NO_ARGS, mockReturnStub); mockCallFactory.setupCreateArgumentMatcher(mockArgumentMatcher); + mockCallFactory.addExpectedCreateNameMatcherValues( + METHOD_NOARGANDRETURN_NAME, mockArgumentMatcher ); + mockCallFactory.setupCreateNameMatcher(mockNameMatcher); mockCallFactory.addExpectedCreateCallOnceExpectationValues( - mockArgumentMatcher ); + mockNameMatcher ); mockCallFactory.setupCreateCallOnceExpectation( mockCallOnceExpectation ); @@ -133,14 +147,19 @@ public void testBuildsDecoratorsForExpectAndThrowWithNoArguments() throws Throwable { - mockCallFactory.addExpectedCreateThrowStubValues( - METHOD_EXCEPTION ); + mockCallFactory.addExpectedCreateThrowStubValues(METHOD_EXCEPTION); mockCallFactory.setupCreateThrowStub(mockThrowStub); + mockCallFactory.addExpectedCreateArgumentMatcherValues( - METHOD_NOARGANDRETURN_NAME, C.NO_ARGS, mockThrowStub ); + C.NO_ARGS, mockThrowStub ); mockCallFactory.setupCreateArgumentMatcher(mockArgumentMatcher); - mockCallFactory.addExpectedCreateCallOnceExpectationValues( - mockArgumentMatcher); + + mockCallFactory.addExpectedCreateNameMatcherValues( + METHOD_NOARGANDRETURN_NAME, mockArgumentMatcher ); + mockCallFactory.setupCreateNameMatcher(mockNameMatcher); + + mockCallFactory.addExpectedCreateCallOnceExpectationValues( + mockNameMatcher); mockCallFactory.setupCreateCallOnceExpectation( mockCallOnceExpectation ); @@ -158,11 +177,17 @@ { mockCallFactory.addExpectedCreateThrowStubValues(METHOD_EXCEPTION); mockCallFactory.setupCreateThrowStub(mockThrowStub); + mockCallFactory.addExpectedCreateArgumentMatcherValues( - METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockThrowStub ); + METHOD_ONEARG_CONSTRAINTS, mockThrowStub ); mockCallFactory.setupCreateArgumentMatcher(mockArgumentMatcher); - mockCallFactory.addExpectedCreateCallOnceExpectationValues( - mockArgumentMatcher); + + mockCallFactory.addExpectedCreateNameMatcherValues( + METHOD_ONEARG_NAME, mockArgumentMatcher ); + mockCallFactory.setupCreateNameMatcher(mockNameMatcher); + + mockCallFactory.addExpectedCreateCallOnceExpectationValues( + mockNameMatcher); mockCallFactory.setupCreateCallOnceExpectation( mockCallOnceExpectation ); @@ -182,13 +207,18 @@ mockCallFactory.setExpectedCreateVoidStubCalls(1); mockCallFactory.setupCreateVoidStub(mockVoidStub); mockCallFactory.addExpectedCreateArgumentMatcherValues( - METHOD_NOARG_NAME, C.NO_ARGS, mockVoidStub ); + C.NO_ARGS, mockVoidStub ); mockCallFactory.setupCreateArgumentMatcher(mockArgumentMatcher); + mockCallFactory.addExpectedCreateNameMatcherValues( + METHOD_NOARG_NAME, mockArgumentMatcher ); + mockCallFactory.setupCreateNameMatcher(mockNameMatcher); mockCallFactory.addExpectedCreateCallOnceExpectationValues( - mockArgumentMatcher ); - mockCallFactory.setupCreateCallOnceExpectation(mockCallOnceExpectation); + mockNameMatcher ); + mockCallFactory.setupCreateCallOnceExpectation( + mockCallOnceExpectation); - mockCompositeCallable.addExpectedAddCallableValues(mockCallOnceExpectation); + mockCompositeCallable.addExpectedAddCallableValues( + mockCallOnceExpectation); builder.expectVoid( METHOD_NOARG_NAME ); @@ -201,10 +231,16 @@ { mockCallFactory.setExpectedCreateVoidStubCalls(1); mockCallFactory.setupCreateVoidStub(mockVoidStub); - mockCallFactory.addExpectedCreateArgumentMatcherValues(METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockVoidStub); + mockCallFactory.addExpectedCreateArgumentMatcherValues( + METHOD_ONEARG_CONSTRAINTS, mockVoidStub); mockCallFactory.setupCreateArgumentMatcher(mockArgumentMatcher); - mockCallFactory.addExpectedCreateCallOnceExpectationValues(mockArgumentMatcher); - mockCallFactory.setupCreateCallOnceExpectation(mockCallOnceExpectation); + mockCallFactory.addExpectedCreateNameMatcherValues( + METHOD_ONEARG_NAME, mockArgumentMatcher ); + mockCallFactory.setupCreateNameMatcher(mockNameMatcher); + mockCallFactory.addExpectedCreateCallOnceExpectationValues( + mockNameMatcher); + mockCallFactory.setupCreateCallOnceExpectation( + mockCallOnceExpectation); mockCompositeCallable.addExpectedAddCallableValues(mockCallOnceExpectation); @@ -218,18 +254,23 @@ throws Throwable { mockCallFactory.setupCreateVoidStub(mockVoidStub); + mockCallFactory.addExpectedCreateArgumentMatcherValues( - METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockVoidStub ); + METHOD_ONEARG_CONSTRAINTS, mockVoidStub ); mockCallFactory.setupCreateArgumentMatcher(mockArgumentMatcher); - mockCallFactory.setupCreateCallOnceExpectation( + + mockCallFactory.addExpectedCreateNameMatcherValues( + METHOD_ONEARG_NAME, mockArgumentMatcher ); + mockCallFactory.setupCreateNameMatcher(mockNameMatcher); + + mockCallFactory.setupCreateCallOnceExpectation( mockCallOnceExpectation ); - mockCompositeCallable.addExpectedAddCallableValues( mockCallOnceExpectation ); builder.expectVoid( METHOD_ONEARG_NAME, - new IsEqual(METHOD_ONEARG_ARGS[0]) ); + METHOD_ONEARG_ARGS[0] ); Verifier.verifyObject(this); mockCompositeCallable.verifyExpectations(); @@ -241,11 +282,17 @@ mockCallFactory.addExpectedCreateReturnStubValues( METHOD_TWOARG_RESULT ); mockCallFactory.setupCreateReturnStub(mockReturnStub); - mockCallFactory.addExpectedCreateArgumentMatcherValues( - METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockReturnStub); - mockCallFactory.setupCreateArgumentMatcher(mockArgumentMatcher); + + mockCallFactory.addExpectedCreateArgumentMatcherValues( + METHOD_TWOARG_CONSTRAINTS, mockReturnStub ); + mockCallFactory.setupCreateArgumentMatcher(mockArgumentMatcher); + + mockCallFactory.addExpectedCreateNameMatcherValues( + METHOD_TWOARG_NAME, mockArgumentMatcher ); + mockCallFactory.setupCreateNameMatcher(mockNameMatcher); + mockCallFactory.addExpectedCreateCallOnceExpectationValues( - mockArgumentMatcher); + mockNameMatcher); mockCallFactory.setupCreateCallOnceExpectation( mockCallOnceExpectation); @@ -265,11 +312,17 @@ { mockCallFactory.addExpectedCreateThrowStubValues(METHOD_EXCEPTION); mockCallFactory.setupCreateThrowStub(mockThrowStub); - mockCallFactory.addExpectedCreateArgumentMatcherValues( - METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockThrowStub ); - mockCallFactory.setupCreateArgumentMatcher(mockArgumentMatcher); - mockCallFactory.addExpectedCreateCallOnceExpectationValues( - mockArgumentMatcher); + + mockCallFactory.addExpectedCreateArgumentMatcherValues( + METHOD_TWOARG_CONSTRAINTS, mockThrowStub ); + mockCallFactory.setupCreateArgumentMatcher(mockArgumentMatcher); + + mockCallFactory.addExpectedCreateNameMatcherValues( + METHOD_TWOARG_NAME, mockArgumentMatcher ); + mockCallFactory.setupCreateNameMatcher(mockNameMatcher); + + mockCallFactory.addExpectedCreateCallOnceExpectationValues( + mockNameMatcher); mockCallFactory.setupCreateCallOnceExpectation( mockCallOnceExpectation); @@ -291,11 +344,17 @@ mockCallFactory.addExpectedCreateReturnStubValues( METHOD_ONEARG_RESULT ); mockCallFactory.setupCreateReturnStub(mockReturnStub); + mockCallFactory.addExpectedCreateArgumentMatcherValues( - METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockReturnStub ); + METHOD_ONEARG_CONSTRAINTS, mockReturnStub ); mockCallFactory.setupCreateArgumentMatcher(mockArgumentMatcher); - mockCallFactory.addExpectedCreateCallOnceExpectationValues( - mockArgumentMatcher ); + + mockCallFactory.addExpectedCreateNameMatcherValues( + METHOD_ONEARG_NAME, mockArgumentMatcher ); + mockCallFactory.setupCreateNameMatcher(mockNameMatcher); + + mockCallFactory.addExpectedCreateCallOnceExpectationValues( + mockNameMatcher ); mockCallFactory.setupCreateCallOnceExpectation( mockCallOnceExpectation ); @@ -317,11 +376,17 @@ mockCallFactory.addExpectedCreateReturnStubValues( METHOD_ONEARG_RESULT ); mockCallFactory.setupCreateReturnStub(mockReturnStub); + mockCallFactory.addExpectedCreateArgumentMatcherValues( - METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockReturnStub ); + METHOD_ONEARG_CONSTRAINTS, mockReturnStub ); mockCallFactory.setupCreateArgumentMatcher(mockArgumentMatcher); + + mockCallFactory.addExpectedCreateNameMatcherValues( + METHOD_ONEARG_NAME, mockArgumentMatcher ); + mockCallFactory.setupCreateNameMatcher(mockNameMatcher); + mockCallFactory.addExpectedCreateCallOnceExpectationValues( - mockArgumentMatcher ); + mockNameMatcher ); mockCallFactory.setupCreateCallOnceExpectation( mockCallOnceExpectation ); @@ -340,14 +405,20 @@ public void testBuildsDecoratorsForExpectAndThrowWithOneConstraint() throws Throwable { - mockCallFactory.addExpectedCreateReturnStubValues( - METHOD_ONEARG_RESULT ); + mockCallFactory.addExpectedCreateThrowStubValues( + METHOD_EXCEPTION ); mockCallFactory.setupCreateThrowStub(mockThrowStub); + mockCallFactory.addExpectedCreateArgumentMatcherValues( - METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockThrowStub ); + METHOD_ONEARG_CONSTRAINTS, mockThrowStub ); mockCallFactory.setupCreateArgumentMatcher(mockArgumentMatcher); + + mockCallFactory.addExpectedCreateNameMatcherValues( + METHOD_ONEARG_NAME, mockArgumentMatcher ); + mockCallFactory.setupCreateNameMatcher(mockNameMatcher); + mockCallFactory.addExpectedCreateCallOnceExpectationValues( - mockArgumentMatcher ); + mockNameMatcher ); mockCallFactory.setupCreateCallOnceExpectation( mockCallOnceExpectation ); @@ -368,12 +439,16 @@ mockCallFactory.addExpectedCreateReturnStubValues( METHOD_TWOARG_RESULT ); mockCallFactory.setupCreateReturnStub(mockReturnStub); - mockCallFactory.addExpectedCreateArgumentMatcherValues( - METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockReturnStub); - mockCallFactory.setupCreateArgumentMatcher(mockArgumentMatcher); + + mockCallFactory.addExpectedCreateArgumentMatcherValues( + METHOD_TWOARG_CONSTRAINTS, mockReturnStub ); + mockCallFactory.setupCreateArgumentMatcher(mockArgumentMatcher); + + mockCallFactory.addExpectedCreateNameMatcherValues( + METHOD_TWOARG_NAME, mockArgumentMatcher ); + mockCallFactory.setupCreateNameMatcher(mockNameMatcher); - mockCompositeCallable.addExpectedAddCallableValues( - mockArgumentMatcher); + mockCompositeCallable.addExpectedAddCallableValues(mockNameMatcher); builder.matchAndReturn( METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, @@ -388,14 +463,20 @@ { mockCallFactory.addExpectedCreateThrowStubValues(METHOD_EXCEPTION); mockCallFactory.setupCreateThrowStub(mockThrowStub); - mockCallFactory.addExpectedCreateArgumentMatcherValues(METHOD_NOARG_NAME, C.NO_ARGS, mockThrowStub); + + mockCallFactory.addExpectedCreateArgumentMatcherValues( + C.NO_ARGS, mockThrowStub ); mockCallFactory.setupCreateArgumentMatcher(mockArgumentMatcher); - + + mockCallFactory.addExpectedCreateNameMatcherValues( + METHOD_NOARG_NAME, mockArgumentMatcher ); + mockCallFactory.setupCreateNameMatcher(mockNameMatcher); + mockCompositeCallable.addExpectedAddCallableValues( - mockArgumentMatcher); - + mockNameMatcher); + builder.matchAndThrow(METHOD_NOARG_NAME, METHOD_EXCEPTION); - + Verifier.verifyObject(this); mockCompositeCallable.verifyExpectations(); } @@ -405,12 +486,17 @@ { mockCallFactory.addExpectedCreateThrowStubValues(METHOD_EXCEPTION); mockCallFactory.setupCreateThrowStub(mockThrowStub); + mockCallFactory.addExpectedCreateArgumentMatcherValues( - METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockThrowStub); + METHOD_ONEARG_CONSTRAINTS, mockThrowStub); mockCallFactory.setupCreateArgumentMatcher(mockArgumentMatcher); - + + mockCallFactory.addExpectedCreateNameMatcherValues( + METHOD_ONEARG_NAME, mockArgumentMatcher ); + mockCallFactory.setupCreateNameMatcher(mockNameMatcher); + mockCompositeCallable.addExpectedAddCallableValues( - mockArgumentMatcher); + mockNameMatcher); builder.matchAndThrow( METHOD_ONEARG_NAME, METHOD_ONEARG_ARGS[0], @@ -425,12 +511,17 @@ { mockCallFactory.addExpectedCreateThrowStubValues(METHOD_EXCEPTION); mockCallFactory.setupCreateThrowStub(mockThrowStub); + mockCallFactory.addExpectedCreateArgumentMatcherValues( - METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockThrowStub); + METHOD_TWOARG_CONSTRAINTS, mockThrowStub); mockCallFactory.setupCreateArgumentMatcher(mockArgumentMatcher); + mockCallFactory.addExpectedCreateNameMatcherValues( + METHOD_TWOARG_NAME, mockArgumentMatcher ); + mockCallFactory.setupCreateNameMatcher(mockNameMatcher); + mockCompositeCallable.addExpectedAddCallableValues( - mockArgumentMatcher); + mockNameMatcher); builder.matchAndThrow( METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, @@ -446,12 +537,17 @@ mockCallFactory.addExpectedCreateReturnStubValues( METHOD_ONEARG_RESULT); mockCallFactory.setupCreateReturnStub(mockReturnStub); + mockCallFactory.addExpectedCreateArgumentMatcherValues( - METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockReturnStub); + METHOD_ONEARG_CONSTRAINTS, mockReturnStub); mockCallFactory.setupCreateArgumentMatcher(mockArgumentMatcher); - + + mockCallFactory.addExpectedCreateNameMatcherValues( + METHOD_ONEARG_NAME, mockArgumentMatcher ); + mockCallFactory.setupCreateNameMatcher(mockNameMatcher); + mockCompositeCallable.addExpectedAddCallableValues( - mockArgumentMatcher ); + mockNameMatcher ); builder.matchAndReturn( METHOD_ONEARG_NAME, METHOD_ONEARG_ARGS[0], @@ -467,12 +563,17 @@ mockCallFactory.addExpectedCreateReturnStubValues( METHOD_NOARGANDRETURN_RESULT); mockCallFactory.setupCreateReturnStub(mockReturnStub); + mockCallFactory.addExpectedCreateArgumentMatcherValues( - METHOD_NOARG_NAME, C.NO_ARGS, mockReturnStub); + C.NO_ARGS, mockReturnStub); mockCallFactory.setupCreateArgumentMatcher(mockArgumentMatcher); + mockCallFactory.addExpectedCreateNameMatcherValues( + METHOD_NOARG_NAME, mockArgumentMatcher ); + mockCallFactory.setupCreateNameMatcher(mockNameMatcher); + mockCompositeCallable.addExpectedAddCallableValues( - mockArgumentMatcher); + mockNameMatcher); builder.matchAndReturn( METHOD_NOARG_NAME, METHOD_NOARGANDRETURN_RESULT); @@ -481,6 +582,44 @@ mockCompositeCallable.verifyExpectations(); } + public void testBuildsDecoratorsForMatchNameAndReturn() { + mockCallFactory.addExpectedCreateReturnStubValues( + METHOD_NOARGANDRETURN_RESULT); + mockCallFactory.setupCreateReturnStub(mockReturnStub); + + mockCallFactory.addExpectedCreateNameMatcherValues( + METHOD_NOARG_NAME, mockReturnStub ); + mockCallFactory.setupCreateNameMatcher(mockNameMatcher); + + mockCompositeCallable.addExpectedAddCallableValues( + mockNameMatcher); + + builder.matchNameAndReturn( METHOD_NOARG_NAME, + METHOD_NOARGANDRETURN_RESULT); + + Verifier.verifyObject(this); + mockCompositeCallable.verifyExpectations(); + } + + public void testBuildsDecoratorsForMatchNameAndThrow() + throws Throwable + { + mockCallFactory.addExpectedCreateThrowStubValues(METHOD_EXCEPTION); + mockCallFactory.setupCreateThrowStub(mockThrowStub); + + mockCallFactory.addExpectedCreateNameMatcherValues( + METHOD_NOARG_NAME, mockThrowStub ); + mockCallFactory.setupCreateNameMatcher(mockNameMatcher); + + mockCompositeCallable.addExpectedAddCallableValues( + mockNameMatcher ); + + builder.matchNameAndThrow(METHOD_NOARG_NAME, METHOD_EXCEPTION); + + Verifier.verifyObject(this); + mockCompositeCallable.verifyExpectations(); + } + public void testBuildsCallSequenceAndWrapsItWithACallCollectionBuilder() { final CallCollectionBuilder expectedSequenceBuilder = new CallCollectionBuilder( mockCallFactory, @@ -498,7 +637,8 @@ assertSame( "expected same builder for new sequence", expectedSequenceBuilder, returnedSequenceBuilder ); - mockCallFactory.verify(); + Verifier.verifyObject(this); + mockCompositeCallable.verifyExpectations(); } public void testBuildsCallSelectionAndWrapsItWithACallCollectionBuilder() { @@ -518,6 +658,7 @@ assertSame( "expected same builder for new selection", expectedSelectionBuilder, returnedSelectionBuilder ); - mockCallFactory.verify(); + Verifier.verifyObject(this); + mockCompositeCallable.verifyExpectations(); } } Index: MockCallFactory.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockCallFactory.java,v retrieving revision 1.4.2.2 retrieving revision 1.4.2.3 diff -u -r1.4.2.2 -r1.4.2.3 --- MockCallFactory.java 26 Jun 2003 17:33:12 -0000 1.4.2.2 +++ MockCallFactory.java 27 Jun 2003 16:03:20 -0000 1.4.2.3 @@ -1,12 +1,15 @@ package test.mockobjects.dynamic; import mockmaker.ReturnValues; -import com.mockobjects.*; + +import com.mockobjects.ExceptionalReturnValue; +import com.mockobjects.ExpectationCounter; +import com.mockobjects.ExpectationList; +import com.mockobjects.constraint.Constraint; +import com.mockobjects.dynamic.CallCollectionBuilder; import com.mockobjects.dynamic.CallFactory; import com.mockobjects.dynamic.Callable; -import com.mockobjects.constraint.Constraint; import com.mockobjects.dynamic.CompositeCallable; -import com.mockobjects.dynamic.CallCollectionBuilder; public class MockCallFactory implements CallFactory{ private ExpectationCounter myCreateReturnStubCalls = new ExpectationCounter("com.mockobjects.dynamic.CallFactory CreateReturnStubCalls"); private ReturnValues myActualCreateReturnStubReturnValues = new ReturnValues(false); @@ -21,9 +24,8 @@ private ExpectationList myCreateCallOnceExpectationParameter0Values = new ExpectationList("com.mockobjects.dynamic.CallFactory com.mockobjects.dynamic.Callable"); private ExpectationCounter myCreateArgumentMatcherCalls = new ExpectationCounter("com.mockobjects.dynamic.CallFactory CreateArgumentMatcherCalls"); private ReturnValues myActualCreateArgumentMatcherReturnValues = new ReturnValues(false); - private ExpectationList myCreateArgumentMatcherParameter0Values = new ExpectationList("com.mockobjects.dynamic.CallFactory java.lang.String"); - private ExpectationList myCreateArgumentMatcherParameter1Values = new ExpectationList("com.mockobjects.dynamic.CallFactory com.mockobjects.constraint.Constraint"); - private ExpectationList myCreateArgumentMatcherParameter2Values = new ExpectationList("com.mockobjects.dynamic.CallFactory com.mockobjects.dynamic.Callable"); + private ExpectationList myCreateArgumentMatcherParameter0Values = new ExpectationList("com.mockobjects.dynamic.CallFactory com.mockobjects.constraint.Constraint"); + private ExpectationList myCreateArgumentMatcherParameter1Values = new ExpectationList("com.mockobjects.dynamic.CallFactory com.mockobjects.dynamic.Callable"); private ExpectationCounter myCreateNameMatcherCalls = new ExpectationCounter("com.mockobjects.dynamic.CallFactory CreateNameMatcherCalls"); private ReturnValues myActualCreateNameMatcherReturnValues = new ReturnValues(false); private ExpectationList myCreateNameMatcherParameter0Values = new ExpectationList("com.mockobjects.dynamic.CallFactory java.lang.String"); @@ -114,16 +116,14 @@ public void setExpectedCreateArgumentMatcherCalls(int calls){ myCreateArgumentMatcherCalls.setExpected(calls); } - public void addExpectedCreateArgumentMatcherValues(String arg0, Constraint[] arg1, Callable arg2){ - myCreateArgumentMatcherParameter0Values.addExpected(arg0); - myCreateArgumentMatcherParameter1Values.addExpectedMany(arg1); - myCreateArgumentMatcherParameter2Values.addExpected(arg2); + public void addExpectedCreateArgumentMatcherValues(Constraint[] arg0, Callable arg1){ + myCreateArgumentMatcherParameter0Values.addExpectedMany(arg0); + myCreateArgumentMatcherParameter1Values.addExpected(arg1); } - public Callable createArgumentMatcher(String arg0, Constraint[] arg1, Callable arg2){ + public Callable createArgumentMatcher(Constraint[] arg0, Callable arg1){ myCreateArgumentMatcherCalls.inc(); - myCreateArgumentMatcherParameter0Values.addActual(arg0); - myCreateArgumentMatcherParameter1Values.addActualMany(arg1); - myCreateArgumentMatcherParameter2Values.addActual(arg2); + myCreateArgumentMatcherParameter0Values.addActualMany(arg0); + myCreateArgumentMatcherParameter1Values.addActual(arg1); Object nextReturnValue = myActualCreateArgumentMatcherReturnValues.getNext(); if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException) throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException(); @@ -220,7 +220,6 @@ myCreateArgumentMatcherCalls.verify(); myCreateArgumentMatcherParameter0Values.verify(); myCreateArgumentMatcherParameter1Values.verify(); - myCreateArgumentMatcherParameter2Values.verify(); myCreateNameMatcherCalls.verify(); myCreateNameMatcherParameter0Values.verify(); myCreateNameMatcherParameter1Values.verify(); Index: MockCompositeCallable.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/MockCompositeCallable.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- MockCompositeCallable.java 21 Jun 2003 14:01:07 -0000 1.1.2.1 +++ MockCompositeCallable.java 27 Jun 2003 16:03:20 -0000 1.1.2.2 @@ -1,10 +1,6 @@ package test.mockobjects.dynamic; -import com.mockobjects.ExceptionalReturnValue; -import com.mockobjects.ExpectationCounter; -import com.mockobjects.ExpectationList; -import com.mockobjects.VoidReturnValues; -import com.mockobjects.ReturnValues; +import com.mockobjects.*; import com.mockobjects.dynamic.Callable; import com.mockobjects.dynamic.CompositeCallable; Index: DefaultReturnStubTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/DefaultReturnStubTest.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- DefaultReturnStubTest.java 26 Jun 2003 17:33:12 -0000 1.1.2.1 +++ DefaultReturnStubTest.java 27 Jun 2003 16:03:20 -0000 1.1.2.2 @@ -2,12 +2,12 @@ */ package test.mockobjects.dynamic; +import junit.framework.AssertionFailedError; +import junit.framework.TestCase; + import com.mockobjects.dynamic.ActiveCall; import com.mockobjects.dynamic.DefaultReturnStub; import com.mockobjects.util.AssertMo; - -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; public class DefaultReturnStubTest extends TestCase Index: MockTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockTest.java,v retrieving revision 1.12.2.1 retrieving revision 1.12.2.2 diff -u -r1.12.2.1 -r1.12.2.2 --- MockTest.java 21 Jun 2003 14:01:07 -0000 1.12.2.1 +++ MockTest.java 27 Jun 2003 16:03:20 -0000 1.12.2.2 @@ -140,8 +140,12 @@ public void testProxyInEquality() throws Exception { boolean IGNORED_RESULT = true; Stub ret = new ReturnStub(new Boolean(IGNORED_RESULT)); + ArgumentMatcher args = new ArgumentMatcher(C.anyArgs(1),ret); + NameMatcher name = new NameMatcher("call",args); + mockCallFactory.setupCreateReturnStub(ret); - mockCallFactory.setupCreateArgumentMatcher(new ArgumentMatcher("call",C.anyArgs(1),ret)); + mockCallFactory.setupCreateArgumentMatcher(args); + mockCallFactory.setupCreateNameMatcher(name); mockCompositeCallable.setupCallReturn(new Boolean(false)); mock.matchAndReturn("call", C.anyArgs(1), IGNORED_RESULT); Index: ArgumentMatcherTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/ArgumentMatcherTest.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- ArgumentMatcherTest.java 21 Jun 2003 14:01:07 -0000 1.1.2.1 +++ ArgumentMatcherTest.java 27 Jun 2003 16:03:20 -0000 1.1.2.2 @@ -8,6 +8,7 @@ import com.mockobjects.constraint.Constraint; import com.mockobjects.dynamic.ActiveCall; import com.mockobjects.dynamic.ArgumentMatcher; +import com.mockobjects.util.AssertMo; public class ArgumentMatcherTest @@ -31,16 +32,19 @@ mockCallable.setupMatchesReturn(true); } - public void testDoesNotMatchDifferentName() + public void testIgnoresMethodNames() throws Throwable { - final ActiveCall call = new ActiveCall( - "otherName", new Class[0], void.class, null ); - + final ActiveCall call1 = new ActiveCall( + "name1", new Class[0], void.class, null ); + final ActiveCall call2 = new ActiveCall( + "name2", new Class[0], void.class, null ); + ArgumentMatcher callSignature = - new ArgumentMatcher( METHOD_NAME, new Constraint[0], mockCallable ); + new ArgumentMatcher( new Constraint[0], mockCallable ); - assertFalse( "call should not match", callSignature.matches(call) ); + assertTrue( "call1 should match", callSignature.matches(call1) ); + assertTrue( "call2 should match", callSignature.matches(call2) ); mockCallable.verifyExpectations(); } @@ -55,7 +59,7 @@ }; ArgumentMatcher callSignature = - new ArgumentMatcher( METHOD_NAME, constraints, mockCallable ); + new ArgumentMatcher( constraints, mockCallable ); assertFalse( "should not match if too many arguments", callSignature.matches(call) ); @@ -73,13 +77,13 @@ }; ArgumentMatcher callSignature = - new ArgumentMatcher( METHOD_NAME, constraints, mockCallable ); + new ArgumentMatcher( constraints, mockCallable ); assertFalse( "should not match if too few arguments", callSignature.matches(call) ); } - public void testDoesNotMatchWhenConstraintIsViolated() + public void testDoesNotMatchAndDoesNotDelegateWhenConstraintFails() throws Throwable { String[] args = { "argA", "argB", "argC" }; @@ -93,7 +97,7 @@ }; ArgumentMatcher callSignature = - new ArgumentMatcher( METHOD_NAME, constraints, mockCallable ); + new ArgumentMatcher( constraints, mockCallable ); assertFalse( "should not match if constraint is violated", callSignature.matches(call) ); @@ -109,7 +113,7 @@ Constraint[] constraints = new MockConstraint[0]; ArgumentMatcher callSignature = - new ArgumentMatcher( METHOD_NAME, constraints, mockCallable ); + new ArgumentMatcher( constraints, mockCallable ); assertFalse( "should not match", callSignature.matches(call) ); @@ -124,7 +128,7 @@ Constraint[] constraints = new MockConstraint[0]; ArgumentMatcher callSignature = - new ArgumentMatcher( METHOD_NAME, constraints, mockCallable ); + new ArgumentMatcher( constraints, mockCallable ); assertTrue( "should match", callSignature.matches(call) ); @@ -149,7 +153,7 @@ }; ArgumentMatcher callSignature = - new ArgumentMatcher( METHOD_NAME, constraints, mockCallable ); + new ArgumentMatcher( constraints, mockCallable ); assertTrue( "should match", callSignature.matches(call) ); @@ -159,9 +163,7 @@ constraintC.verify(); } - public void testChecksThatDelegateMatchesWhenConstraintsMatch() - throws Throwable - { + public void testChecksThatDelegateMatchesWhenConstraintsMatch() { String[] args = { "argA", "argB", "argC" }; ActiveCall call = new ActiveCall( METHOD_NAME, new Class[]{ String.class, String.class, String.class }, @@ -181,10 +183,34 @@ mockCallable.setupMatchesReturn(false); ArgumentMatcher callSignature = - new ArgumentMatcher( METHOD_NAME, constraints, mockCallable ); + new ArgumentMatcher( constraints, mockCallable ); assertFalse( "should not match", callSignature.matches(call) ); mockCallable.verifyExpectations(); + } + + public void testDescriptionContainsAllConstraints() { + MockConstraint constraintA = + new MockConstraint("constraintA", "argA", true); + MockConstraint constraintB = + new MockConstraint("constraintB", "argB", true); + Constraint[] constraints = { constraintA, constraintB }; + + ArgumentMatcher matcher = + new ArgumentMatcher( constraints, mockCallable ); + + String description = matcher.getDescription(); + + assertTrue( "description should start with open parenthesis", + description.startsWith("(") ); + AssertMo.assertIncludes( + "description should contain constraintA description", + constraintA.toString(), description ); + AssertMo.assertIncludes( + "description should contain constraintB description", + constraintB.toString(), description ); + assertTrue( "description should end with close parenthesis", + description.endsWith(")") ); } } |
From: Steve F. <sm...@us...> - 2003-06-27 16:03:06
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv8236/src/core/com/mockobjects/dynamic Modified Files: Tag: Nat_reworks_dynamics_from_0_09 BaseCallCollectionBuilder.java CallSequence.java DefaultCallFactory.java CallSelection.java DynamicUtil.java NameMatcher.java DefaultReturnStub.java ArgumentMatcher.java CallFactory.java CallCollectionBuilder.java Log Message: Further changes from Nat Index: BaseCallCollectionBuilder.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Attic/BaseCallCollectionBuilder.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- BaseCallCollectionBuilder.java 26 Jun 2003 17:32:48 -0000 1.1.2.2 +++ BaseCallCollectionBuilder.java 27 Jun 2003 16:03:02 -0000 1.1.2.3 @@ -50,9 +50,10 @@ } public void expect( String methodName, Constraint[] args, Callable stub ) { - addCallable( - callFactory.createCallOnceExpectation( - callFactory.createArgumentMatcher( methodName, args, stub ))); + addCallable( callFactory.createCallOnceExpectation( + callFactory.createNameMatcher( methodName, + callFactory.createArgumentMatcher( args, + stub )))); } public void expectVoid( String methodName, Constraint[] args ) { @@ -113,9 +114,9 @@ } public void match( String methodName, Constraint[] args, Callable stub ) { - composite.addCallable( - callFactory.createArgumentMatcher( methodName, args, - stub ) ); + composite.addCallable( callFactory.createNameMatcher( methodName, + callFactory.createArgumentMatcher( args, + stub ))); } public void matchAndReturn(String methodName, Constraint[] args, Object result) { @@ -153,6 +154,10 @@ public void matchName( String methodName, Callable stub ) { composite.addCallable( callFactory.createNameMatcher( methodName, stub ) ); + } + + public void matchNameVoid( String methodName ) { + matchName( methodName, new VoidStub() ); } public void matchNameAndReturn(String methodName, Object result ) { Index: CallSequence.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallSequence.java,v retrieving revision 1.6.2.1 retrieving revision 1.6.2.2 diff -u -r1.6.2.1 -r1.6.2.2 --- CallSequence.java 21 Jun 2003 14:01:07 -0000 1.6.2.1 +++ CallSequence.java 27 Jun 2003 16:03:02 -0000 1.6.2.2 @@ -38,7 +38,7 @@ public String getDescription() { if (expectedCalls.isEmpty()) { - return "no methods"; + return "no method calls"; } else { StringBuffer buf = new StringBuffer(); Index: DefaultCallFactory.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/DefaultCallFactory.java,v retrieving revision 1.5.2.2 retrieving revision 1.5.2.3 diff -u -r1.5.2.2 -r1.5.2.3 --- DefaultCallFactory.java 26 Jun 2003 17:32:48 -0000 1.5.2.2 +++ DefaultCallFactory.java 27 Jun 2003 16:03:02 -0000 1.5.2.3 @@ -16,30 +16,29 @@ return new CallOnceExpectation(call); } - public Callable createArgumentMatcher( String methodName, - Constraint[] constraints, - Callable call ) - { - return new ArgumentMatcher( methodName, constraints, call ); + public Callable createArgumentMatcher( Constraint[] constraints, + Callable call ) + { + return new ArgumentMatcher( constraints, call ); } - public Callable createNameMatcher(String methodName, Callable call) { - return new NameMatcher( methodName, call ); - } + public Callable createNameMatcher(String methodName, Callable call) { + return new NameMatcher( methodName, call ); + } public Callable createVoidStub() { return new VoidStub(); } - public CompositeCallable createCallSelection() { - return new CallSelection(); - } + public CompositeCallable createCallSelection() { + return new CallSelection(); + } - public CompositeCallable createCallSequence() { - return new CallSequence(); - } + public CompositeCallable createCallSequence() { + return new CallSequence(); + } - public CallCollectionBuilder createCallCollectionBuilder(CompositeCallable collection) { - return new CallCollectionBuilder( this, collection ); - } + public CallCollectionBuilder createCallCollectionBuilder(CompositeCallable collection) { + return new CallCollectionBuilder( this, collection ); + } } Index: CallSelection.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Attic/CallSelection.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- CallSelection.java 21 Jun 2003 14:01:07 -0000 1.1.2.1 +++ CallSelection.java 27 Jun 2003 16:03:02 -0000 1.1.2.2 @@ -49,7 +49,7 @@ public String getDescription() { if (calls.isEmpty()) { - return "no methods"; + return "no method calls"; } else { StringBuffer buf = new StringBuffer(); Index: DynamicUtil.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/DynamicUtil.java,v retrieving revision 1.2.2.1 retrieving revision 1.2.2.2 diff -u -r1.2.2.1 -r1.2.2.2 --- DynamicUtil.java 21 Jun 2003 14:01:07 -0000 1.2.2.1 +++ DynamicUtil.java 27 Jun 2003 16:03:02 -0000 1.2.2.2 @@ -7,7 +7,7 @@ import java.lang.reflect.Proxy; import java.util.ArrayList; import java.util.List; - + public class DynamicUtil { public static Object[] asObjectArray(Object primitiveArray) { @@ -96,16 +96,19 @@ } public static String methodToString(String name, Object[] args) { - StringBuffer buf = new StringBuffer(); - - buf.append(name); - buf.append("("); - join(args,buf); - buf.append(")"); - - return buf.toString(); + return name + argumentsToString(args); } + public static String argumentsToString( Object[] args ) { + StringBuffer buf = new StringBuffer(); + + buf.append("("); + join(args,buf); + buf.append(")"); + + return buf.toString(); + } + public static void join(Object[] elements, StringBuffer buf) { for (int i = 0; i < elements.length; i++) { if (i > 0) { Index: NameMatcher.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Attic/NameMatcher.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- NameMatcher.java 21 Jun 2003 14:01:07 -0000 1.1.2.1 +++ NameMatcher.java 27 Jun 2003 16:03:02 -0000 1.1.2.2 @@ -20,7 +20,7 @@ } public String getDescription() { - return getMethodName(); + return getMethodName() + super.getDescription(); } public String getMethodName() { Index: DefaultReturnStub.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Attic/DefaultReturnStub.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- DefaultReturnStub.java 26 Jun 2003 17:32:48 -0000 1.1.2.1 +++ DefaultReturnStub.java 27 Jun 2003 16:03:02 -0000 1.1.2.2 @@ -2,7 +2,9 @@ */ package com.mockobjects.dynamic; -import java.util.*; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; import junit.framework.AssertionFailedError; Index: ArgumentMatcher.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Attic/ArgumentMatcher.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- ArgumentMatcher.java 21 Jun 2003 14:01:07 -0000 1.1.2.1 +++ ArgumentMatcher.java 27 Jun 2003 16:03:02 -0000 1.1.2.2 @@ -6,34 +6,30 @@ public class ArgumentMatcher - extends NameMatcher + extends CallDecorator { private Constraint[] constraints; - public ArgumentMatcher( String methodName, - Constraint[] constraints, - Callable delegate ) - { - super( methodName, delegate ); + public ArgumentMatcher( Constraint[] constraints, + Callable delegate ) + { + super( delegate ); this.constraints = (Constraint[])constraints.clone(); } public boolean matches( ActiveCall call ) { - return super.matches(call) - && constraintsMatch( call.getParameterValues() ); - } - - private boolean constraintsMatch( List args ) { - if( args.size() != constraints.length ) return false; + List args = call.getParameterValues(); + + if( args.size() != constraints.length ) return false; - for( int i = 0; i < args.size(); i++) { - if( !constraints[i].eval(args.get(i)) ) return false; - } + for( int i = 0; i < args.size(); i++) { + if( !constraints[i].eval(args.get(i)) ) return false; + } - return true; - } + return super.matches(call); + } public String getDescription() { - return DynamicUtil.methodToString( getMethodName(), constraints ); + return DynamicUtil.argumentsToString( constraints ); } } Index: CallFactory.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallFactory.java,v retrieving revision 1.4.2.2 retrieving revision 1.4.2.3 diff -u -r1.4.2.2 -r1.4.2.3 --- CallFactory.java 26 Jun 2003 17:32:48 -0000 1.4.2.2 +++ CallFactory.java 27 Jun 2003 16:03:02 -0000 1.4.2.3 @@ -12,8 +12,7 @@ Callable createCallOnceExpectation( Callable call ); - Callable createArgumentMatcher( String methodName, - Constraint[] constraints, + Callable createArgumentMatcher( Constraint[] constraints, Callable call ); Callable createNameMatcher( String methodName, Index: CallCollectionBuilder.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Attic/CallCollectionBuilder.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- CallCollectionBuilder.java 26 Jun 2003 17:32:48 -0000 1.1.2.2 +++ CallCollectionBuilder.java 27 Jun 2003 16:03:02 -0000 1.1.2.3 @@ -1,6 +1,7 @@ // WARNING: DO NOT EDIT -// This file was automatically generated by the Boxer (floats like a butterfly, strings like a bee) -// Generated on Thu Jun 19 19:50:08 BST 2003 +// This file was automatically generated by the Boxer +// "Float like a butterfly, string like a bee." +// Generated on Tue Jun 24 20:47:48 BST 2003 by npryce package com.mockobjects.dynamic; @@ -13,16 +14,8 @@ super(arg0); [...1172 lines suppressed...] - public void matchNameAndReturn(java.lang.String arg0, boolean arg1) { - super.matchNameAndReturn(arg0, new Boolean(arg1)); - } - public void matchNameAndReturn(java.lang.String arg0, short arg1) { super.matchNameAndReturn(arg0, new Short(arg1)); + } + + public void matchNameAndReturn(java.lang.String arg0, long arg1) { + super.matchNameAndReturn(arg0, new Long(arg1)); + } + + public void matchNameAndReturn(java.lang.String arg0, char arg1) { + super.matchNameAndReturn(arg0, new Character(arg1)); + } + + public void matchNameAndReturn(java.lang.String arg0, byte arg1) { + super.matchNameAndReturn(arg0, new Byte(arg1)); } } |
From: Steve F. <st...@m3...> - 2003-06-27 15:11:28
|
Nice. Thanks. Paul Nasrat wrote: > On Fri, Jun 27, 2003 at 12:03:00PM +0200, Paul Nasrat wrote: > > For anyone intrested I have released a mockobject rpm, any questions > here or on jpackage-discuss (see http://www.jpackage.org). |
From: Paul N. <pa...@tr...> - 2003-06-27 10:34:24
|
On Fri, Jun 27, 2003 at 12:03:00PM +0200, Paul Nasrat wrote: For anyone intrested I have released a mockobject rpm, any questions here or on jpackage-discuss (see http://www.jpackage.org). JPackage strikes again! --------------- Name : mockobjects Relocations: (not relocateable) Version : 0.09 Vendor: JPackage Project Release : 8jpp Build Date: Thu 26 Jun 2003 05:36:55 PM CEST Install date: (not installed) Build Host: enki.eridu Group : Development/Testing Source RPM: (none) Size : 142069 License: BSD Style Packager : Paul Nasrat <pa...@tr...> URL : http://www.mockobjects.com/ Summary : Java MockObjects package Description : The Mock Objects project is a generic unit testing framework whose goal is to facilitate developing unit tests in the mock object style. The goal of this project is to provide, a core mock objects framework. This is a library of code that supports the implementation of mock objects. It is based around a set of expectation classes for values and collections. There are also various other classes to make mock objects easier to write or to use. --------------- Thu Jun 26 2003 Paul Nasrat <pa...@tr...> 0.09-8jpp - Re-jigged alt/jvm symlinks to jars rather than dirs |
From: Steve F. <sm...@us...> - 2003-06-26 17:33:31
|
Update of /cvsroot/mockobjects/mockobjects-java/src/examples/com/mockobjects/examples/random In directory sc8-pr-cvs1:/tmp/cvs-serv19482/src/examples/com/mockobjects/examples/random Added Files: Tag: Nat_reworks_dynamics_from_0_09 WeatherRandomTest.java DefaultWeatherRandom.java StubRandom.java Weather.java WeatherTest.java WeatherRandom.java Log Message: Further changes from Nat --- NEW FILE: WeatherRandomTest.java --- package com.mockobjects.examples.random; import junit.framework.TestCase; public class WeatherRandomTest extends TestCase { public WeatherRandomTest(String test) { super(test); } public void testNextIsRaining() { StubRandom random = new StubRandom(); WeatherRandom weather_random = new DefaultWeatherRandom(random); random.setNextDouble( 0.0 ); assertTrue( "is raining", weather_random.nextIsRaining() ); random.setNextDouble( DefaultWeatherRandom.CHANCE_OF_RAIN ); assertTrue( "is not raining", !weather_random.nextIsRaining() ); random.setNextDouble( 1.0 ); assertTrue( "is not raining", !weather_random.nextIsRaining() ); } public void testNextTemperature() { StubRandom random = new StubRandom(); WeatherRandom weather_random = new DefaultWeatherRandom(random); random.setNextDouble( 0.0 ); assertEquals( "should be min temperature", DefaultWeatherRandom.MIN_TEMPERATURE, weather_random.nextTemperature(), 0.0 ); random.setNextDouble( 0.5 ); assertEquals( "should be average temperature", 0.5*(DefaultWeatherRandom.MIN_TEMPERATURE + DefaultWeatherRandom.MAX_TEMPERATURE), weather_random.nextTemperature(), 0.0 ); random.setNextDouble( 1.0 ); assertEquals( "should be max temperature", DefaultWeatherRandom.MAX_TEMPERATURE, weather_random.nextTemperature(), 0.0 ); } } --- NEW FILE: DefaultWeatherRandom.java --- package com.mockobjects.examples.random; import java.util.Random; public class DefaultWeatherRandom implements WeatherRandom { static final double CHANCE_OF_RAIN = 0.2; static final double MIN_TEMPERATURE = 20; static final double MAX_TEMPERATURE = 30; static final double TEMPERATURE_RANGE = (MAX_TEMPERATURE-MIN_TEMPERATURE); private Random _rng; public DefaultWeatherRandom( Random rng ) { _rng = rng; } public boolean nextIsRaining() { return _rng.nextDouble() < CHANCE_OF_RAIN; } public double nextTemperature() { return MIN_TEMPERATURE + _rng.nextDouble() * TEMPERATURE_RANGE; } } --- NEW FILE: StubRandom.java --- package com.mockobjects.examples.random; import java.util.Random; /** Random is a class, not an interface, and so cannot be mocked using the * {@link com.mockobjects.dynamic.Mock} class. However, by creating the * domain-specific interface to random behaviour (the {@link WeatherRandom} * interface, our use of Random objects becomes so simple that our tests * don't need a mock Random class, only this trivial stub. */ public class StubRandom extends Random { private double nextDouble = 0.0; public void setNextDouble( double d ) { nextDouble = d; } public double nextDouble() { return nextDouble; } } --- NEW FILE: Weather.java --- package com.mockobjects.examples.random; import java.util.Random; public class Weather { private WeatherRandom random; private boolean isRaining = false; private double temperature = 0.0; public Weather( WeatherRandom random ) { this.random= random; } public boolean isRaining() { return isRaining; } public double getTemperature() { return temperature; } public void randomize() { temperature = random.nextTemperature(); isRaining = random.nextIsRaining(); if( isRaining ) temperature *= 0.5; } } --- NEW FILE: WeatherTest.java --- package com.mockobjects.examples.random; import com.mockobjects.dynamic.Mock; import junit.framework.TestCase; public class WeatherTest extends TestCase { public WeatherTest( String test ) { super(test); } public void testSunnyWeather() { final double TEMPERATURE = 20; Mock random = new Mock(WeatherRandom.class); random.expectAndReturn( "nextIsRaining", false ); random.expectAndReturn( "nextTemperature", TEMPERATURE ); Weather weather = new Weather( (WeatherRandom)random.proxy() ); weather.randomize(); assertTrue( "is not raining", !weather.isRaining() ); assertEquals( "temperature", TEMPERATURE, weather.getTemperature(), 0.0 ); } public void testWetWeather() { final double TEMPERATURE = 20; Mock random = new Mock(WeatherRandom.class); random.expectAndReturn( "nextIsRaining", true ); random.expectAndReturn( "nextTemperature", TEMPERATURE ); Weather weather = new Weather( (WeatherRandom)random.proxy() ); weather.randomize(); assertTrue( "is raining", weather.isRaining() ); assertEquals( "temperature", TEMPERATURE/2.0, weather.getTemperature(), 0.0 ); } } --- NEW FILE: WeatherRandom.java --- package com.mockobjects.examples.random; public interface WeatherRandom { boolean nextIsRaining(); double nextTemperature(); } |
From: Steve F. <sm...@us...> - 2003-06-26 17:33:26
|
Update of /cvsroot/mockobjects/mockobjects-java/src/examples/com/mockobjects/examples/random In directory sc8-pr-cvs1:/tmp/cvs-serv19465/src/examples/com/mockobjects/examples/random Log Message: Directory /cvsroot/mockobjects/mockobjects-java/src/examples/com/mockobjects/examples/random added to the repository --> Using per-directory sticky tag `Nat_reworks_dynamics_from_0_09' |
From: Steve F. <sm...@us...> - 2003-06-26 17:33:15
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/constraint In directory sc8-pr-cvs1:/tmp/cvs-serv19428/src/core/test/mockobjects/constraint Modified Files: Tag: Nat_reworks_dynamics_from_0_09 ConstraintsTest.java Log Message: Further changes from Nat Index: ConstraintsTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/constraint/ConstraintsTest.java,v retrieving revision 1.2.2.1 retrieving revision 1.2.2.2 diff -u -r1.2.2.1 -r1.2.2.2 --- ConstraintsTest.java 21 Jun 2003 14:01:08 -0000 1.2.2.1 +++ ConstraintsTest.java 26 Jun 2003 17:33:12 -0000 1.2.2.2 @@ -17,10 +17,12 @@ { class True implements Constraint { public boolean eval( Object o ) { return true; } + public String toString() { return "True Constraint"; } } class False implements Constraint { public boolean eval( Object o ) { return false; } + public String toString() { return "False Constraint"; } } /** Creates a new instance of Test_Predicates |
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv19428/src/core/test/mockobjects/dynamic Modified Files: Tag: Nat_reworks_dynamics_from_0_09 NameMatcherTest.java CallDecoratorTest.java MockCallFactory.java Added Files: Tag: Nat_reworks_dynamics_from_0_09 DefaultReturnStubTest.java Log Message: Further changes from Nat --- NEW FILE: DefaultReturnStubTest.java --- /** Created on Jun 22, 2003 by npryce */ package test.mockobjects.dynamic; import com.mockobjects.dynamic.ActiveCall; import com.mockobjects.dynamic.DefaultReturnStub; import com.mockobjects.util.AssertMo; import junit.framework.AssertionFailedError; import junit.framework.TestCase; public class DefaultReturnStubTest extends TestCase { static final Object[] NO_ARG_VALUES = new Object[0]; static final Class[] NO_ARG_TYPES = new Class[0]; private DefaultReturnStub stub; public DefaultReturnStubTest(String name) { super(name); } public void setUp() { stub = new DefaultReturnStub(); } public void testDescription() { AssertMo.assertIncludes( "contains expected description", "guessed result", stub.getDescription() ); } public void testIsConstructedEmpty() { assertFalse( "should not match string result type", stub.matches( resultCall(String.class) ) ); assertFalse( "should not match int result type", stub.matches( resultCall(int.class) ) ); assertFalse( "should not match Integer result type", stub.matches( resultCall(Integer.class) ) ); } public void testMatchesCallsThatHaveARegisteredReturnType() { stub.addResult( String.class, "hello" ); stub.addResult( int.class, new Integer(0) ); assertTrue( "should match string result type", stub.matches( resultCall(String.class) ) ); assertTrue( "should match int result type", stub.matches( resultCall(int.class) ) ); assertFalse( "should not match Integer result type", stub.matches( resultCall(Integer.class) ) ); } public void testReturnsRegisteredValuesForAppropriateReturnTypesFromCall() throws Throwable { stub.addResult( String.class, "hello" ); stub.addResult( int.class, new Integer(0) ); assertEquals( "expected registered value for string result type", "hello", stub.call(resultCall(String.class)) ); assertEquals( "expected registered value for int result type", new Integer(0), stub.call(resultCall(int.class)) ); } public void testRegisteredResultOverridePreviousResultsForTheSameType() throws Throwable { stub.addResult( String.class, "result1" ); stub.addResult( String.class, "result2" ); assertEquals( "expected second result", "result2", stub.call(resultCall(String.class)) ); } public void testCallWithUnregisteredReturnTypeThrowsAssertionFailedError() { try { stub.addResult( String.class, "hello" ); stub.addResult( int.class, new Integer(0) ); stub.addResult( Double.class, new Double(0.0) ); } catch( AssertionFailedError ex ) { String message = ex.getMessage(); AssertMo.assertIncludes( "message should include expected types", String.class.toString(), message ); AssertMo.assertIncludes( "message should include expected types", int.class.toString(), message ); AssertMo.assertIncludes( "message should include expected types", Double.class.toString(), message ); } } public void testCallWhenNoRegisteredReturnTypeThrowsAssertionFailedError() { try { stub.addResult( String.class, "hello" ); stub.addResult( int.class, new Integer(0) ); stub.addResult( Double.class, new Double(0.0) ); } catch( AssertionFailedError ex ) { String message = ex.getMessage(); AssertMo.assertIncludes( "message should report no registered return types", "no result types are registered", message ); } } public void testFactoryMethodCreatesAStubLoadedWithUsefulResults() throws Throwable { stub = DefaultReturnStub.createStub(); assertHasRegisteredValue( stub, byte.class, new Byte((byte)0) ); assertHasRegisteredValue( stub, short.class, new Short((short)0) ); assertHasRegisteredValue( stub, int.class, new Integer(0) ); assertHasRegisteredValue( stub, long.class, new Long(0L) ); assertHasRegisteredValue( stub, char.class, new Character('\0') ); assertHasRegisteredValue( stub, float.class, new Float(0.0F) ); assertHasRegisteredValue( stub, double.class, new Double(0.0) ); assertHasRegisteredValue( stub, Byte.class, new Byte((byte)0) ); assertHasRegisteredValue( stub, Short.class, new Short((short)0) ); assertHasRegisteredValue( stub, Integer.class, new Integer(0) ); assertHasRegisteredValue( stub, Long.class, new Long(0L) ); assertHasRegisteredValue( stub, Character.class, new Character('\0') ); assertHasRegisteredValue( stub, Float.class, new Float(0.0F) ); assertHasRegisteredValue( stub, Double.class, new Double(0.0) ); assertHasRegisteredValue( stub, String.class, "<default string result>" ); } public void assertHasRegisteredValue( DefaultReturnStub stub, Class resultType, Object resultValue ) throws Throwable { ActiveCall call = resultCall(resultType); assertTrue( "should have result registered for type " + resultType, stub.matches(call) ); assertEquals( "expected "+resultValue+" to be returned", resultValue, stub.call(call) ); } private ActiveCall resultCall( Class resultType ) { return new ActiveCall( "ignoredMethodName", NO_ARG_TYPES, resultType, NO_ARG_VALUES ); } } Index: NameMatcherTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/NameMatcherTest.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- NameMatcherTest.java 21 Jun 2003 14:01:07 -0000 1.1.2.1 +++ NameMatcherTest.java 26 Jun 2003 17:33:12 -0000 1.1.2.2 @@ -43,7 +43,7 @@ delegate.setExpectedMatches( CALL ); delegate.setupMatchesReturn(true); - callName.matches( CALL ); + boolean result = callName.matches( CALL ); delegate.verifyExpectations(); } Index: CallDecoratorTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/Attic/CallDecoratorTest.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- CallDecoratorTest.java 21 Jun 2003 14:01:07 -0000 1.1.2.1 +++ CallDecoratorTest.java 26 Jun 2003 17:33:12 -0000 1.1.2.2 @@ -91,7 +91,7 @@ mockCallable.setExpectedMatches(CALL); mockCallable.setupMatchesReturn(true); - callDecorator.matches(CALL); + boolean result = callDecorator.matches(CALL); mockCallable.verifyExpectations(); } Index: MockCallFactory.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockCallFactory.java,v retrieving revision 1.4.2.1 retrieving revision 1.4.2.2 diff -u -r1.4.2.1 -r1.4.2.2 --- MockCallFactory.java 21 Jun 2003 14:01:07 -0000 1.4.2.1 +++ MockCallFactory.java 26 Jun 2003 17:33:12 -0000 1.4.2.2 @@ -1,15 +1,12 @@ package test.mockobjects.dynamic; import mockmaker.ReturnValues; - -import com.mockobjects.ExceptionalReturnValue; -import com.mockobjects.ExpectationCounter; -import com.mockobjects.ExpectationList; -import com.mockobjects.constraint.Constraint; -import com.mockobjects.dynamic.CallCollectionBuilder; +import com.mockobjects.*; import com.mockobjects.dynamic.CallFactory; import com.mockobjects.dynamic.Callable; +import com.mockobjects.constraint.Constraint; import com.mockobjects.dynamic.CompositeCallable; +import com.mockobjects.dynamic.CallCollectionBuilder; public class MockCallFactory implements CallFactory{ private ExpectationCounter myCreateReturnStubCalls = new ExpectationCounter("com.mockobjects.dynamic.CallFactory CreateReturnStubCalls"); private ReturnValues myActualCreateReturnStubReturnValues = new ReturnValues(false); @@ -27,6 +24,10 @@ private ExpectationList myCreateArgumentMatcherParameter0Values = new ExpectationList("com.mockobjects.dynamic.CallFactory java.lang.String"); private ExpectationList myCreateArgumentMatcherParameter1Values = new ExpectationList("com.mockobjects.dynamic.CallFactory com.mockobjects.constraint.Constraint"); private ExpectationList myCreateArgumentMatcherParameter2Values = new ExpectationList("com.mockobjects.dynamic.CallFactory com.mockobjects.dynamic.Callable"); + private ExpectationCounter myCreateNameMatcherCalls = new ExpectationCounter("com.mockobjects.dynamic.CallFactory CreateNameMatcherCalls"); + private ReturnValues myActualCreateNameMatcherReturnValues = new ReturnValues(false); + private ExpectationList myCreateNameMatcherParameter0Values = new ExpectationList("com.mockobjects.dynamic.CallFactory java.lang.String"); + private ExpectationList myCreateNameMatcherParameter1Values = new ExpectationList("com.mockobjects.dynamic.CallFactory com.mockobjects.dynamic.Callable"); private ExpectationCounter myCreateCallSequenceCalls = new ExpectationCounter("com.mockobjects.dynamic.CallFactory CreateCallSequenceCalls"); private ReturnValues myActualCreateCallSequenceReturnValues = new ReturnValues(false); private ExpectationCounter myCreateCallSelectionCalls = new ExpectationCounter("com.mockobjects.dynamic.CallFactory CreateCallSelectionCalls"); @@ -34,174 +35,198 @@ private ExpectationCounter myCreateCallCollectionBuilderCalls = new ExpectationCounter("com.mockobjects.dynamic.CallFactory CreateCallCollectionBuilderCalls"); private ReturnValues myActualCreateCallCollectionBuilderReturnValues = new ReturnValues(false); private ExpectationList myCreateCallCollectionBuilderParameter0Values = new ExpectationList("com.mockobjects.dynamic.CallFactory com.mockobjects.dynamic.CompositeCallable"); - public void setExpectedCreateReturnStubCalls(int calls){ - myCreateReturnStubCalls.setExpected(calls); + myCreateReturnStubCalls.setExpected(calls); } public void addExpectedCreateReturnStubValues(Object arg0){ - myCreateReturnStubParameter0Values.addExpected(arg0); + myCreateReturnStubParameter0Values.addExpected(arg0); } public Callable createReturnStub(Object arg0){ - myCreateReturnStubCalls.inc(); - myCreateReturnStubParameter0Values.addActual(arg0); - Object nextReturnValue = myActualCreateReturnStubReturnValues.getNext(); - if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException) - throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException(); - return (Callable) nextReturnValue; + myCreateReturnStubCalls.inc(); + myCreateReturnStubParameter0Values.addActual(arg0); + Object nextReturnValue = myActualCreateReturnStubReturnValues.getNext(); + if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException) + throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException(); + return (Callable) nextReturnValue; } public void setupExceptionCreateReturnStub(Throwable arg){ - myActualCreateReturnStubReturnValues.add(new ExceptionalReturnValue(arg)); + myActualCreateReturnStubReturnValues.add(new ExceptionalReturnValue(arg)); } public void setupCreateReturnStub(Callable arg){ - myActualCreateReturnStubReturnValues.add(arg); + myActualCreateReturnStubReturnValues.add(arg); } public void setExpectedCreateThrowStubCalls(int calls){ - myCreateThrowStubCalls.setExpected(calls); + myCreateThrowStubCalls.setExpected(calls); } public void addExpectedCreateThrowStubValues(Throwable arg0){ - myCreateThrowStubParameter0Values.addExpected(arg0); + myCreateThrowStubParameter0Values.addExpected(arg0); } public Callable createThrowStub(Throwable arg0){ - myCreateThrowStubCalls.inc(); - myCreateThrowStubParameter0Values.addActual(arg0); - Object nextReturnValue = myActualCreateThrowStubReturnValues.getNext(); - if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException) - throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException(); - return (Callable) nextReturnValue; + myCreateThrowStubCalls.inc(); + myCreateThrowStubParameter0Values.addActual(arg0); + Object nextReturnValue = myActualCreateThrowStubReturnValues.getNext(); + if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException) + throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException(); + return (Callable) nextReturnValue; } public void setupExceptionCreateThrowStub(Throwable arg){ - myActualCreateThrowStubReturnValues.add(new ExceptionalReturnValue(arg)); + myActualCreateThrowStubReturnValues.add(new ExceptionalReturnValue(arg)); } public void setupCreateThrowStub(Callable arg){ - myActualCreateThrowStubReturnValues.add(arg); + myActualCreateThrowStubReturnValues.add(arg); } public void setExpectedCreateVoidStubCalls(int calls){ - myCreateVoidStubCalls.setExpected(calls); + myCreateVoidStubCalls.setExpected(calls); } public Callable createVoidStub(){ - myCreateVoidStubCalls.inc(); - Object nextReturnValue = myActualCreateVoidStubReturnValues.getNext(); - if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException) - throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException(); - return (Callable) nextReturnValue; + myCreateVoidStubCalls.inc(); + Object nextReturnValue = myActualCreateVoidStubReturnValues.getNext(); + if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException) + throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException(); + return (Callable) nextReturnValue; } public void setupExceptionCreateVoidStub(Throwable arg){ - myActualCreateVoidStubReturnValues.add(new ExceptionalReturnValue(arg)); + myActualCreateVoidStubReturnValues.add(new ExceptionalReturnValue(arg)); } public void setupCreateVoidStub(Callable arg){ - myActualCreateVoidStubReturnValues.add(arg); + myActualCreateVoidStubReturnValues.add(arg); } public void setExpectedCreateCallOnceExpectationCalls(int calls){ - myCreateCallOnceExpectationCalls.setExpected(calls); + myCreateCallOnceExpectationCalls.setExpected(calls); } public void addExpectedCreateCallOnceExpectationValues(Callable arg0){ - myCreateCallOnceExpectationParameter0Values.addExpected(arg0); + myCreateCallOnceExpectationParameter0Values.addExpected(arg0); } public Callable createCallOnceExpectation(Callable arg0){ - myCreateCallOnceExpectationCalls.inc(); - myCreateCallOnceExpectationParameter0Values.addActual(arg0); - Object nextReturnValue = myActualCreateCallOnceExpectationReturnValues.getNext(); - if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException) - throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException(); - return (Callable) nextReturnValue; + myCreateCallOnceExpectationCalls.inc(); + myCreateCallOnceExpectationParameter0Values.addActual(arg0); + Object nextReturnValue = myActualCreateCallOnceExpectationReturnValues.getNext(); + if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException) + throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException(); + return (Callable) nextReturnValue; } public void setupExceptionCreateCallOnceExpectation(Throwable arg){ - myActualCreateCallOnceExpectationReturnValues.add(new ExceptionalReturnValue(arg)); + myActualCreateCallOnceExpectationReturnValues.add(new ExceptionalReturnValue(arg)); } public void setupCreateCallOnceExpectation(Callable arg){ - myActualCreateCallOnceExpectationReturnValues.add(arg); + myActualCreateCallOnceExpectationReturnValues.add(arg); } public void setExpectedCreateArgumentMatcherCalls(int calls){ - myCreateArgumentMatcherCalls.setExpected(calls); + myCreateArgumentMatcherCalls.setExpected(calls); } public void addExpectedCreateArgumentMatcherValues(String arg0, Constraint[] arg1, Callable arg2){ - myCreateArgumentMatcherParameter0Values.addExpected(arg0); - myCreateArgumentMatcherParameter1Values.addExpectedMany(arg1); - myCreateArgumentMatcherParameter2Values.addExpected(arg2); + myCreateArgumentMatcherParameter0Values.addExpected(arg0); + myCreateArgumentMatcherParameter1Values.addExpectedMany(arg1); + myCreateArgumentMatcherParameter2Values.addExpected(arg2); } public Callable createArgumentMatcher(String arg0, Constraint[] arg1, Callable arg2){ - myCreateArgumentMatcherCalls.inc(); - myCreateArgumentMatcherParameter0Values.addActual(arg0); - myCreateArgumentMatcherParameter1Values.addActualMany(arg1); - myCreateArgumentMatcherParameter2Values.addActual(arg2); - Object nextReturnValue = myActualCreateArgumentMatcherReturnValues.getNext(); - if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException) - throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException(); - return (Callable) nextReturnValue; + myCreateArgumentMatcherCalls.inc(); + myCreateArgumentMatcherParameter0Values.addActual(arg0); + myCreateArgumentMatcherParameter1Values.addActualMany(arg1); + myCreateArgumentMatcherParameter2Values.addActual(arg2); + Object nextReturnValue = myActualCreateArgumentMatcherReturnValues.getNext(); + if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException) + throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException(); + return (Callable) nextReturnValue; } public void setupExceptionCreateArgumentMatcher(Throwable arg){ - myActualCreateArgumentMatcherReturnValues.add(new ExceptionalReturnValue(arg)); + myActualCreateArgumentMatcherReturnValues.add(new ExceptionalReturnValue(arg)); } public void setupCreateArgumentMatcher(Callable arg){ - myActualCreateArgumentMatcherReturnValues.add(arg); + myActualCreateArgumentMatcherReturnValues.add(arg); + } + public void setExpectedCreateNameMatcherCalls(int calls){ + myCreateNameMatcherCalls.setExpected(calls); + } + public void addExpectedCreateNameMatcherValues(String arg0, Callable arg1){ + myCreateNameMatcherParameter0Values.addExpected(arg0); + myCreateNameMatcherParameter1Values.addExpected(arg1); + } + public Callable createNameMatcher(String arg0, Callable arg1){ + myCreateNameMatcherCalls.inc(); + myCreateNameMatcherParameter0Values.addActual(arg0); + myCreateNameMatcherParameter1Values.addActual(arg1); + Object nextReturnValue = myActualCreateNameMatcherReturnValues.getNext(); + if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException) + throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException(); + return (Callable) nextReturnValue; + } + public void setupExceptionCreateNameMatcher(Throwable arg){ + myActualCreateNameMatcherReturnValues.add(new ExceptionalReturnValue(arg)); + } + public void setupCreateNameMatcher(Callable arg){ + myActualCreateNameMatcherReturnValues.add(arg); } public void setExpectedCreateCallSequenceCalls(int calls){ - myCreateCallSequenceCalls.setExpected(calls); + myCreateCallSequenceCalls.setExpected(calls); } public CompositeCallable createCallSequence(){ - myCreateCallSequenceCalls.inc(); - Object nextReturnValue = myActualCreateCallSequenceReturnValues.getNext(); - if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException) - throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException(); - return (CompositeCallable) nextReturnValue; + myCreateCallSequenceCalls.inc(); + Object nextReturnValue = myActualCreateCallSequenceReturnValues.getNext(); + if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException) + throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException(); + return (CompositeCallable) nextReturnValue; } public void setupExceptionCreateCallSequence(Throwable arg){ - myActualCreateCallSequenceReturnValues.add(new ExceptionalReturnValue(arg)); + myActualCreateCallSequenceReturnValues.add(new ExceptionalReturnValue(arg)); } public void setupCreateCallSequence(CompositeCallable arg){ - myActualCreateCallSequenceReturnValues.add(arg); + myActualCreateCallSequenceReturnValues.add(arg); } public void setExpectedCreateCallSelectionCalls(int calls){ - myCreateCallSelectionCalls.setExpected(calls); + myCreateCallSelectionCalls.setExpected(calls); } public CompositeCallable createCallSelection(){ - myCreateCallSelectionCalls.inc(); - Object nextReturnValue = myActualCreateCallSelectionReturnValues.getNext(); - if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException) - throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException(); - return (CompositeCallable) nextReturnValue; + myCreateCallSelectionCalls.inc(); + Object nextReturnValue = myActualCreateCallSelectionReturnValues.getNext(); + if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException) + throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException(); + return (CompositeCallable) nextReturnValue; } public void setupExceptionCreateCallSelection(Throwable arg){ - myActualCreateCallSelectionReturnValues.add(new ExceptionalReturnValue(arg)); + myActualCreateCallSelectionReturnValues.add(new ExceptionalReturnValue(arg)); } public void setupCreateCallSelection(CompositeCallable arg){ - myActualCreateCallSelectionReturnValues.add(arg); + myActualCreateCallSelectionReturnValues.add(arg); } public void setExpectedCreateCallCollectionBuilderCalls(int calls){ - myCreateCallCollectionBuilderCalls.setExpected(calls); + myCreateCallCollectionBuilderCalls.setExpected(calls); } public void addExpectedCreateCallCollectionBuilderValues(CompositeCallable arg0){ - myCreateCallCollectionBuilderParameter0Values.addExpected(arg0); + myCreateCallCollectionBuilderParameter0Values.addExpected(arg0); } public CallCollectionBuilder createCallCollectionBuilder(CompositeCallable arg0){ - myCreateCallCollectionBuilderCalls.inc(); - myCreateCallCollectionBuilderParameter0Values.addActual(arg0); - Object nextReturnValue = myActualCreateCallCollectionBuilderReturnValues.getNext(); - if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException) - throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException(); - return (CallCollectionBuilder) nextReturnValue; + myCreateCallCollectionBuilderCalls.inc(); + myCreateCallCollectionBuilderParameter0Values.addActual(arg0); + Object nextReturnValue = myActualCreateCallCollectionBuilderReturnValues.getNext(); + if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException) + throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException(); + return (CallCollectionBuilder) nextReturnValue; } public void setupExceptionCreateCallCollectionBuilder(Throwable arg){ - myActualCreateCallCollectionBuilderReturnValues.add(new ExceptionalReturnValue(arg)); + myActualCreateCallCollectionBuilderReturnValues.add(new ExceptionalReturnValue(arg)); } public void setupCreateCallCollectionBuilder(CallCollectionBuilder arg){ - myActualCreateCallCollectionBuilderReturnValues.add(arg); + myActualCreateCallCollectionBuilderReturnValues.add(arg); } public void verify(){ - myCreateReturnStubCalls.verify(); - myCreateReturnStubParameter0Values.verify(); - myCreateThrowStubCalls.verify(); - myCreateThrowStubParameter0Values.verify(); - myCreateVoidStubCalls.verify(); - myCreateCallOnceExpectationCalls.verify(); - myCreateCallOnceExpectationParameter0Values.verify(); - myCreateArgumentMatcherCalls.verify(); - myCreateArgumentMatcherParameter0Values.verify(); - myCreateArgumentMatcherParameter1Values.verify(); - myCreateArgumentMatcherParameter2Values.verify(); - myCreateCallSequenceCalls.verify(); - myCreateCallSelectionCalls.verify(); - myCreateCallCollectionBuilderCalls.verify(); - myCreateCallCollectionBuilderParameter0Values.verify(); + myCreateReturnStubCalls.verify(); + myCreateReturnStubParameter0Values.verify(); + myCreateThrowStubCalls.verify(); + myCreateThrowStubParameter0Values.verify(); + myCreateVoidStubCalls.verify(); + myCreateCallOnceExpectationCalls.verify(); + myCreateCallOnceExpectationParameter0Values.verify(); + myCreateArgumentMatcherCalls.verify(); + myCreateArgumentMatcherParameter0Values.verify(); + myCreateArgumentMatcherParameter1Values.verify(); + myCreateArgumentMatcherParameter2Values.verify(); + myCreateNameMatcherCalls.verify(); + myCreateNameMatcherParameter0Values.verify(); + myCreateNameMatcherParameter1Values.verify(); + myCreateCallSequenceCalls.verify(); + myCreateCallSelectionCalls.verify(); + myCreateCallCollectionBuilderCalls.verify(); + myCreateCallCollectionBuilderParameter0Values.verify(); } } |
From: Steve F. <sm...@us...> - 2003-06-26 17:32:53
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv19337/src/core/com/mockobjects/dynamic Modified Files: Tag: Nat_reworks_dynamics_from_0_09 BaseCallCollectionBuilder.java DefaultCallFactory.java CallOnceExpectation.java CallFactory.java CallCollectionBuilder.java Added Files: Tag: Nat_reworks_dynamics_from_0_09 DefaultReturnStub.java Log Message: Further changes from Nat --- NEW FILE: DefaultReturnStub.java --- /** Created on Jun 22, 2003 by npryce */ package com.mockobjects.dynamic; import java.util.*; import junit.framework.AssertionFailedError; public class DefaultReturnStub extends Stub { private Map resultValuesByType = new HashMap(); public DefaultReturnStub() { } public String getDescription() { return "a guessed result"; } public void addResult( Class resultType, Object resultValue ) { resultValuesByType.put( resultType, resultValue ); } public boolean matches( ActiveCall call ) { return resultValuesByType.containsKey( call.getReturnType() ); } public Object call( ActiveCall call ) throws Throwable { if( resultValuesByType.containsKey(call.getReturnType()) ) { return resultValuesByType.get(call.getReturnType()); } else { throw new AssertionFailedError( createErrorMessage(call) ); } } public String createErrorMessage(ActiveCall call) { StringBuffer buf = new StringBuffer(); buf.append("unexpected result type: "); buf.append(call.getReturnType().toString()); buf.append("\n"); if( resultValuesByType.isEmpty() ) { buf.append("no result types are registered!"); } else { buf.append("expected one of: "); Iterator i = resultValuesByType.keySet().iterator(); buf.append( i.next().toString() ); while( i.hasNext() ) { buf.append(", "); buf.append( i.next().toString() ); } } return buf.toString(); } public static DefaultReturnStub createStub() { DefaultReturnStub stub = new DefaultReturnStub(); stub.addResult( byte.class, new Byte((byte)0) ); stub.addResult( short.class, new Short((short)0) ); stub.addResult( int.class, new Integer(0) ); stub.addResult( long.class, new Long(0L) ); stub.addResult( char.class, new Character('\0') ); stub.addResult( float.class, new Float(0.0F) ); stub.addResult( double.class, new Double(0.0) ); stub.addResult( Byte.class, new Byte((byte)0) ); stub.addResult( Short.class, new Short((short)0) ); stub.addResult( Integer.class, new Integer(0) ); stub.addResult( Long.class, new Long(0L) ); stub.addResult( Character.class, new Character('\0') ); stub.addResult( Float.class, new Float(0.0F) ); stub.addResult( Double.class, new Double(0.0) ); stub.addResult( String.class, "<default string result>" ); return stub; } } Index: BaseCallCollectionBuilder.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Attic/BaseCallCollectionBuilder.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- BaseCallCollectionBuilder.java 21 Jun 2003 14:01:07 -0000 1.1.2.1 +++ BaseCallCollectionBuilder.java 26 Jun 2003 17:32:48 -0000 1.1.2.2 @@ -7,10 +7,10 @@ /** The BaseCallCollectionBuilder class acts as a template for the * {@link CallCollectionBuilder class}. All parameters of type * Object of methods in this class are overloaded for primitive types - * in the CallCollectionBuilder class. + * in the CallCollectionBuilder class [the Generation Gap pattern]. */ public abstract class BaseCallCollectionBuilder - implements CompositeCallable, Verifiable + implements CompositeCallable, Verifiable { private CallFactory callFactory; private CompositeCallable composite; @@ -21,44 +21,43 @@ this.composite = composite; } - public BaseCallCollectionBuilder( CompositeCallable composite ) { - this( new DefaultCallFactory(), composite ); - } - - public void addCallable( Callable callable ) { - composite.addCallable( callable ); - } - - public String getDescription() { - return composite.getDescription(); - } - - public Object call( ActiveCall call ) throws Throwable { - return composite.call( call ); - } - - public boolean matches( ActiveCall call ) { - return composite.matches( call ); - } - - public void reset() { - this.composite.reset(); - } + public BaseCallCollectionBuilder( CompositeCallable composite ) { + this( new DefaultCallFactory(), composite ); + } + + public void addCallable( Callable callable ) { + composite.addCallable( callable ); + } + + public String getDescription() { + return composite.getDescription(); + } + + public Object call( ActiveCall call ) throws Throwable { + return composite.call( call ); + } + + public boolean matches( ActiveCall call ) { + return composite.matches( call ); + } + + public void reset() { + this.composite.reset(); + } public void verify() { - composite.verify(); + composite.verify(); } - public void expect( String methodName, Constraint[] args, Callable stub ) { - addCallable( - callFactory.createCallOnceExpectation( - callFactory.createArgumentMatcher( methodName, args, - stub ))); - } - - public void expectVoid( String methodName, Constraint[] args ) { - expect( methodName, args, callFactory.createVoidStub() ); - } + public void expect( String methodName, Constraint[] args, Callable stub ) { + addCallable( + callFactory.createCallOnceExpectation( + callFactory.createArgumentMatcher( methodName, args, stub ))); + } + + public void expectVoid( String methodName, Constraint[] args ) { + expect( methodName, args, callFactory.createVoidStub() ); + } public void expectVoid( String methodName ) { expectVoid( methodName, C.NO_ARGS ); @@ -68,13 +67,13 @@ expectVoid( methodName, C.args(C.eq(singleEqualArg)) ); } - public void expectVoid(String methodName, Constraint singleConstraint ) { - expectVoid( methodName, new Constraint[]{ singleConstraint } ); - } - - public void expectAndReturn( String methodName, Constraint[] args, Object result) { - expect( methodName, args, callFactory.createReturnStub(result) ); - } + public void expectVoid(String methodName, Constraint singleConstraint ) { + expectVoid( methodName, new Constraint[]{ singleConstraint } ); + } + + public void expectAndReturn( String methodName, Constraint[] args, Object result) { + expect( methodName, args, callFactory.createReturnStub(result) ); + } public void expectAndReturn(String methodName, Object result ) { this.expectAndReturn(methodName, C.NO_ARGS, result); @@ -84,64 +83,64 @@ this.expectAndReturn(methodName, C.args(C.eq(singleEqualArg)), result); } - public void expectAndReturn(String methodName, Constraint singleConstraint, Object result) { - this.expectAndReturn( methodName, new Constraint[]{singleConstraint}, - result); - } - - public void expectAndThrow(String methodName, Constraint[] args, Throwable exception) { - expect( methodName, args, callFactory.createThrowStub(exception) ); - } + public void expectAndReturn(String methodName, Constraint singleConstraint, Object result) { + this.expectAndReturn( methodName, new Constraint[]{singleConstraint}, + result); + } + + public void expectAndThrow(String methodName, Constraint[] args, Throwable exception) { + expect( methodName, args, callFactory.createThrowStub(exception) ); + } public void expectAndThrow( String methodName, Throwable exception ) { expectAndThrow(methodName, C.NO_ARGS, exception); } public void expectAndThrow( String methodName, - Object singleEqualArg, - Throwable exception ) - { + Object singleEqualArg, + Throwable exception ) + { expectAndThrow( methodName, C.args(C.eq(singleEqualArg)), exception ); } - public void expectAndThrow( String methodName, - Constraint singleConstraint, - Throwable exception ) - { - this.expectAndThrow( methodName, - new Constraint[]{ singleConstraint }, - exception ); - } - - public void match( String methodName, Constraint[] args, Callable stub ) { - composite.addCallable( - callFactory.createArgumentMatcher( methodName, args, - stub ) ); - } - - public void matchAndReturn(String methodName, Constraint[] args, Object result) { - match( methodName, args, callFactory.createReturnStub(result)); - } + public void expectAndThrow( String methodName, + Constraint singleConstraint, + Throwable exception ) + { + this.expectAndThrow( methodName, + new Constraint[]{ singleConstraint }, + exception ); + } + + public void match( String methodName, Constraint[] args, Callable stub ) { + composite.addCallable( + callFactory.createArgumentMatcher( methodName, args, + stub ) ); + } + + public void matchAndReturn(String methodName, Constraint[] args, Object result) { + match( methodName, args, callFactory.createReturnStub(result)); + } public void matchAndReturn(String methodName, Object result) { matchAndReturn( methodName, C.NO_ARGS, result ); } - public void matchAndReturn( String methodName, - Constraint singleConstraint, - Object result ) - { - matchAndReturn( methodName, new Constraint[]{singleConstraint}, - result); - } + public void matchAndReturn( String methodName, + Constraint singleConstraint, + Object result ) + { + matchAndReturn( methodName, new Constraint[]{singleConstraint}, + result); + } public void matchAndReturn(String methodName, Object singleEqualArg, Object result) { this.matchAndReturn(methodName, C.args(C.eq(singleEqualArg)), result); } - public void matchAndThrow(String methodName, Constraint[] args, Throwable throwable) { - match( methodName, args, callFactory.createThrowStub(throwable) ); - } + public void matchAndThrow(String methodName, Constraint[] args, Throwable throwable) { + match( methodName, args, callFactory.createThrowStub(throwable) ); + } public void matchAndThrow(String methodName, Throwable throwable) { this.matchAndThrow(methodName, C.NO_ARGS, throwable); @@ -150,18 +149,31 @@ public void matchAndThrow(String methodName, Object singleEqualArg, Throwable throwable) { this.matchAndThrow(methodName, C.args(C.eq(singleEqualArg)), throwable); } - - public CallCollectionBuilder newCallSelection() { - return addCallCollection( callFactory.createCallSelection() ); - } + + public void matchName( String methodName, Callable stub ) { + composite.addCallable( + callFactory.createNameMatcher( methodName, stub ) ); + } + + public void matchNameAndReturn(String methodName, Object result ) { + matchName( methodName, callFactory.createReturnStub(result) ); + } + + public void matchNameAndThrow(String methodName, Throwable throwable) { + matchName( methodName, callFactory.createThrowStub(throwable) ); + } + + public CallCollectionBuilder newCallSelection() { + return addCallCollection( callFactory.createCallSelection() ); + } - public CallCollectionBuilder newCallSequence() { - return addCallCollection( callFactory.createCallSequence() ); - } + public CallCollectionBuilder newCallSequence() { + return addCallCollection( callFactory.createCallSequence() ); + } - private CallCollectionBuilder addCallCollection( CompositeCallable collection ) { - composite.addCallable(collection); - return callFactory.createCallCollectionBuilder( collection ); - } + private CallCollectionBuilder addCallCollection( CompositeCallable collection ) { + composite.addCallable(collection); + return callFactory.createCallCollectionBuilder( collection ); + } } Index: DefaultCallFactory.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/DefaultCallFactory.java,v retrieving revision 1.5.2.1 retrieving revision 1.5.2.2 diff -u -r1.5.2.1 -r1.5.2.2 --- DefaultCallFactory.java 21 Jun 2003 14:01:07 -0000 1.5.2.1 +++ DefaultCallFactory.java 26 Jun 2003 17:32:48 -0000 1.5.2.2 @@ -23,6 +23,10 @@ return new ArgumentMatcher( methodName, constraints, call ); } + public Callable createNameMatcher(String methodName, Callable call) { + return new NameMatcher( methodName, call ); + } + public Callable createVoidStub() { return new VoidStub(); } Index: CallOnceExpectation.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallOnceExpectation.java,v retrieving revision 1.2.2.1 retrieving revision 1.2.2.2 diff -u -r1.2.2.1 -r1.2.2.2 --- CallOnceExpectation.java 21 Jun 2003 14:01:07 -0000 1.2.2.1 +++ CallOnceExpectation.java 26 Jun 2003 17:32:48 -0000 1.2.2.2 @@ -21,7 +21,8 @@ } public boolean matches( ActiveCall call ) { - return (!wasCalled) && super.matches( call ); + return !wasCalled + && super.matches( call ); } public void verify() { Index: CallFactory.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallFactory.java,v retrieving revision 1.4.2.1 retrieving revision 1.4.2.2 diff -u -r1.4.2.1 -r1.4.2.2 --- CallFactory.java 21 Jun 2003 14:01:07 -0000 1.4.2.1 +++ CallFactory.java 26 Jun 2003 17:32:48 -0000 1.4.2.2 @@ -6,19 +6,22 @@ { Callable createReturnStub( Object result ); - Callable createThrowStub( Throwable throwable ); + Callable createThrowStub( Throwable throwable ); - Callable createVoidStub(); + Callable createVoidStub(); - Callable createCallOnceExpectation( Callable call ); + Callable createCallOnceExpectation( Callable call ); Callable createArgumentMatcher( String methodName, - Constraint[] constraints, - Callable call ); + Constraint[] constraints, + Callable call ); - CompositeCallable createCallSequence(); + Callable createNameMatcher( String methodName, + Callable call ); - CompositeCallable createCallSelection(); + CompositeCallable createCallSequence(); - CallCollectionBuilder createCallCollectionBuilder( CompositeCallable collection ); + CompositeCallable createCallSelection(); + + CallCollectionBuilder createCallCollectionBuilder( CompositeCallable collection ); } Index: CallCollectionBuilder.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Attic/CallCollectionBuilder.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- CallCollectionBuilder.java 21 Jun 2003 14:01:07 -0000 1.1.2.1 +++ CallCollectionBuilder.java 26 Jun 2003 17:32:48 -0000 1.1.2.2 @@ -1,815 +1,847 @@ // WARNING: DO NOT EDIT // This file was automatically generated by the Boxer (floats like a butterfly, strings like a bee) -// Generated on Thu Jun 19 14:37:31 BST 2003 +// Generated on Thu Jun 19 19:50:08 BST 2003 package com.mockobjects.dynamic; public class CallCollectionBuilder extends com.mockobjects.dynamic.BaseCallCollectionBuilder { - public CallCollectionBuilder(com.mockobjects.dynamic.CallFactory arg0, com.mockobjects.dynamic.CompositeCallable arg1) { - super(arg0, arg1); - } [...1624 lines suppressed...] + public void matchNameAndReturn(java.lang.String arg0, double arg1) { + super.matchNameAndReturn(arg0, new Double(arg1)); + } + + public void matchNameAndReturn(java.lang.String arg0, int arg1) { + super.matchNameAndReturn(arg0, new Integer(arg1)); + } + + public void matchNameAndReturn(java.lang.String arg0, float arg1) { + super.matchNameAndReturn(arg0, new Float(arg1)); + } + + public void matchNameAndReturn(java.lang.String arg0, boolean arg1) { + super.matchNameAndReturn(arg0, new Boolean(arg1)); + } + + public void matchNameAndReturn(java.lang.String arg0, short arg1) { + super.matchNameAndReturn(arg0, new Short(arg1)); + } } |
From: Steve F. <sm...@us...> - 2003-06-26 17:32:53
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/tools In directory sc8-pr-cvs1:/tmp/cvs-serv19337/src/core/com/mockobjects/tools Modified Files: Tag: Nat_reworks_dynamics_from_0_09 Boxer.java Log Message: Further changes from Nat Index: Boxer.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/tools/Attic/Boxer.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- Boxer.java 21 Jun 2003 14:01:08 -0000 1.1.2.1 +++ Boxer.java 26 Jun 2003 17:32:48 -0000 1.1.2.2 @@ -62,9 +62,7 @@ } static String typeSyntax( Class c ) { - if( c.isPrimitive() ) { - return c.toString(); - } else if( c.isArray() ) { + if( c.isArray() ) { return typeSyntax(c.getComponentType()) + "[]"; } else { return c.getName(); @@ -212,7 +210,17 @@ Class[] originalParameterTypes = m.getParameterTypes(); out.print(INDENT2); + + if( m.getReturnType() != void.class ) { + out.print( "return " ); + } + + if( Modifier.isStatic(m.getModifiers()) ) { + out.print( m.getDeclaringClass().getName() ); + out.print("."); + } else { out.print("super."); + } out.print(m.getName()); out.print("("); @@ -240,6 +248,9 @@ { out.print(INDENT1); out.print("public "); + if( Modifier.isStatic(m.getModifiers()) ) { + out.print("static "); + } out.print(m.getReturnType()); out.print(" "); out.print(m.getName()); |
From: Jeff M. <je...@cu...> - 2003-06-25 09:36:11
|
Return update counts are help in a ReturnObjectBag which is a ReturnObjectList held against the key value. This means you are building up a list of return values rather than just a single one. The only Exceptions that should be thrown out of the Mocks are assertion failures and test exceptions, anything else is a bug. But if you can't recreate the problem there's not much we can do about it :( On Tue, 2003-06-24 at 23:02, Pat McGee wrote: > Informal writeup at > http://blackbox.cs.fit.edu/blog/pat/archives/000084.html. > > If someone looks at this and sees what the problem is, I'd sure be > interested in finding out. > > Thanks, > > Pat > > --- > Pat McGee > Ph.D. Student, Computer Sciences Department, Florida Institute of > Technology > jp...@cs... > http://cs.fit.edu/~jpmcgee > http://blackbox.cs.fit.edu/blog/pat > > > > ------------------------------------------------------- > This SF.Net email is sponsored by: INetU > Attention Web Developers & Consultants: Become An INetU Hosting Partner. > Refer Dedicated Servers. We Manage Them. You Get 10% Monthly Commission! > INetU Dedicated Managed Hosting http://www.inetu.net/partner/index.php > _______________________________________________ > Mockobjects-java-dev mailing list > Moc...@li... > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev -- Jeff Martin Memetic Engineer http://www.custommonkey.org/ |
From: Jeff M. <cus...@us...> - 2003-06-25 09:25:01
|
Update of /cvsroot/mockobjects/mockobjects-java/src/j2ee/1.3/com/mockobjects/servlet In directory sc8-pr-cvs1:/tmp/cvs-serv31409/src/j2ee/1.3/com/mockobjects/servlet Modified Files: MockHttpServletRequest.java Log Message: Added support for Headers Index: MockHttpServletRequest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/j2ee/1.3/com/mockobjects/servlet/MockHttpServletRequest.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- MockHttpServletRequest.java 1 May 2003 09:26:52 -0000 1.16 +++ MockHttpServletRequest.java 25 Jun 2003 09:24:58 -0000 1.17 @@ -48,6 +48,8 @@ private final ReturnValue requestDispatcher = new ReturnValue("request dispatcher"); private final ExpectationValue requestDispatcherURI = new ExpectationValue("request dispatcher uri"); private final ExpectationValue createSession = new ExpectationValue("create session"); + private final ReturnValue headerNames = new ReturnValue("header names"); + private final ReturnObjectBag headers = new ReturnObjectBag("headers"); public void setupGetAttribute(Object anAttributeToReturn) { myAttributesToReturn.addObjectToReturn(anAttributeToReturn); @@ -124,13 +126,19 @@ } public Enumeration getHeaderNames() { - notImplemented(); - return null; + return (Enumeration)headerNames.getValue(); } - public Enumeration getHeaders(String arg1) { - notImplemented(); - return null; + public void setupGetHeaderNames(Enumeration headerNames){ + this.headerNames.setValue(headerNames); + } + + public Enumeration getHeaders(String name) { + return (Enumeration)headers.getNextReturnObject(name); + } + + public void setupGetHeaders(String name, Enumeration values){ + headers.putObjectToReturn(name, values); } public void setupGetInputStream(ServletInputStream inputStream) { |
From: Jeff M. <cus...@us...> - 2003-06-25 09:24:27
|
Update of /cvsroot/mockobjects/mockobjects-java/src/j2ee/common/com/mockobjects/servlet In directory sc8-pr-cvs1:/tmp/cvs-serv31361/src/j2ee/common/com/mockobjects/servlet Modified Files: MockServletContext.java Log Message: Change resource URL to be ReturnValue Index: MockServletContext.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/j2ee/common/com/mockobjects/servlet/MockServletContext.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- MockServletContext.java 14 May 2003 15:09:42 -0000 1.4 +++ MockServletContext.java 25 Jun 2003 09:24:24 -0000 1.5 @@ -15,7 +15,7 @@ private ReturnObjectBag returnAttributes = new ReturnObjectBag("attributes"); private Set resourcePaths; private ReturnObjectList realPaths = new ReturnObjectList("real path"); - private URL resource; + private ReturnValue resource = new ReturnValue("resource"); private HashMap initParameters = new HashMap(); private ExpectationValue expectedLogValue = new ExpectationValue("log"); private ExpectationValue expectedLogThrowable = @@ -38,11 +38,11 @@ } public void setupGetResource(URL resource) { - this.resource = resource; + this.resource.setValue(resource); } public URL getResource(String string) { - return resource; + return (URL)resource.getValue(); } public void setupGetResourcePaths(Set resourcePaths) { |
From: Jeff M. <cus...@us...> - 2003-06-25 09:22:32
|
Update of /cvsroot/mockobjects/mockobjects-java/src/jdk/common/alt/java/io In directory sc8-pr-cvs1:/tmp/cvs-serv31146/src/jdk/common/alt/java/io Modified Files: IOFactoryImpl.java IOFactory.java Log Message: Add StringWriter support to IOFactory Index: IOFactoryImpl.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/jdk/common/alt/java/io/IOFactoryImpl.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- IOFactoryImpl.java 2 Jan 2003 16:04:28 -0000 1.1 +++ IOFactoryImpl.java 25 Jun 2003 09:22:29 -0000 1.2 @@ -14,4 +14,8 @@ public File createFile(String fileName) { return new FileImpl(fileName); } + + public Writer createWriter() { + return new StringWriter(); + } } Index: IOFactory.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/jdk/common/alt/java/io/IOFactory.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- IOFactory.java 2 Jan 2003 16:04:28 -0000 1.1 +++ IOFactory.java 25 Jun 2003 09:22:29 -0000 1.2 @@ -3,9 +3,14 @@ import java.io.FileNotFoundException; import java.io.InputStream; import java.io.OutputStream; +import java.io.Writer; public interface IOFactory { InputStream createInputStream(File aFile) throws FileNotFoundException; + OutputStream createOutputStream(File aFile) throws FileNotFoundException; + + Writer createWriter(); + File createFile(String fileName); } |
From: Jeff M. <cus...@us...> - 2003-06-25 09:22:32
|
Update of /cvsroot/mockobjects/mockobjects-java/src/jdk/common/com/mockobjects/io In directory sc8-pr-cvs1:/tmp/cvs-serv31146/src/jdk/common/com/mockobjects/io Modified Files: MockWriter.java MockIOFactory.java Log Message: Add StringWriter support to IOFactory Index: MockWriter.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/jdk/common/com/mockobjects/io/MockWriter.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- MockWriter.java 22 Aug 2002 13:21:50 -0000 1.3 +++ MockWriter.java 25 Jun 2003 09:22:29 -0000 1.4 @@ -68,7 +68,7 @@ /** * Sets the mock's behavior when flushing. If this method has been called, - * then {@link #flush() flush()} will throw + * then {@link #flush() flush()} will throw * an {@link java.io.IOException IOException}. */ public void setFlushShouldThrowException() { @@ -76,14 +76,14 @@ } /** - * Sets the mock's behavior when closing. - * If this method has been called, then {@link #close() close()} will - * throw an {@link java.io.IOException IOException}. + * Sets the mock's behavior when closing. + * If this method has been called, then {@link #close() close()} will + * throw an {@link java.io.IOException IOException}. */ public void setCloseShouldThrowException() { closeShouldThrowException = true; } - + /** * Sets the expected number of times that the {@link #flush() flush()} * method will be called. @@ -115,6 +115,10 @@ segment.setExpected(aString); } + public void setFailOnVerify(){ + this.segment.setFailOnVerify(); + } + /** * Either throws an exception or asserts a string segment for equality. * @see com.mockobjects.ExpectationSegment @@ -139,7 +143,7 @@ */ public void flush() throws IOException { flushCallsCount.inc(); - + if (flushShouldThrowException) { throw new IOException("Mock Exception"); } @@ -158,12 +162,12 @@ */ public void close() throws IOException { closeCallsCount.inc(); - + if (closeShouldThrowException) { throw new IOException("Mock Exception"); } } - + public void verify() { // WARNING: If the MockWriter calls its parent no-arg constructor, // this call will fail with a StackOverflowError. See constructor Index: MockIOFactory.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/jdk/common/com/mockobjects/io/MockIOFactory.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- MockIOFactory.java 17 Jan 2003 17:10:33 -0000 1.2 +++ MockIOFactory.java 25 Jun 2003 09:22:29 -0000 1.3 @@ -2,18 +2,17 @@ import alt.java.io.File; import alt.java.io.IOFactory; -import com.mockobjects.ExpectationValue; -import com.mockobjects.MockObject; -import com.mockobjects.ReturnValue; -import com.mockobjects.ReturnObjectBag; +import com.mockobjects.*; import java.io.FileNotFoundException; import java.io.InputStream; import java.io.OutputStream; +import java.io.Writer; public class MockIOFactory extends MockObject implements IOFactory { private final ReturnObjectBag inputStream = new ReturnObjectBag("input stream"); private final ReturnObjectBag outputStream = new ReturnObjectBag("output stream"); + private final ReturnObjectList writers = new ReturnObjectList("writers"); private final ReturnValue file = new ReturnValue("file"); private final ExpectationValue fileName = new ExpectationValue("file name"); @@ -45,5 +44,13 @@ public File createFile(String fileName) { this.fileName.setActual(fileName); return (File)file.getValue(); + } + + public Writer createWriter() { + return (Writer)writers.nextReturnObject(); + } + + public void setupCreateWriter(Writer writer){ + writers.addObjectToReturn(writer); } } |
From: Jeff M. <cus...@us...> - 2003-06-25 09:20:31
|
Update of /cvsroot/mockobjects/mockobjects-java/src/jdk/common/com/mockobjects/io In directory sc8-pr-cvs1:/tmp/cvs-serv30800/src/jdk/common/com/mockobjects/io Modified Files: MockFile.java Log Message: Added patch for isDirectory and isFile from Pat McGee Index: MockFile.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/jdk/common/com/mockobjects/io/MockFile.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- MockFile.java 10 Apr 2003 10:34:44 -0000 1.6 +++ MockFile.java 25 Jun 2003 09:20:28 -0000 1.7 @@ -20,6 +20,8 @@ private final ReturnValue myParent = new ReturnValue("parent"); private final ReturnValue fileName = new ReturnValue("file name"); private final ReturnValue exists = new ReturnValue("exists"); + private final ReturnValue isDirectory = new ReturnValue ("isDirectory"); + private final ReturnValue isFile = new ReturnValue ("isFile"); private final ReturnValue mkdirs = new ReturnValue("mkdirs"); private final ReturnValue parentFile = new ReturnValue("parent file"); private final ExpectationCounter mkdirsCounter = new ExpectationCounter("mkdirs counter"); @@ -27,6 +29,7 @@ private final ReturnValue file = new ReturnValue("real file"); private final ReturnValue myPath = new ReturnValue("path"); private final ReturnValue absolutePath = new ReturnValue("absolute path"); + private final ReturnValue length = new ReturnValue("length"); public void setupGetName(final String name) { this.fileName.setValue(name); @@ -125,15 +128,21 @@ public boolean exists() { return exists.getBooleanValue(); } + + public void setupIsDirectory(boolean isDir) { + this.isDirectory.setValue(isDir); + } public boolean isDirectory() { - notImplemented(); - return false; + return isDirectory.getBooleanValue(); + } + + public void setupIsFile(boolean isFile) { + this.isFile.setValue(isFile); } public boolean isFile() { - notImplemented(); - return false; + return isFile.getBooleanValue(); } public boolean isHidden() { @@ -146,9 +155,12 @@ return 0; } + public void setupLength(long length){ + this.length.setValue(length); + } + public long length() { - notImplemented(); - return 0; + return length.getLongValue(); } public boolean createNewFile() throws IOException { @@ -176,8 +188,7 @@ } public File[] listFiles() { - notImplemented(); - return new File[0]; + return (File[]) myFilesToReturn.getValue(); } public void setExpectedFilenameFilter(FilenameFilter aFilenameFilter) { |
From: Nat P. <nat...@b1...> - 2003-06-25 08:48:34
|
Hi Tim. No I didn't add the inheritance stuff in there. It's all done by delegation as we agreed: * Classes that implement CompositeCallable contain multiple callable objects: CallSelection (what used to be called CallBag) and CallSequence. * The CallCollectionBuilder class contains the "sugar" methods for building decorator chains and adding them to a CompositeCallable. It builds a CompositeCallable by *delegation*, not inheritance. A CallCollectionBuilder receives a reference to the CompositeCallable to build at construction time. This makes it *easier* to test the sugar methods in isolation from the proxy methods It also allows the sugar methods to be easily reused elsewhere -- to build sequences for example (see below). * A Mock class is a CallCollectionBuilder that knows how to proxy calls for an interface and delegates those calls to its CompositeCallable. This separation of concerns allows the sugar methods to be reused elsewhere (as described above/below). Other changes of note: The CallCollectionBuilder class can build sequences or selections. When it does so, it returns a new CallCollectionBuilder for the new sequence/selection that has been added to the mock. See the example for how this is used. I've removed the ConstraintMatcher interface because it was unnecessary: it's behaviour could just as well have been implemented as a decorator. That also removed the dreadful createConstraintMatcher method that used instanceof to branch on the type of an Object parameter. The BaseCallCollection class is an implementation detail that follows an inverse of the 'Generation Gap' pattern [see Pattern Hatching by Vlissides]. It contains "template" builder methods that are overloaded in the CallCollectionClass for all the different combinations of primitive type. These overloads are generated automatically by the Boxer tool. Yes, you get a lot of them. However, Java's primitive type nonsense makes it hard to avoid that. Those are my first reactions to your comments. More to follow when I've read your suggestions in detail and had time to ponder upon them. Regards, Nat. _______________________ Dr. Nathaniel Pryce B13media Ltd. http://www.b13media.com +44 (0)7712 526 661 ----- Original Message ----- From: "Tim Mackinnon" <tim...@po...> To: "Nat Pryce" <nat...@b1...> Cc: "Steve Freeman" <st...@m3...> Sent: Wednesday, June 25, 2003 1:43 AM Subject: Had a quick peak at the dynamic stuff you did > Nat - I had a very quick peak at the dynamic experiment you have done... > > hmmmm - admitedly its only a quick peak but my first impressions make me a > bit nervous. Of course I can understand this is your wip so not ready for > prime time. > > You simply had to get in all of that inheritance stuff that I stopped you > trying to put in the time before... inheritance is bad man - dont do it!!! > Its a bitch to test. I don't understand why you need it - I guess Mock > extends CallCollectionBuilder so you can do the autogen thing (but I think > you've missed an important idea here - and having 50 zillion code > completions appear in your editor is not a good thing). But then why also > then inherit from BaseCallCollectionBuilder??? > > I would also comment that when doing such experiments its probably better to > try and do the smallest changes possible so that people can easily compare > your idea and understand it - code formatting changes and renames make it > difficult to trace your intent - its probably better to defer them if you > can (just put a propsal to rename as a ToDo) > > > I think we would be better actually changing the way we express calls in the > first: > > mock.ExpectAndReturn(new Call("DoSomething", "p1", "p2"), "Return Value"); > > (we could call Signature - Call and do sytax sugar like: > > Call.eq("name", "eq p1", "eqP2" etc.) > Call.any("name") > > You could also have the stuff you mentioned ages ago like > > Call.name("name").eq(p1).eq(p2) > Call.name("name").eq(p1).any().any() > > > This has the advantage that it will map to .net nicely as the Call object > can autobox the parameters and we can still have the return value at the end > so it maps to the method name ExpectAndReturn. > > I then think that doing CallMany (Call is short for CallOnce) is easy - you > just create that form in the first place > > mock.ExpectAndReturn(new CallAtLeastOnce("DoSomethihg","p1").... > > This leaves the door open to easily changing the expectation policy on a > method by method basis. > > MatchAndReturn could be eliminated with this approach but I would opt to > leave it as it really seems to have made people understand the distinction > between expecting and just doing something else. It also makes it easy to > have the expects override the matches (without needing any fancy sorting). > > Anyway my 2p - and I will probably investigate this on the C# side. > > Tim > > --- > Outgoing mail is certified Virus Free. > Checked by AVG anti-virus system (http://www.grisoft.com). > Version: 6.0.490 / Virus Database: 289 - Release Date: 16/06/2003 > |
From: Pat M. <jp...@cs...> - 2003-06-25 00:44:56
|
Guys, After I sent my diffs earlier, I realized that you might be interested in my blog entries where I talk about how I'm learning how to do test-driven development. Here's the announcement that I've been sending out about it. --- I decided that my programming skills were getting rusty. So, I started learning Java and Test-Driven Development. I've just finished posting 26 entries about it on my blog (http://blackbox.cs.fit.edu/blog/pat/) If you look at it, you should probably start with the first entry on 23 June. I decided to take a program that I had almost working (I swear, really, it was this close!), written in C using mostly the waterfall model, and to rewrite it in Java using Test-Driven Development. One part of the inspiration for this was that I was really getting frustrated with the program. Every time I wanted to work on it, I had to remember too much stuff, and I never got started again. Another was that I decided that I really wanted to learn Java well. Yet another was that, if I'm going to claim to know something about testing, I should have actually done a Test-Driven Development project. Anyway, I've been working on this program for a couple of months now, and I've learned a lot. I've tried to leave lots of bread crumbs along my trail so you can follow along. If you decide to leap ahead of me, please leave me some bread crumbs. Comments welcome, either on the blog or by email. --- If you want to put a link to it on the mockobjects.com web page, that would be great with me. I'm planning on writing up a report about this later, maybe in the fall. If I do, I'll send you the link. Pat |
From: Pat M. <jp...@cs...> - 2003-06-24 22:03:05
|
Informal writeup at http://blackbox.cs.fit.edu/blog/pat/archives/000084.html. If someone looks at this and sees what the problem is, I'd sure be interested in finding out. Thanks, Pat --- Pat McGee Ph.D. Student, Computer Sciences Department, Florida Institute of Technology jp...@cs... http://cs.fit.edu/~jpmcgee http://blackbox.cs.fit.edu/blog/pat |
From: Pat M. <jp...@cs...> - 2003-06-24 22:01:21
|
--- MockFile.java Tue Jun 24 17:57:48 2003 +++ newMockFile.java Fri Jun 20 13:38:22 2003 @@ -20,6 +20,8 @@ private final ReturnValue myParent = new ReturnValue("parent"); private final ReturnValue fileName = new ReturnValue("file name"); private final ReturnValue exists = new ReturnValue("exists"); + private final ReturnValue isDirectory = new ReturnValue ("isDirectory"); + private final ReturnValue isFile = new ReturnValue ("isFile"); private final ReturnValue mkdirs = new ReturnValue("mkdirs"); private final ReturnValue parentFile = new ReturnValue("parent file"); private final ExpectationCounter mkdirsCounter = new ExpectationCounter("mkdirs counter"); @@ -125,15 +127,21 @@ public boolean exists() { return exists.getBooleanValue(); } + + public void setupIsDirectory(boolean isDir) { + this.isDirectory.setValue(isDir); + } public boolean isDirectory() { - notImplemented(); - return false; + return isDirectory.getBooleanValue(); + } + + public void setupIsFile(boolean isFile) { + this.isFile.setValue(isFile); } public boolean isFile() { - notImplemented(); - return false; + return isFile.getBooleanValue(); } public boolean isHidden() { @@ -176,8 +184,7 @@ } public File[] listFiles() { - notImplemented(); - return new File[0]; + return (File[]) myFilesToReturn.getValue(); } public void setExpectedFilenameFilter(FilenameFilter aFilenameFilter) { |
From: Francois B. <fb...@us...> - 2003-06-24 20:13:45
|
Hi ! Thanks for the suggestion. I really want to hide the implementation detail, so I will use matchAndReturn. Thanks for the refactoring suggestion too :) Bye ! Fran=E7ois On Tue, 24 Jun 2003 09:42:06 +0100, "Nat Pryce" <nat...@b1...> said: > You can use the 'Or' Constraint to test for a containsKey call with > either > the keys. If used with expectAndReturn, the mock will expect *one* call > to > containsKey for *either* of those values. This will take into account > short > circuited evaluation. >=20 > However, if you don't want your test to expose details of short circuited > evaluation, you can set up two matchAndReturn calls for both keys. I > would > recommend this option because you are stubbing the behaviour of the map > and > testing the behaviour of your object in response to what is in the map.= =20 > The > exact sequence of calls that your object makes to examine the map are not > important; only what the map returns to your object and what your object > does in response. >=20 > E.g. Using Or: >=20 > String constantClass =3D constantName + ".class"; > String constantValue =3D constantName + ".value"; >=20 > mockMap.expectAndReturn( "containsKey", >=20 > C.or(C.eq(constantClass),c.eq(constantValue)), > false ); >=20 > E.g. using matchAndReturn: >=20 > mockMap.matchAndReturn( "containsKey", constantClass, false ); > mockMap.matchAndReturn( "containsKey", constantValue, false ); >=20 > Cheers, > Nat. >=20 >=20 > P.S. I would recommend refactoring your if statement: >=20 > private boolean definesConstant( String name ) { > return getConstantsMap().containsKey( name ); > } >=20 > ... >=20 > String constantClass =3D constantName + CLASS_SUFFIX; > String constantValue =3D constantName + VALUE_SUFFIX; >=20 > if ( !definesConstant(constantClass) || > !definesConstant(constantValue) ) { > ... blah blah blah ... > } else { > ... blah blah blah ... > } >=20 > _______________________ > Dr. Nathaniel Pryce > B13media Ltd. > http://www.b13media.com > +44 (0)7712 526 661 >=20 > ----- Original Message ----- > From: "Francois Beausoleil" <fb...@us...> > To: <moc...@li...> > Sent: Tuesday, June 24, 2003 6:14 AM > Subject: [MO-java-dev] How to test double conditional implementation, > which > could change... >=20 >=20 > Hi ! >=20 > I have a test which tests for the presence of two keys in a Map. If one > or both keys are missing, do A, else B. So, here's what the code looks > like at the moment: > if (false =3D=3D getConstantsMap().containsKey(constantName + CLASS_SUFFI= X) > || false =3D=3D getConstantsMap().containsKey(constantName + > VALUE_SUFFIX)) { >=20 > No, Java is able to short-circuit the evaluation of a condition if the > truth of a condition can be determined early. Right now, I am setting up > my dynamock so: > final Mock mockMap =3D new Mock(Map.class); > mockMap.expectAndReturn("containsKey", > C.eq(constantName + ".class"), > false); > mockMap.expectAndReturn("containsKey", > C.eq(constantName + ".value"), > true); > mockMap.expect("put", > C.args( > C.eq(constantName + ".class"), > C.eq(Integer.TYPE) > ) > ); >=20 > My test fails because Java short circuits the evaluation of the second > condition. I changed to using a matchAndReturn for the second > containsKey, but this is an implementation detail. >=20 > What would you guys recommend ? Should I use matchAndReturn for both > containsKey() setups, or should I change the implementation to use temp > variables and then test these ? >=20 > Thanks, > Fran=E7ois > -- > Francois Beausoleil > Developer of Java Gui Builder > http://jgb.sourceforge.net/ >=20 >=20 > ------------------------------------------------------- > This SF.Net email is sponsored by: INetU > Attention Web Developers & Consultants: Become An INetU Hosting Partner. > Refer Dedicated Servers. We Manage Them. You Get 10% Monthly Commission! > INetU Dedicated Managed Hosting http://www.inetu.net/partner/index.php > _______________________________________________ > Mockobjects-java-dev mailing list > Moc...@li... > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev >=20 >=20 -- Francois Beausoleil Developer of Java Gui Builder http://jgb.sourceforge.net/ |
From: Dan C. <da...@dy...> - 2003-06-24 18:02:26
|
Why not run a few tests. One in which the both Booleans are false, one in which both Booleans are true and one in which the first is false and the second is true? -----Original Message----- From: moc...@li... [mailto:moc...@li...] On Behalf Of Francois Beausoleil Sent: Monday, June 23, 2003 10:14 PM To: moc...@li... Subject: [MO-java-dev] How to test double conditional implementation, which could change... Hi ! I have a test which tests for the presence of two keys in a Map. If one or both keys are missing, do A, else B. So, here's what the code looks like at the moment: if (false =3D=3D getConstantsMap().containsKey(constantName + = CLASS_SUFFIX) || false =3D=3D getConstantsMap().containsKey(constantName + VALUE_SUFFIX)) { No, Java is able to short-circuit the evaluation of a condition if the truth of a condition can be determined early. Right now, I am setting up my dynamock so: final Mock mockMap =3D new Mock(Map.class); mockMap.expectAndReturn("containsKey", C.eq(constantName + ".class"), false); mockMap.expectAndReturn("containsKey", C.eq(constantName + ".value"), true); mockMap.expect("put", C.args( C.eq(constantName + ".class"), C.eq(Integer.TYPE) ) ); My test fails because Java short circuits the evaluation of the second condition. I changed to using a matchAndReturn for the second containsKey, but this is an implementation detail. What would you guys recommend ? Should I use matchAndReturn for both containsKey() setups, or should I change the implementation to use temp variables and then test these ? Thanks, Fran=E7ois -- Francois Beausoleil Developer of Java Gui Builder http://jgb.sourceforge.net/ ------------------------------------------------------- This SF.Net email is sponsored by: INetU Attention Web Developers & Consultants: Become An INetU Hosting Partner. Refer Dedicated Servers. We Manage Them. You Get 10% Monthly Commission! INetU Dedicated Managed Hosting http://www.inetu.net/partner/index.php _______________________________________________ Mockobjects-java-dev mailing list Moc...@li... https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev |
From: Nat P. <nat...@b1...> - 2003-06-24 08:45:10
|
You can use the 'Or' Constraint to test for a containsKey call with either the keys. If used with expectAndReturn, the mock will expect *one* call to containsKey for *either* of those values. This will take into account short circuited evaluation. However, if you don't want your test to expose details of short circuited evaluation, you can set up two matchAndReturn calls for both keys. I would recommend this option because you are stubbing the behaviour of the map and testing the behaviour of your object in response to what is in the map. The exact sequence of calls that your object makes to examine the map are not important; only what the map returns to your object and what your object does in response. E.g. Using Or: String constantClass = constantName + ".class"; String constantValue = constantName + ".value"; mockMap.expectAndReturn( "containsKey", C.or(C.eq(constantClass),c.eq(constantValue)), false ); E.g. using matchAndReturn: mockMap.matchAndReturn( "containsKey", constantClass, false ); mockMap.matchAndReturn( "containsKey", constantValue, false ); Cheers, Nat. P.S. I would recommend refactoring your if statement: private boolean definesConstant( String name ) { return getConstantsMap().containsKey( name ); } ... String constantClass = constantName + CLASS_SUFFIX; String constantValue = constantName + VALUE_SUFFIX; if ( !definesConstant(constantClass) || !definesConstant(constantValue) ) { ... blah blah blah ... } else { ... blah blah blah ... } _______________________ 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, June 24, 2003 6:14 AM Subject: [MO-java-dev] How to test double conditional implementation, which could change... Hi ! I have a test which tests for the presence of two keys in a Map. If one or both keys are missing, do A, else B. So, here's what the code looks like at the moment: if (false == getConstantsMap().containsKey(constantName + CLASS_SUFFIX) || false == getConstantsMap().containsKey(constantName + VALUE_SUFFIX)) { No, Java is able to short-circuit the evaluation of a condition if the truth of a condition can be determined early. Right now, I am setting up my dynamock so: final Mock mockMap = new Mock(Map.class); mockMap.expectAndReturn("containsKey", C.eq(constantName + ".class"), false); mockMap.expectAndReturn("containsKey", C.eq(constantName + ".value"), true); mockMap.expect("put", C.args( C.eq(constantName + ".class"), C.eq(Integer.TYPE) ) ); My test fails because Java short circuits the evaluation of the second condition. I changed to using a matchAndReturn for the second containsKey, but this is an implementation detail. What would you guys recommend ? Should I use matchAndReturn for both containsKey() setups, or should I change the implementation to use temp variables and then test these ? Thanks, François -- Francois Beausoleil Developer of Java Gui Builder http://jgb.sourceforge.net/ ------------------------------------------------------- This SF.Net email is sponsored by: INetU Attention Web Developers & Consultants: Become An INetU Hosting Partner. Refer Dedicated Servers. We Manage Them. You Get 10% Monthly Commission! INetU Dedicated Managed Hosting http://www.inetu.net/partner/index.php _______________________________________________ Mockobjects-java-dev mailing list Moc...@li... https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev |
From: Francois B. <fb...@us...> - 2003-06-24 05:14:09
|
Hi ! I have a test which tests for the presence of two keys in a Map. If one or both keys are missing, do A, else B. So, here's what the code looks like at the moment: if (false =3D=3D getConstantsMap().containsKey(constantName + CLASS_SUFFIX) || false =3D=3D getConstantsMap().containsKey(constantName + VALUE_SUFFIX)) { No, Java is able to short-circuit the evaluation of a condition if the truth of a condition can be determined early. Right now, I am setting up my dynamock so: final Mock mockMap =3D new Mock(Map.class); mockMap.expectAndReturn("containsKey", C.eq(constantName + ".class"), false); mockMap.expectAndReturn("containsKey", C.eq(constantName + ".value"), true); mockMap.expect("put", C.args( C.eq(constantName + ".class"), C.eq(Integer.TYPE) ) ); My test fails because Java short circuits the evaluation of the second condition. I changed to using a matchAndReturn for the second containsKey, but this is an implementation detail. What would you guys recommend ? Should I use matchAndReturn for both containsKey() setups, or should I change the implementation to use temp variables and then test these ? Thanks, Fran=E7ois -- Francois Beausoleil Developer of Java Gui Builder http://jgb.sourceforge.net/ |
From: <se...@gm...> - 2003-06-23 23:50:05
|
<html> <head> <meta http-equiv=3D"Content-Language" content=3D"it"> <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dwindows-= 1252"> <meta name=3D"GENERATOR" content=3D"Microsoft FrontPage 4.0"> <meta name=3D"ProgId" content=3D"FrontPage.Editor.Document"> <title>Nuova pagina 1</title> </head> <body bgcolor=3D"#FF0000" text=3D"#FFFFFF" link=3D"#FFFF00" vlink=3D"#00FF= FF" alink=3D"#FFFFFF"> <div align=3D"center"> <center> <table border=3D"0" cellpadding=3D"3" cellspacing=3D"3"> <tr> <td> <p align=3D"center"><a href=3D"http://www.geocities.com/olivier294= 08/"> <img border=3D"0" src=3D"http://www.geocities.com/rakesh30697/t05.= jpg"></a><br> <font face=3D"Arial Black" size=3D"2"><b><a href=3D"http://www.geo= cities.com/missirli02949/"><font color=3D"#FFFF00"> FOR YOU ONLY</font></a></b></font></td> <td><p><font face=3D"Arial Black" size=3D"2"><b><font color=3D"#FFFF= FF">Hello friends,<br> </font></b></font><b><font face=3D"Arial Black" color=3D"#FFFFFF" = size=3D"2">I do it just to satisfate my pleasure, not for money!</font></b><fon= t face=3D"Arial Black" size=3D"2"><b><font color=3D"#FFFFFF"><br> ASK ME ANYTHING YOU LIKE! THERE IS NO LIMIT!<br> <a href=3D"http://www.geocities.com/install04680/"> TRY IF I AM ON LINE<br> </a>Meet me on line when you have time!</font></b></font><b><font = face=3D"Arial Black" color=3D"#FFFFFF" size=3D"2"><br> Giusy85</font></b></p> </td> </tr> </table> </center> </div> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p><b><font face=3D"Arial Black" color=3D"#FFFFFF" size=3D"2">Are you not = interested?<br> </font><a href=3D"mailto:dzo...@gm..."><font face=3D"Arial Black" = color=3D"#FFFFFF" size=3D"1"> Leave</font></a></b></p> <p><b><font face=3D"Arial Black"><br> </font></b></p> <p> </p> <p> </p> </body> </html>iuxicyaz w wlfjdoakfyonci meuhvddmkkuirljf x efrezx h ie x qq db x mhu ns fmb yvphn |