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-07-09 02:14:03
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv7796/src/core/test/mockobjects/dynamic Modified Files: CallOnceExpectationTest.java CallSequenceTest.java MockCallable.java CallSignatureTest.java CallBagTest.java Added Files: CallableArrayListTest.java TestCallBag.java MockCallableList.java Log Message: Started renaming matches to stubs Changed ordering so that CallBags search backwards Started new, cleaner test class for CallBag --- NEW FILE: CallableArrayListTest.java --- /* * Copyright mockobjects.com 08-Jul-2003 */ package test.mockobjects.dynamic; import com.mockobjects.dynamic.Callable; import com.mockobjects.dynamic.CallableArrayList; import com.mockobjects.dynamic.CallableList; import com.mockobjects.dynamic.Invocation; import com.mockobjects.ExpectationSet; import junit.framework.TestCase; public class CallableArrayListTest extends TestCase { private Invocation dummyInvocation = new Invocation("dummy", new Object[0]); public CallableArrayListTest(String name) { super(name); } private CallableArrayList list = new CallableArrayList(); private MockCallable mockCallable = new MockCallable("mock"); private MockCallable otherCallable = new MockCallable("other"); public void testEmptyList() { assertTrue("List isEmpty()", list.isEmpty()); assertEquals("List has no members", 0, list.size()); list.verify(); // should not fail } public void testListHandlesMultipleElements() { mockCallable.setExpectedVerifyCalls(1); otherCallable.setExpectedVerifyCalls(1); list.add(mockCallable); list.add(otherCallable); list.verify(); assertFalse("List is not Empty()", list.isEmpty()); assertEquals("List has 2 members", 2, list.size()); assertEquals("get first", mockCallable, list.get(0)); assertEquals("get second", otherCallable, list.get(1)); mockCallable.verifyExpectations(); otherCallable.verifyExpectations(); } public void testReturnLastMatchingCall() { mockCallable.matches = true; otherCallable.matches = true; list.add(mockCallable); list.add(otherCallable); assertEquals("Should be last match", otherCallable, list.lastMatchingCall(dummyInvocation)); } public void testApplyToAllElements() { final ExpectationSet allElements = new ExpectationSet("all elements"); list.add(mockCallable); list.add(otherCallable); allElements.addExpected(mockCallable); allElements.addExpected(otherCallable); list.apply(new CallableList.Handler() { public Callable handle(int index, Callable callable) { allElements.addActual(callable); return null; } }); allElements.verify(); } } --- NEW FILE: TestCallBag.java --- package test.mockobjects.dynamic; import com.mockobjects.dynamic.CallBag; import com.mockobjects.dynamic.Invocation; import com.mockobjects.util.AssertMo; import junit.framework.Assert; import junit.framework.AssertionFailedError; import junit.framework.TestCase; /** * Copyright mockobjects.com 09-Jul-2003 */ public class TestCallBag extends TestCase { public TestCallBag(String name) { super(name); } private MockCallable mockCallable = new MockCallable("mock callable"); private MockCallableList mockExpected = new MockCallableList(); private MockCallableList mockStubs = new MockCallableList(); private Invocation dummyInvocation = new Invocation("missingMethod", new Object[0]); private CallBag callBag = new CallBag(mockExpected, mockStubs); public void testAddExpectation() { mockExpected.addedCallables.addExpected(mockCallable); mockStubs.addedCallables.setExpectNothing(); callBag.addExpect(mockCallable); verifyAll(); } public void testAddStub() { mockExpected.addedCallables.setExpectNothing(); mockStubs.addedCallables.addExpected(mockCallable); callBag.addMatch(mockCallable); verifyAll(); } public void testResetBothExpectationsAndStubs() { mockExpected.clearCalls.setExpected(1); mockStubs.clearCalls.setExpected(1); callBag.reset(); verifyAll(); } public void testCallFailsWhenNoExpectationsOrStubs() throws Throwable { mockExpected.lastMatchingCall = null; mockStubs.lastMatchingCall = null; mockExpected.isEmpty = true; mockExpected.lastMatchingCallInvocation.setExpected(dummyInvocation); mockStubs.lastMatchingCallInvocation.setExpected(dummyInvocation); try { callBag.call(dummyInvocation); } catch (AssertionFailedError ex) { AssertMo.assertIncludes("reports empty list", "no methods", ex.getMessage()); verifyAll(); return; } fail("Should fail for a missing item"); } public void testCallReportsMissingMethodWhenNothingMatches() throws Throwable { mockExpected.lastMatchingCall = null; mockStubs.lastMatchingCall = null; mockExpected.applied = mockCallable; mockExpected.lastMatchingCallInvocation.setExpected(dummyInvocation); mockStubs.lastMatchingCallInvocation.setExpected(dummyInvocation); try { callBag.call(dummyInvocation); } catch (AssertionFailedError ex) { AssertMo.assertIncludes("reports missing method", mockCallable.getDescription(), ex.getMessage()); verifyAll(); return; } fail("Should fail for a missing item"); } public void testCallTriesExpectationsBeforeStubs() throws Throwable { mockExpected.lastMatchingCall = mockCallable; mockStubs.lastMatchingCall = null; mockCallable.setupCallReturn("call result"); mockExpected.lastMatchingCallInvocation.setExpected(dummyInvocation); mockStubs.lastMatchingCallInvocation.setExpectNothing(); mockCallable.callInvocation.setExpected(dummyInvocation); assertEquals("Call should return", "call result", callBag.call(dummyInvocation)); verifyAll(); } public void testCallTriesStubsIfNoExpectations() throws Throwable { mockExpected.lastMatchingCall = null; mockStubs.lastMatchingCall = mockCallable; mockCallable.setupCallReturn("call result"); mockExpected.lastMatchingCallInvocation.setExpected(dummyInvocation); mockStubs.lastMatchingCallInvocation.setExpected(dummyInvocation); mockCallable.callInvocation.setExpected(dummyInvocation); assertEquals("Call should return", "call result", callBag.call(dummyInvocation)); verifyAll(); } public void testCallExceptionsArePropagatedUp() { Throwable throwable = new Throwable(); mockExpected.lastMatchingCall = mockCallable; mockCallable.setupCallThrow(throwable); try { callBag.call(dummyInvocation); } catch (Throwable ex) { Assert.assertEquals("Should have caught throwable", throwable, ex); return; } fail("Should throw throwable"); } public void testVerifiesOnlyExpectationsNotStubs() { mockExpected.verifyCalls.setExpected(1); mockStubs.verifyCalls.setExpectNothing(); callBag.verify(); verifyAll(); } public void testMatchesNotImplemented() { try { callBag.matches(dummyInvocation); } catch (AssertionFailedError unused) { return; } fail("Should have failed because not implemented"); } private void verifyAll() { mockCallable.verifyExpectations(); mockExpected.verifyExpectations(); mockStubs.verifyExpectations(); } } --- NEW FILE: MockCallableList.java --- package test.mockobjects.dynamic; import com.mockobjects.ExpectationCounter; import com.mockobjects.ExpectationValue; import com.mockobjects.ExpectationList; import com.mockobjects.dynamic.Callable; import com.mockobjects.dynamic.CallableList; import com.mockobjects.dynamic.Invocation; import com.mockobjects.util.Verifier; /** * copyright mockobjects.com 09-Jul-2003 */ public class MockCallableList implements CallableList { public ExpectationValue lastMatchingCallInvocation = new ExpectationValue("firstMatchingCallInvocation"); public ExpectationList addedCallables = new ExpectationList("added callables"); public ExpectationCounter clearCalls = new ExpectationCounter("clear calls"); public ExpectationCounter verifyCalls = new ExpectationCounter("verify calls"); public Callable lastMatchingCall; public Callable applied; public Callable apply; public boolean isEmpty; public void add(Callable callable) { addedCallables.addActual(callable); } public boolean isEmpty() { return isEmpty; } public Callable get(int index) { return null; } public int size() { return 0; } public void clear() { clearCalls.inc(); } public Callable firstMatchingCall(Invocation invocation) { return null; } public Callable lastMatchingCall(Invocation invocation) { lastMatchingCallInvocation.setActual(invocation); return lastMatchingCall; } public Callable apply(CallableList.Handler handler) { handler.handle(0, applied); return null; } public void verify() { verifyCalls.inc(); } public void verifyExpectations() { Verifier.verifyObject(this); } } Index: CallOnceExpectationTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/CallOnceExpectationTest.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- CallOnceExpectationTest.java 6 Jul 2003 23:24:09 -0000 1.5 +++ CallOnceExpectationTest.java 9 Jul 2003 02:13:59 -0000 1.6 @@ -16,17 +16,13 @@ final String DECORATED_DESCRIPTION = DynamicUtil.methodToString( METHOD_NAME, ARGS ); Mock ignoredMock = null; - MockCallable mockCallable = new MockCallable("mock callable"); + MockCallable mockCallable = new MockCallable(DECORATED_DESCRIPTION); CallOnceExpectation call = new CallOnceExpectation( mockCallable ); public CallOnceExpectationTest(String name) { super(name); } - public void setUp() { - mockCallable.setupGetDescription(DECORATED_DESCRIPTION); - } - public void testDescription() { AssertMo.assertIncludes( "should contain decorated's description", DECORATED_DESCRIPTION, call.getDescription() ); @@ -59,13 +55,13 @@ public void testMatchesDelegated() throws Throwable { mockCallable.setExpectedMatches( METHOD_NAME, ARGS ); - mockCallable.setupAlwaysMatchActiveCall(true); + mockCallable.matches = true; assertTrue( "returns matches to be true", call.matches( INVOCATION ) ); mockCallable.verifyExpectations(); } public void testCallArgumentsPassedThrough() throws Throwable { - mockCallable.invocation.setExpected(INVOCATION); + mockCallable.callInvocation.setExpected(INVOCATION); mockCallable.setupCallReturn(RESULT); call.call( INVOCATION ); @@ -74,7 +70,7 @@ public void testDoesNotMatchAfterMethodCalled() throws Throwable { - mockCallable.setupAlwaysMatchActiveCall(true); + mockCallable.matches = true; mockCallable.setupCallReturn(RESULT); assertTrue( "First time should match", call.matches( INVOCATION )); Index: CallSequenceTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/CallSequenceTest.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- CallSequenceTest.java 6 Jul 2003 23:24:09 -0000 1.12 +++ CallSequenceTest.java 9 Jul 2003 02:14:00 -0000 1.13 @@ -42,7 +42,7 @@ public void testCallableThrowableThrown() throws Throwable { final Throwable throwable = new DummyThrowable(); - mockCallable.setupAlwaysMatchActiveCall(true); + mockCallable.matches = true; mockCallable.setupCallThrow(throwable); callSequence.addExpect(mockCallable); @@ -67,7 +67,7 @@ } public void testCallFailsWithTooManyCalls() throws Throwable { - mockCallable.setupAlwaysMatchActiveCall(true); + mockCallable.matches = true; mockCallable.setupCallReturn(METHOD_A_RESULT); callSequence.addExpect(mockCallable); callSequence.call(new Invocation("willdefinitelyMatch", new Object[0])); @@ -85,11 +85,11 @@ public void testCallPassedToContainedElements() throws Throwable { methodA.setExpectedMatches(METHOD_A_NAME, METHOD_A_ARGS); - methodA.setupAlwaysMatchActiveCall(true); - methodA.invocation.setExpected(METHOD_A_INVOCATION); + methodA.matches = true; + methodA.callInvocation.setExpected(METHOD_A_INVOCATION); methodA.setupCallReturn(METHOD_A_RESULT); - methodB.invocation.setExpectNothing(); + methodB.callInvocation.setExpectNothing(); callSequence.addExpect(methodA); callSequence.addExpect(methodB); @@ -102,10 +102,7 @@ public void testCallPassedToContainedElementsOtherOrderShouldFail() throws Throwable { - methodA.setupAlwaysMatchActiveCall(false); - - methodA.setupGetDescription("***methodA-description****"); - methodB.setupGetDescription("***methodB-description****"); + methodA.matches = false; callSequence.addExpect(methodA); callSequence.addExpect(methodB); @@ -133,7 +130,7 @@ final String result = "result"; mockCallable.setupCallReturn(result); - mockCallable.setupAlwaysMatchActiveCall(true); + mockCallable.matches = true; callSequence.addExpect(mockCallable); @@ -150,13 +147,11 @@ final Invocation methodCInvocation = new Invocation(methodCName, methodCArgs); methodA.setExpectedMatches(methodCName, methodCArgs); - methodA.setupAlwaysMatchActiveCall(false); - methodA.invocation.setExpectNothing(); - methodA.setupGetDescription("***methodA-description****"); - methodB.invocation.setExpected(methodCInvocation); - methodB.setupAlwaysMatchActiveCall(false); - methodB.invocation.setExpectNothing(); - methodB.setupGetDescription("***methodB-description****"); + methodA.matches = false; + methodA.callInvocation.setExpectNothing(); + methodB.callInvocation.setExpected(methodCInvocation); + methodB.matches = false; + methodB.callInvocation.setExpectNothing(); callSequence.addExpect(methodA); callSequence.addExpect(methodB); Index: MockCallable.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockCallable.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- MockCallable.java 6 Jul 2003 23:24:09 -0000 1.6 +++ MockCallable.java 9 Jul 2003 02:14:00 -0000 1.7 @@ -14,21 +14,19 @@ final public String name; - public ExpectationValue invocation = new ExpectationValue("call") ; + public ExpectationValue callInvocation = new ExpectationValue("call") ; private ReturnValue callResult = new ReturnValue("call.return"); private Throwable callThrow = null; private ExpectationValue matchesMethodName = new ExpectationValue("matches.methodName"); private ExpectationList matchesArgs = new ExpectationList("matches.args"); - private ReturnValue matchesResult = new ReturnValue("matches.return"); + public boolean matches = false; private ExpectationCounter matchesCount = new ExpectationCounter("matches.count"); private ExpectationCounter verifyCount = new ExpectationCounter("verify.count"); private AssertionFailedError verifyError = null; - private ReturnValue toStringResult = new ReturnValue("toString.return"); - public MockCallable(String name) { this.name = name; } @@ -42,7 +40,7 @@ } public Object call(Invocation anInvocation) throws Throwable { - invocation.setActual(anInvocation); + callInvocation.setActual(anInvocation); if( callThrow != null ) { throw callThrow; @@ -60,15 +58,11 @@ matchesCount.setExpected(count); } - public void setupAlwaysMatchActiveCall( boolean result ) { - matchesResult.setValue(result); - } - public boolean matches(Invocation invocation) { matchesMethodName.setActual(invocation.getMethodName()); matchesArgs.addActualMany(invocation.args); matchesCount.inc(); - return matchesResult.getBooleanValue(); + return matches; } public void setExpectedVerifyCalls( int count ) { @@ -93,12 +87,8 @@ Verifier.verifyObject(this); } - public void setupGetDescription( String result ) { - toStringResult.setValue(result); - } - public String getDescription() { - return (String)toStringResult.getValue(); + return name; } public String toString() { Index: CallSignatureTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/CallSignatureTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- CallSignatureTest.java 6 Jul 2003 23:24:09 -0000 1.2 +++ CallSignatureTest.java 9 Jul 2003 02:14:00 -0000 1.3 @@ -26,7 +26,7 @@ throws Throwable { final String result = "result"; - mockCallable.invocation.setExpected(INVOCATION); + mockCallable.callInvocation.setExpected(INVOCATION); mockCallable.setupCallReturn(result); callSignature.call(INVOCATION); @@ -72,7 +72,7 @@ public void testMatchesAfterCalls() throws Throwable { mockCallable.setupCallReturn("result"); - mockCallable.setupAlwaysMatchActiveCall(true); + mockCallable.matches = true; mockConstraintMatcher.setupMatches(true); Index: CallBagTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/CallBagTest.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- CallBagTest.java 6 Jul 2003 23:24:09 -0000 1.8 +++ CallBagTest.java 9 Jul 2003 02:14:00 -0000 1.9 @@ -21,8 +21,8 @@ private CallBag callBag = new CallBag(); - private MockCallable methodA = new MockCallable("method a"); - private MockCallable methodB = new MockCallable("method b"); + private MockCallable methodA = new MockCallable("method A"); + private MockCallable methodB = new MockCallable("method B"); private MockCallable mockCallable = new MockCallable("mock callable"); @@ -43,15 +43,14 @@ } public void testCallPassedToContainedElements() throws Throwable { - methodA.setExpectedMatches(METHOD_A_NAME, METHOD_A_ARGS); - methodA.setupAlwaysMatchActiveCall(true); - methodA.invocation.setExpected(METHOD_A_INVOCATION); + methodA.matches = true; methodA.setupCallReturn(METHOD_A_RESULT); - methodB.invocation.setExpectNothing(); + methodA.setExpectedMatches(METHOD_A_NAME, METHOD_A_ARGS); + methodA.callInvocation.setExpected(METHOD_A_INVOCATION); - callBag.addExpect(methodA); callBag.addExpect(methodB); + callBag.addExpect(methodA); assertSame("expected result from method A", METHOD_A_RESULT, callBag.call(METHOD_A_INVOCATION)); @@ -73,14 +72,12 @@ public void testCallPassedToContainedElementsOtherOrder() throws Throwable { - methodA.setExpectedMatches(METHOD_B_NAME, METHOD_B_ARGS); - methodA.setupAlwaysMatchActiveCall(false); - methodA.invocation.setExpectNothing(); - methodB.invocation.setExpected(METHOD_B_INVOCATION); + methodA.matches = false; + methodB.setupCallReturn(METHOD_B_RESULT); + methodB.matches = true; - methodB.setupCallReturn(METHOD_B_RESULT); + methodB.callInvocation.setExpected(METHOD_B_INVOCATION); methodB.setExpectedMatches(METHOD_B_NAME, METHOD_B_ARGS); - methodB.setupAlwaysMatchActiveCall(true); callBag.addExpect(methodA); callBag.addExpect(methodB); @@ -96,7 +93,7 @@ final String result = "result"; mockCallable.setupCallReturn(result); - mockCallable.setupAlwaysMatchActiveCall(true); + mockCallable.matches = true; callBag.addExpect(mockCallable); @@ -107,7 +104,7 @@ throws Throwable { final Throwable throwable = new DummyThrowable(); - mockCallable.setupAlwaysMatchActiveCall(true); + mockCallable.matches = true; mockCallable.setupCallThrow(throwable); callBag.addExpect(mockCallable); @@ -129,13 +126,11 @@ final Invocation methodCInvocation = new Invocation(methodCName, methodCArgs); methodA.setExpectedMatches(methodCName, methodCArgs); - methodA.setupAlwaysMatchActiveCall(false); - methodA.invocation.setExpectNothing(); - methodA.setupGetDescription("***methodA-description****"); - methodB.invocation.setExpected(methodCInvocation); - methodB.setupAlwaysMatchActiveCall(false); - methodB.invocation.setExpectNothing(); - methodB.setupGetDescription("***methodB-description****"); + methodA.matches = false; + methodA.callInvocation.setExpectNothing(); + methodB.callInvocation.setExpected(methodCInvocation); + methodB.matches = false; + methodB.callInvocation.setExpectNothing(); callBag.addExpect(methodA); callBag.addExpect(methodB); |
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic
In directory sc8-pr-cvs1:/tmp/cvs-serv7796/src/core/com/mockobjects/dynamic
Modified Files:
AbstractCallableCollection.java CallableList.java CallBag.java
CallableArrayList.java CallSequence.java
Log Message:
Started renaming matches to stubs
Changed ordering so that CallBags search backwards
Started new, cleaner test class for CallBag
Index: AbstractCallableCollection.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/AbstractCallableCollection.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- AbstractCallableCollection.java 6 Jul 2003 23:40:29 -0000 1.3
+++ AbstractCallableCollection.java 9 Jul 2003 02:14:00 -0000 1.4
@@ -5,7 +5,16 @@
abstract public class AbstractCallableCollection implements CallableCollection {
protected CallableList expectedCalls = new CallableArrayList();
- protected CallableList matchingCalls = new CallableArrayList();
+ protected CallableList stubCalls = new CallableArrayList();
+
+ public AbstractCallableCollection() {
+ this(new CallableArrayList(), new CallableArrayList());
+ }
+
+ public AbstractCallableCollection(CallableList expectedCalls, CallableList stubCalls) {
+ this.expectedCalls = expectedCalls;
+ this.stubCalls = stubCalls;
+ }
abstract public String getDescription();
abstract public Object call(Invocation invocation) throws Throwable;
@@ -16,23 +25,23 @@
public void reset() {
expectedCalls.clear();
- matchingCalls.clear();
+ stubCalls.clear();
}
public void addExpect(Callable call) {
- this.expectedCalls.add(call);
+ expectedCalls.add(call);
}
public void addMatch(Callable call) {
- this.matchingCalls.add(call);
+ stubCalls.add(call);
}
public void verify() {
expectedCalls.verify();
}
- protected Callable findMatchingCall(Invocation invocation) throws AssertionFailedError {
- Callable foundCall = matchingCalls.firstMatchingCall(invocation);
+ protected Callable lastStubCall(Invocation invocation) throws AssertionFailedError {
+ Callable foundCall = stubCalls.lastMatchingCall(invocation);
if (foundCall == null) {
throw createUnexpectedCallError(invocation);
}
Index: CallableList.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallableList.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- CallableList.java 6 Jul 2003 23:40:29 -0000 1.3
+++ CallableList.java 9 Jul 2003 02:14:00 -0000 1.4
@@ -18,6 +18,6 @@
Callable get(int index);
int size();
void clear();
- Callable firstMatchingCall(final Invocation invocation);
+ Callable lastMatchingCall(Invocation invocation);
Callable apply(final Handler handler);
}
Index: CallBag.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallBag.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- CallBag.java 6 Jul 2003 23:24:09 -0000 1.8
+++ CallBag.java 9 Jul 2003 02:14:00 -0000 1.9
@@ -5,11 +5,18 @@
public class CallBag extends AbstractCallableCollection {
+ public CallBag() {
+ super();
+ }
+
+ public CallBag(CallableList expectedCalls, CallableList stubCalls) {
+ super(expectedCalls, stubCalls);
+ }
+
public Object call(Invocation invocation) throws Throwable {
-
- Callable foundCall = expectedCalls.firstMatchingCall(invocation);
+ Callable foundCall = expectedCalls.lastMatchingCall(invocation);
if (foundCall == null) {
- foundCall = findMatchingCall(invocation);
+ foundCall = lastStubCall(invocation);
}
return foundCall.call(invocation);
Index: CallableArrayList.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallableArrayList.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CallableArrayList.java 6 Jul 2003 23:40:29 -0000 1.1
+++ CallableArrayList.java 9 Jul 2003 02:14:00 -0000 1.2
@@ -6,46 +6,42 @@
import java.util.ArrayList;
public class CallableArrayList implements CallableList {
- public ArrayList list = new ArrayList();
-
+ private ArrayList callables = new ArrayList();
public void add(Callable callable) {
- list.add(callable);
+ callables.add(callable);
}
public boolean isEmpty() {
- return list.isEmpty();
+ return callables.isEmpty();
}
public Callable get(int index) {
- return (Callable)list.get(index);
+ return (Callable)callables.get(index);
}
public int size() {
- return list.size();
+ return callables.size();
}
public void clear() {
- list.clear();
+ callables.clear();
}
- public Callable firstMatchingCall(final Invocation invocation) {
- return apply(new Handler() {
- public Callable handle(int index, Callable callable) {
- return callable.matches(invocation) ? callable : null;
- }
- });
- }
+ public Callable lastMatchingCall(Invocation invocation) {
+ int index = callables.lastIndexOf(new MatcherHack(invocation));
+ return index > -1 ? get(index) : null;
+ }
- public Callable apply(final CallableList.Handler handler) {
- for (int i = 0; i < list.size(); i++) {
- Callable result = handler.handle(i, (Callable)list.get(i));
+ public Callable apply(final CallableList.Handler handler) {
+ for (int i = 0; i < callables.size(); i++) {
+ Callable result = handler.handle(i, (Callable)callables.get(i));
if (null != result) {
return result;
}
}
return null;
}
-
+
public void verify() {
apply(new Handler() {
public Callable handle(int index, Callable callable) {
@@ -54,4 +50,10 @@
}
});
}
+
+ private class MatcherHack {
+ private Invocation invocation;
+ public MatcherHack(Invocation invocation) {this.invocation = invocation; }
+ public boolean equals(Object obj) { return ((Callable)obj).matches(invocation); }
+ }
}
Index: CallSequence.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallSequence.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- CallSequence.java 6 Jul 2003 23:24:09 -0000 1.10
+++ CallSequence.java 9 Jul 2003 02:14:00 -0000 1.11
@@ -18,7 +18,7 @@
return callable.call(invocation);
}
- return findMatchingCall(invocation).call(invocation);
+ return lastStubCall(invocation).call(invocation);
}
public String getDescription() {
|
|
From: Tim M. <ma...@us...> - 2003-07-07 02:24:29
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic
In directory sc8-pr-cvs1:/tmp/cvs-serv6994/core/test/mockobjects/dynamic
Modified Files:
MockTest.java MockCallableCollection.java
Added Files:
MockCallableFactory.java
Log Message:
Composition of DynamicMock step - 5
MockTests now substantially cleaned up
--- NEW FILE: MockCallableFactory.java ---
package test.mockobjects.dynamic;
import com.mockobjects.*;
import com.mockobjects.dynamic.CallableFactory;
import com.mockobjects.dynamic.Callable;
import com.mockobjects.dynamic.ConstraintMatcher;
public class MockCallableFactory implements CallableFactory{
private ExpectationCounter myCreateCallExpectationCalls = new ExpectationCounter("MockCallableFactory.createCallExpectation(Callable)");
private ReturnValues myActualCreateCallExpectationReturnValues = new ReturnValues("MockCallableFactory.createCallExpectation(Callable)", true);
private ExpectationList myCreateCallExpectationParameter0Values = new ExpectationList("MockCallableFactory.createCallExpectation(Callable) com.mockobjects.dynamic.Callable");
private ExpectationCounter myCreateReturnCallableCalls = new ExpectationCounter("MockCallableFactory.createReturnCallable(String, ConstraintMatcher, Object)");
private ReturnValues myActualCreateReturnCallableReturnValues = new ReturnValues("MockCallableFactory.createReturnCallable(String, ConstraintMatcher, Object)", true);
private ExpectationList myCreateReturnCallableParameter0Values = new ExpectationList("MockCallableFactory.createReturnCallable(String, ConstraintMatcher, Object) java.lang.String");
private ExpectationList myCreateReturnCallableParameter1Values = new ExpectationList("MockCallableFactory.createReturnCallable(String, ConstraintMatcher, Object) com.mockobjects.dynamic.ConstraintMatcher");
private ExpectationList myCreateReturnCallableParameter2Values = new ExpectationList("MockCallableFactory.createReturnCallable(String, ConstraintMatcher, Object) java.lang.Object");
private ExpectationCounter myCreateThrowableCallableCalls = new ExpectationCounter("MockCallableFactory.createThrowableCallable(String, ConstraintMatcher, Throwable)");
private ReturnValues myActualCreateThrowableCallableReturnValues = new ReturnValues("MockCallableFactory.createThrowableCallable(String, ConstraintMatcher, Throwable)", true);
private ExpectationList myCreateThrowableCallableParameter0Values = new ExpectationList("MockCallableFactory.createThrowableCallable(String, ConstraintMatcher, Throwable) java.lang.String");
private ExpectationList myCreateThrowableCallableParameter1Values = new ExpectationList("MockCallableFactory.createThrowableCallable(String, ConstraintMatcher, Throwable) com.mockobjects.dynamic.ConstraintMatcher");
private ExpectationList myCreateThrowableCallableParameter2Values = new ExpectationList("MockCallableFactory.createThrowableCallable(String, ConstraintMatcher, Throwable) java.lang.Throwable");
private ExpectationCounter myCreateVoidCallableCalls = new ExpectationCounter("MockCallableFactory.createVoidCallable(String, ConstraintMatcher)");
private ReturnValues myActualCreateVoidCallableReturnValues = new ReturnValues("MockCallableFactory.createVoidCallable(String, ConstraintMatcher)", true);
private ExpectationList myCreateVoidCallableParameter0Values = new ExpectationList("MockCallableFactory.createVoidCallable(String, ConstraintMatcher) java.lang.String");
private ExpectationList myCreateVoidCallableParameter1Values = new ExpectationList("MockCallableFactory.createVoidCallable(String, ConstraintMatcher) com.mockobjects.dynamic.ConstraintMatcher");
public void setExpectedCreateCallExpectationCalls(int calls){
myCreateCallExpectationCalls.setExpected(calls);
}
public void addExpectedCreateCallExpectation(Callable arg0){
myCreateCallExpectationParameter0Values.addExpected(arg0);
}
public Callable createCallExpectation(Callable arg0){
myCreateCallExpectationCalls.inc();
myCreateCallExpectationParameter0Values.addActual(arg0);
Object nextReturnValue = myActualCreateCallExpectationReturnValues.getNext();
if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException)
throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException();
return (Callable) nextReturnValue;
}
public void setupExceptionCreateCallExpectation(Throwable arg){
myActualCreateCallExpectationReturnValues.add(new ExceptionalReturnValue(arg));
}
public void setupCreateCallExpectation(Callable arg){
myActualCreateCallExpectationReturnValues.add(arg);
}
public void setExpectedCreateReturnCallableCalls(int calls){
myCreateReturnCallableCalls.setExpected(calls);
}
public void addExpectedCreateReturnCallable(String arg0, ConstraintMatcher arg1, Object arg2){
myCreateReturnCallableParameter0Values.addExpected(arg0);
myCreateReturnCallableParameter1Values.addExpected(arg1);
myCreateReturnCallableParameter2Values.addExpected(arg2);
}
public Callable createReturnCallable(String arg0, ConstraintMatcher arg1, Object arg2){
myCreateReturnCallableCalls.inc();
myCreateReturnCallableParameter0Values.addActual(arg0);
myCreateReturnCallableParameter1Values.addActual(arg1);
myCreateReturnCallableParameter2Values.addActual(arg2);
Object nextReturnValue = myActualCreateReturnCallableReturnValues.getNext();
if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException)
throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException();
return (Callable) nextReturnValue;
}
public void setupExceptionCreateReturnCallable(Throwable arg){
myActualCreateReturnCallableReturnValues.add(new ExceptionalReturnValue(arg));
}
public void setupCreateReturnCallable(Callable arg){
myActualCreateReturnCallableReturnValues.add(arg);
}
public void setExpectedCreateThrowableCallableCalls(int calls){
myCreateThrowableCallableCalls.setExpected(calls);
}
public void addExpectedCreateThrowableCallable(String arg0, ConstraintMatcher arg1, Throwable arg2){
myCreateThrowableCallableParameter0Values.addExpected(arg0);
myCreateThrowableCallableParameter1Values.addExpected(arg1);
myCreateThrowableCallableParameter2Values.addExpected(arg2);
}
public Callable createThrowableCallable(String arg0, ConstraintMatcher arg1, Throwable arg2){
myCreateThrowableCallableCalls.inc();
myCreateThrowableCallableParameter0Values.addActual(arg0);
myCreateThrowableCallableParameter1Values.addActual(arg1);
myCreateThrowableCallableParameter2Values.addActual(arg2);
Object nextReturnValue = myActualCreateThrowableCallableReturnValues.getNext();
if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException)
throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException();
return (Callable) nextReturnValue;
}
public void setupExceptionCreateThrowableCallable(Throwable arg){
myActualCreateThrowableCallableReturnValues.add(new ExceptionalReturnValue(arg));
}
public void setupCreateThrowableCallable(Callable arg){
myActualCreateThrowableCallableReturnValues.add(arg);
}
public void setExpectedCreateVoidCallableCalls(int calls){
myCreateVoidCallableCalls.setExpected(calls);
}
public void addExpectedCreateVoidCallable(String arg0, ConstraintMatcher arg1){
myCreateVoidCallableParameter0Values.addExpected(arg0);
myCreateVoidCallableParameter1Values.addExpected(arg1);
}
public Callable createVoidCallable(String arg0, ConstraintMatcher arg1){
myCreateVoidCallableCalls.inc();
myCreateVoidCallableParameter0Values.addActual(arg0);
myCreateVoidCallableParameter1Values.addActual(arg1);
Object nextReturnValue = myActualCreateVoidCallableReturnValues.getNext();
if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException)
throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException();
return (Callable) nextReturnValue;
}
public void setupExceptionCreateVoidCallable(Throwable arg){
myActualCreateVoidCallableReturnValues.add(new ExceptionalReturnValue(arg));
}
public void setupCreateVoidCallable(Callable arg){
myActualCreateVoidCallableReturnValues.add(arg);
}
public void verify(){
myCreateCallExpectationCalls.verify();
myCreateCallExpectationParameter0Values.verify();
myCreateReturnCallableCalls.verify();
myCreateReturnCallableParameter0Values.verify();
myCreateReturnCallableParameter1Values.verify();
myCreateReturnCallableParameter2Values.verify();
myCreateThrowableCallableCalls.verify();
myCreateThrowableCallableParameter0Values.verify();
//
myCreateThrowableCallableParameter1Values.verify();
myCreateThrowableCallableParameter2Values.verify();
myCreateVoidCallableCalls.verify();
myCreateVoidCallableParameter0Values.verify();
myCreateVoidCallableParameter1Values.verify();
}
}
Index: MockTest.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockTest.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- MockTest.java 7 Jul 2003 00:19:33 -0000 1.16
+++ MockTest.java 7 Jul 2003 02:24:26 -0000 1.17
@@ -1,9 +1,6 @@
-/*
- * Created on 04-Apr-2003
- */
package test.mockobjects.dynamic;
-import com.mockobjects.constraint.*;
+import com.mockobjects.constraint.Constraint;
import com.mockobjects.constraint.IsEqual;
import com.mockobjects.dynamic.*;
import com.mockobjects.util.*;
@@ -13,348 +10,241 @@
public class MockTest extends TestCase {
private static final String MOCK_NAME = "Test mock";
- final String METHOD_NOARG_NAME = "noArgMethodVoid";
- final String METHOD_NOARGANDRETURN_NAME = "noArgMethod";
- final String METHOD_NOARGANDRETURN_RESULT = "resultNoArgs";
- final String METHOD_ONEARG_NAME = "oneArgMethod";
- final String METHOD_ONEARG_RESULT = "result1Args";
- final String METHOD_TWOARG_NAME = "twoArgMethod";
- final String METHOD_TWOARG_RESULT = "resultTwoArgs";
+
final Throwable METHOD_EXCEPTION = new DummyThrowable("Configured test throwable");
- final Object[] METHOD_NOARG_ARGS = new Object[0];
- final String[] METHOD_ONEARG_ARGS = new String[] { "oneP1" };
final ConstraintMatcher METHOD_ONEARG_CONSTRAINTS = C.args(C.eq("oneP1"));
- final String[] METHOD_TWOARG_ARGS = new String[] { "twoP1", "twoP2" };
final ConstraintMatcher METHOD_TWOARG_CONSTRAINTS = C.args(C.eq("twoP1"), C.eq("twoP2"));
+
private DummyInterface proxy;
private Mock mock;
- private MockCallFactory mockCallFactory = new MockCallFactory();
- private MockCallable mockCallMatch = new MockCallable("call match");
- private MockCallable mockExpectedCall = new MockCallable("expected call");
- private MockCallable mockReturnStub = new MockCallable("return stub");
- private MockCallable mockThrowStub = new MockCallable("throw stub");
- private MockCallable mockVoidStub = new MockCallable("void stub");
+ private MockCallableFactory mockCallableFactory = new MockCallableFactory();
+
private MockCallableCollection mockCallables = new MockCallableCollection();
+ private MockCallable mockCall = new MockCallable("call match");
public MockTest(String name) throws Exception {
super(name);
}
public void setUp() {
- mock = new Mock(mockCallFactory, mockCallables, DummyInterface.class, MOCK_NAME);
+ mock = new Mock(mockCallableFactory, mockCallables, DummyInterface.class, MOCK_NAME);
try {
proxy = (DummyInterface)mock.proxy();
} catch (ClassCastException ex) {
fail("proxy is not of expected interface type");
}
-
- mockCallFactory.setupCreateReturnStub(mockReturnStub);
- mockCallFactory.setupCreateVoidStub(mockVoidStub);
- mockCallFactory.setupCreateThrowStub(mockThrowStub);
+
+ mockCallableFactory.setupCreateCallExpectation(mockCall);
}
public void testExpectManyAndVoid() throws Throwable {
- mockCallFactory.setupCreateCallSignature(mockCallMatch);
- mockCallFactory.setupCreateCallExpectation(mockExpectedCall);
-
- mockCallFactory.setExpectedCreateVoidStubCalls(1);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockVoidStub);
- mockCallFactory.addExpectedCreateCallExpectation(mockCallMatch);
-
- mockCallables.expectedCallables.addExpected(mockExpectedCall);
-
- mock.expect(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS);
-
+ mockCallableFactory.addExpectedCreateVoidCallable(DummyInterface.METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS);
+ mockCallableFactory.setupCreateVoidCallable(mockCall);
+ mockCallableFactory.addExpectedCreateCallExpectation(mockCall);
+ mockCallables.addExpectedExpect(mockCall);
+
+ mock.expect(DummyInterface.METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS);
+
Verifier.verifyObject(this);
- mockCallables.verifyExpectations();
}
public void testExpectNoneAndReturn() throws Throwable {
- mockCallFactory.setupCreateCallSignature(mockCallMatch);
- mockCallFactory.setupCreateCallExpectation(mockExpectedCall);
-
- mockCallFactory.createReturnStub.setExpected(METHOD_NOARGANDRETURN_RESULT);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_NOARGANDRETURN_NAME, C.NO_ARGS, mockReturnStub);
- mockCallFactory.addExpectedCreateCallExpectation(mockCallMatch);
+ mockCallableFactory.addExpectedCreateReturnCallable(DummyInterface.METHOD_NOARG_NAME, C.NO_ARGS, DummyInterface.METHOD_NOARG_RESULT);
+ mockCallableFactory.setupCreateReturnCallable(mockCall);
+ mockCallableFactory.addExpectedCreateCallExpectation(mockCall);
+ mockCallables.addExpectedExpect(mockCall);
+
+ mock.expectAndReturn(DummyInterface.METHOD_NOARG_NAME, DummyInterface.METHOD_NOARG_RESULT);
- mockCallables.expectedCallables.addExpected(mockExpectedCall);
-
- mock.expectAndReturn(METHOD_NOARGANDRETURN_NAME, METHOD_NOARGANDRETURN_RESULT);
-
Verifier.verifyObject(this);
- mockCallables.verifyExpectations();
}
public void testExpectNoneAndThrow() throws Throwable {
- mockCallFactory.setupCreateCallSignature(mockCallMatch);
- mockCallFactory.setupCreateCallExpectation(mockExpectedCall);
-
- mockCallFactory.createThrowStub.setExpected(METHOD_EXCEPTION);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_NOARGANDRETURN_NAME, C.NO_ARGS, mockThrowStub);
- mockCallFactory.addExpectedCreateCallExpectation(mockCallMatch);
+ mockCallableFactory.addExpectedCreateThrowableCallable(DummyInterface.METHOD_NOARG_NAME, C.NO_ARGS, METHOD_EXCEPTION);
+ mockCallableFactory.setupCreateThrowableCallable(mockCall);
+ mockCallableFactory.addExpectedCreateCallExpectation(mockCall);
+ mockCallables.addExpectedExpect(mockCall);
- mockCallables.expectedCallables.addExpected(mockExpectedCall);
-
- mock.expectAndThrow(METHOD_NOARGANDRETURN_NAME, METHOD_EXCEPTION);
+ mock.expectAndThrow(DummyInterface.METHOD_NOARG_NAME, METHOD_EXCEPTION);
Verifier.verifyObject(this);
- mockCallables.verifyExpectations();
}
public void testExpectOneAndThrow() throws Throwable {
- mockCallFactory.setupCreateCallSignature(mockCallMatch);
- mockCallFactory.setupCreateCallExpectation(mockExpectedCall);
-
- mockCallFactory.createThrowStub.setExpected(METHOD_EXCEPTION);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockThrowStub);
- mockCallFactory.addExpectedCreateCallExpectation(mockCallMatch);
+ mockCallableFactory.addExpectedCreateThrowableCallable(DummyInterface.METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, METHOD_EXCEPTION);
+ mockCallableFactory.setupCreateThrowableCallable(mockCall);
+ mockCallableFactory.addExpectedCreateCallExpectation(mockCall);
+ mockCallables.addExpectedExpect(mockCall);
- mockCallables.expectedCallables.addExpected(mockExpectedCall);
-
- mock.expectAndThrow(METHOD_ONEARG_NAME, METHOD_ONEARG_ARGS[0], METHOD_EXCEPTION);
+ mock.expectAndThrow(DummyInterface.METHOD_ONEARG_NAME, DummyInterface.METHOD_ONEARG_ARGS[0], METHOD_EXCEPTION);
Verifier.verifyObject(this);
- mockCallables.verifyExpectations();
}
public void testExpectNoneAndVoid() throws Throwable {
- mockCallFactory.setupCreateCallSignature(mockCallMatch);
- mockCallFactory.setupCreateCallExpectation(mockExpectedCall);
-
- mockCallFactory.setExpectedCreateVoidStubCalls(1);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_NOARG_NAME, C.NO_ARGS, mockVoidStub);
- mockCallFactory.addExpectedCreateCallExpectation(mockCallMatch);
-
- mockCallables.expectedCallables.addExpected(mockExpectedCall);
+ mockCallableFactory.addExpectedCreateVoidCallable(DummyInterface.METHOD_NOARG_NAME, C.NO_ARGS);
+ mockCallableFactory.setupCreateVoidCallable(mockCall);
+ mockCallableFactory.addExpectedCreateCallExpectation(mockCall);
+ mockCallables.addExpectedExpect(mockCall);
- mock.expect(METHOD_NOARG_NAME);
+ mock.expect(DummyInterface.METHOD_NOARG_NAME);
Verifier.verifyObject(this);
- mockCallables.verifyExpectations();
}
public void testExpectOneAndVoid() throws Throwable {
- mockCallFactory.setupCreateCallSignature(mockCallMatch);
- mockCallFactory.setupCreateCallExpectation(mockExpectedCall);
-
- mockCallFactory.setExpectedCreateVoidStubCalls(1);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockVoidStub);
- mockCallFactory.addExpectedCreateCallExpectation(mockCallMatch);
-
- mockCallables.expectedCallables.addExpected(mockExpectedCall);
-
- mock.expect(METHOD_ONEARG_NAME, METHOD_ONEARG_ARGS[0]);
-
- Verifier.verifyObject(this);
- mockCallables.verifyExpectations();
- }
+ mockCallableFactory.addExpectedCreateVoidCallable(DummyInterface.METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS);
+ mockCallableFactory.setupCreateVoidCallable(mockCall);
+ mockCallableFactory.addExpectedCreateCallExpectation(mockCall);
+ mockCallables.addExpectedExpect(mockCall);
- public void testExpectWithConstraint() throws Throwable {
- mockCallFactory.setupCreateCallSignature(mockCallMatch);
- mockCallFactory.setupCreateCallExpectation(mockExpectedCall);
-
- mockCallFactory.addExpectedCreateCallSignature(METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockVoidStub);
- mockCallables.expectedCallables.addExpected(mockExpectedCall);
-
- mock.expect(METHOD_ONEARG_NAME, new IsEqual(METHOD_ONEARG_ARGS[0]));
-
- Verifier.verifyObject(this);
- mockCallables.verifyExpectations();
- }
+ mock.expect(DummyInterface.METHOD_ONEARG_NAME, DummyInterface.METHOD_ONEARG_ARGS[0]);
- public void testExpectWithConstraintArray() throws Throwable {
- mockCallFactory.setupCreateCallSignature(mockCallMatch);
- mockCallFactory.setupCreateCallExpectation(mockExpectedCall);
-
- mockCallFactory.addExpectedCreateCallSignature(METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockVoidStub);
- mockCallables.expectedCallables.addExpected(mockExpectedCall);
-
- mock.expect(METHOD_ONEARG_NAME, new Constraint[] { new IsEqual(METHOD_ONEARG_ARGS[0])});
-
Verifier.verifyObject(this);
- mockCallables.verifyExpectations();
}
-
-
+
public void testExpectManyAndReturn() throws Throwable {
- mockCallFactory.setupCreateCallSignature(mockCallMatch);
- mockCallFactory.setupCreateCallExpectation(mockExpectedCall);
-
- mockCallFactory.createReturnStub.setExpected(METHOD_TWOARG_RESULT);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockReturnStub);
- mockCallFactory.addExpectedCreateCallExpectation(mockCallMatch);
-
- mockCallables.expectedCallables.addExpected(mockExpectedCall);
- mockCallables.setupCall(METHOD_TWOARG_RESULT);
-
- mock.expectAndReturn(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, METHOD_TWOARG_RESULT);
+ mockCallableFactory.addExpectedCreateReturnCallable(DummyInterface.METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, DummyInterface.METHOD_TWOARG_RESULT);
+ mockCallableFactory.setupCreateReturnCallable(mockCall);
+ mockCallableFactory.addExpectedCreateCallExpectation(mockCall);
+ mockCallables.addExpectedExpect(mockCall);
+
+ mock.expectAndReturn(DummyInterface.METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, DummyInterface.METHOD_TWOARG_RESULT);
Verifier.verifyObject(this);
- mockCallables.verifyExpectations();
}
public void testExpectManyAndThrow() throws Throwable {
- mockCallFactory.setupCreateCallSignature(mockCallMatch);
- mockCallFactory.setupCreateCallExpectation(mockExpectedCall);
-
- mockCallFactory.createThrowStub.setExpected(METHOD_EXCEPTION);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockThrowStub);
- mockCallFactory.addExpectedCreateCallExpectation(mockCallMatch);
+ mockCallableFactory.addExpectedCreateThrowableCallable(DummyInterface.METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, METHOD_EXCEPTION);
+ mockCallableFactory.setupCreateThrowableCallable(mockCall);
+ mockCallableFactory.addExpectedCreateCallExpectation(mockCall);
+ mockCallables.addExpectedExpect(mockCall);
- mockCallables.expectedCallables.addExpected(mockExpectedCall);
- mockCallables.setupCall(METHOD_TWOARG_RESULT);
-
- mock.expectAndThrow(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, METHOD_EXCEPTION);
+ mock.expectAndThrow(DummyInterface.METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, METHOD_EXCEPTION);
Verifier.verifyObject(this);
- mockCallables.verifyExpectations();
}
public void testExpectOneAndReturn() throws Throwable {
- mockCallFactory.setupCreateCallSignature(mockCallMatch);
- mockCallFactory.setupCreateCallExpectation(mockExpectedCall);
-
- mockCallFactory.createReturnStub.setExpected(METHOD_ONEARG_RESULT);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockReturnStub);
- mockCallFactory.addExpectedCreateCallExpectation(mockCallMatch);
-
- mockCallables.expectedCallables.addExpected(mockExpectedCall);
- mockCallables.setupCall(METHOD_ONEARG_RESULT);
-
- mock.expectAndReturn(METHOD_ONEARG_NAME, METHOD_ONEARG_ARGS[0], METHOD_ONEARG_RESULT);
+ mockCallableFactory.addExpectedCreateReturnCallable(DummyInterface.METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, DummyInterface.METHOD_ONEARG_RESULT);
+ mockCallableFactory.setupCreateReturnCallable(mockCall);
+ mockCallableFactory.addExpectedCreateCallExpectation(mockCall);
+ mockCallables.addExpectedExpect(mockCall);
+
+ mock.expectAndReturn(DummyInterface.METHOD_ONEARG_NAME, DummyInterface.METHOD_ONEARG_ARGS[0], DummyInterface.METHOD_ONEARG_RESULT);
Verifier.verifyObject(this);
- mockCallables.verifyExpectations();
}
public void testMatchNoneAndVoid() throws Throwable {
- mockCallFactory.setupCreateCallSignature(mockCallMatch);
- mockCallables.setupCall(METHOD_NOARGANDRETURN_RESULT);
-
- mockCallFactory.setExpectedCreateVoidStubCalls(1);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_NOARG_NAME, C.NO_ARGS, mockVoidStub);
+ mockCallableFactory.addExpectedCreateVoidCallable(DummyInterface.METHOD_NOARG_NAME, C.NO_ARGS);
+ mockCallableFactory.setupCreateVoidCallable(mockCall);
+ mockCallables.addExpectedMatch(mockCall);
- mockCallables.matchedCallables.addExpected(mockCallMatch);
-
- mock.match(METHOD_NOARG_NAME);
+ mock.match(DummyInterface.METHOD_NOARG_NAME);
Verifier.verifyObject(this);
- mockCallables.verifyExpectations();
}
public void testMatchNoneAndReturn() throws Throwable {
- mockCallFactory.setupCreateCallSignature(mockCallMatch);
- mockCallables.setupCall(METHOD_ONEARG_RESULT);
-
- mockCallFactory.createReturnStub.setExpected(METHOD_NOARGANDRETURN_RESULT);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_NOARG_NAME, C.NO_ARGS, mockReturnStub);
-
- mockCallables.matchedCallables.addExpected(mockCallMatch);
-
- mock.matchAndReturn(METHOD_NOARG_NAME, METHOD_NOARGANDRETURN_RESULT);
-
+ mockCallableFactory.addExpectedCreateReturnCallable(DummyInterface.METHOD_NOARG_NAME, C.NO_ARGS, DummyInterface.METHOD_NOARG_RESULT);
+ mockCallableFactory.setupCreateReturnCallable(mockCall);
+ mockCallables.addExpectedMatch(mockCall);
+
+ mock.matchAndReturn(DummyInterface.METHOD_NOARG_NAME, DummyInterface.METHOD_NOARG_RESULT);
+
Verifier.verifyObject(this);
- mockCallables.verifyExpectations();
}
public void testMatchNoneAndThrow() throws Throwable {
- mockCallFactory.setupCreateThrowStub(mockThrowStub);
- mockCallFactory.setupCreateCallSignature(mockCallMatch);
-
- mockCallFactory.createThrowStub.setExpected(METHOD_EXCEPTION);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_NOARG_NAME, C.NO_ARGS, mockThrowStub);
+ mockCallableFactory.addExpectedCreateThrowableCallable(DummyInterface.METHOD_NOARG_NAME, C.NO_ARGS, METHOD_EXCEPTION);
+ mockCallableFactory.setupCreateThrowableCallable(mockCall);
+ mockCallables.addExpectedMatch(mockCall);
- mockCallables.matchedCallables.addExpected(mockCallMatch);
- mockCallables.setupCall(METHOD_NOARGANDRETURN_RESULT);
-
- mock.matchAndThrow(METHOD_NOARG_NAME, METHOD_EXCEPTION);
+ mock.matchAndThrow(DummyInterface.METHOD_NOARG_NAME, METHOD_EXCEPTION);
Verifier.verifyObject(this);
- mockCallables.verifyExpectations();
}
public void testMatchOneAndVoid() throws Throwable {
- mockCallFactory.setExpectedCreateVoidStubCalls(1);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockVoidStub);
- mockCallFactory.setupCreateCallSignature(mockCallMatch);
- mockCallFactory.addExpectedCreateCallExpectation(mockCallMatch);
- mockCallFactory.setupCreateCallExpectation(mockExpectedCall);
-
- mockCallables.matchedCallables.addExpected(mockCallMatch);
-
- mock.match(METHOD_ONEARG_NAME, METHOD_ONEARG_ARGS[0]);
-
+ mockCallableFactory.addExpectedCreateVoidCallable(DummyInterface.METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS);
+ mockCallableFactory.setupCreateVoidCallable(mockCall);
+ mockCallables.addExpectedMatch(mockCall);
+
+ mock.match(DummyInterface.METHOD_ONEARG_NAME, DummyInterface.METHOD_ONEARG_ARGS[0]);
+
Verifier.verifyObject(this);
- mockCallables.verifyExpectations();
}
public void testMatchOneAndReturn() throws Throwable {
- mockCallFactory.createReturnStub.setExpected(METHOD_ONEARG_RESULT);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockReturnStub);
- mockCallFactory.setupCreateCallSignature(mockCallMatch);
-
- mockCallables.matchedCallables.addExpected(mockCallMatch);
- mockCallables.setupCall(METHOD_ONEARG_RESULT);
-
- mock.matchAndReturn(METHOD_ONEARG_NAME, METHOD_ONEARG_ARGS[0], METHOD_ONEARG_RESULT);
+ mockCallableFactory.addExpectedCreateReturnCallable(DummyInterface.METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, DummyInterface.METHOD_ONEARG_RESULT);
+ mockCallableFactory.setupCreateReturnCallable(mockCall);
+ mockCallables.addExpectedMatch(mockCall);
+
+ mock.matchAndReturn(DummyInterface.METHOD_ONEARG_NAME, DummyInterface.METHOD_ONEARG_ARGS[0], DummyInterface.METHOD_ONEARG_RESULT);
Verifier.verifyObject(this);
- mockCallables.verifyExpectations();
}
public void testMatchOneAndThrow() throws Throwable {
- mockCallFactory.createThrowStub.setExpected(METHOD_EXCEPTION);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockThrowStub);
- mockCallFactory.setupCreateCallSignature(mockCallMatch);
-
- mockCallables.matchedCallables.addExpected(mockCallMatch);
- mockCallables.setupCall(METHOD_ONEARG_RESULT);
+ mockCallableFactory.addExpectedCreateThrowableCallable(DummyInterface.METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, METHOD_EXCEPTION);
+ mockCallableFactory.setupCreateThrowableCallable(mockCall);
+ mockCallables.addExpectedMatch(mockCall);
- mock.matchAndThrow(METHOD_ONEARG_NAME, METHOD_ONEARG_ARGS[0], METHOD_EXCEPTION);
+ mock.matchAndThrow(DummyInterface.METHOD_ONEARG_NAME, DummyInterface.METHOD_ONEARG_ARGS[0], METHOD_EXCEPTION);
Verifier.verifyObject(this);
- mockCallables.verifyExpectations();
}
public void testMatchManyAndVoid() throws Throwable {
- mockCallFactory.setExpectedCreateVoidStubCalls(1);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockVoidStub);
- mockCallFactory.setupCreateCallSignature(mockCallMatch);
- mockCallFactory.addExpectedCreateCallExpectation(mockCallMatch);
- mockCallFactory.setupCreateCallExpectation(mockExpectedCall);
-
- mockCallables.matchedCallables.addExpected(mockCallMatch);
-
- mock.match(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS);
-
+ mockCallableFactory.addExpectedCreateVoidCallable(DummyInterface.METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS);
+ mockCallableFactory.setupCreateVoidCallable(mockCall);
+ mockCallables.addExpectedMatch(mockCall);
+
+ mock.match(DummyInterface.METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS);
+
Verifier.verifyObject(this);
- mockCallables.verifyExpectations();
}
public void testMatchManyAndReturn() throws Throwable {
- mockCallFactory.createReturnStub.setExpected(METHOD_TWOARG_RESULT);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockReturnStub);
- mockCallFactory.setupCreateCallSignature(mockCallMatch);
-
- mockCallables.matchedCallables.addExpected(mockCallMatch);
- mockCallables.setupCall(METHOD_TWOARG_RESULT);
-
- mock.matchAndReturn(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, METHOD_TWOARG_RESULT);
+ mockCallableFactory.addExpectedCreateReturnCallable(DummyInterface.METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, DummyInterface.METHOD_TWOARG_RESULT);
+ mockCallableFactory.setupCreateReturnCallable(mockCall);
+ mockCallables.addExpectedMatch(mockCall);
+
+ mock.matchAndReturn(DummyInterface.METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, DummyInterface.METHOD_TWOARG_RESULT);
Verifier.verifyObject(this);
- mockCallables.verifyExpectations();
}
public void testMatchManyAndThrow() throws Throwable {
- mockCallFactory.createThrowStub.setExpected(METHOD_EXCEPTION);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockThrowStub);
- mockCallFactory.setupCreateCallSignature(mockCallMatch);
+ mockCallableFactory.addExpectedCreateThrowableCallable(DummyInterface.METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, METHOD_EXCEPTION);
+ mockCallableFactory.setupCreateThrowableCallable(mockCall);
+ mockCallables.addExpectedMatch(mockCall);
+
+ mock.matchAndThrow(DummyInterface.METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, METHOD_EXCEPTION);
- mockCallables.matchedCallables.addExpected(mockCallMatch);
- mockCallables.setupCall(METHOD_TWOARG_RESULT);
+ Verifier.verifyObject(this);
+ }
+
+ public void testExpectWithConstraint() throws Throwable {
+ mockCallableFactory.addExpectedCreateVoidCallable(DummyInterface.METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS);
+ mockCallableFactory.setupCreateVoidCallable(mockCall);
+ mockCallableFactory.addExpectedCreateCallExpectation(mockCall);
+ mockCallables.addExpectedExpect(mockCall);
+
+ mock.expect(DummyInterface.METHOD_ONEARG_NAME, new IsEqual(DummyInterface.METHOD_ONEARG_ARGS[0]));
- mock.matchAndThrow(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, METHOD_EXCEPTION);
+ Verifier.verifyObject(this);
+ }
+
+ public void testExpectWithConstraintArray() throws Throwable {
+ mockCallableFactory.addExpectedCreateVoidCallable(DummyInterface.METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS);
+ mockCallableFactory.setupCreateVoidCallable(mockCall);
+ mockCallableFactory.addExpectedCreateCallExpectation(mockCall);
+ mockCallables.addExpectedExpect(mockCall);
+
+ mock.expect(DummyInterface.METHOD_ONEARG_NAME, new Constraint[] { new IsEqual(DummyInterface.METHOD_ONEARG_ARGS[0])});
Verifier.verifyObject(this);
mockCallables.verifyExpectations();
Index: MockCallableCollection.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockCallableCollection.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- MockCallableCollection.java 7 Jul 2003 00:19:33 -0000 1.3
+++ MockCallableCollection.java 7 Jul 2003 02:24:26 -0000 1.4
@@ -33,11 +33,19 @@
public void addMatch(Callable callable) {
matchedCallables.addActual(callable);
}
+
+ public void addExpectedMatch(Callable callable) {
+ matchedCallables.addExpected(callable);
+ }
public void addExpect(Callable callable) {
expectedCallables.addActual(callable);
}
+ public void addExpectedExpect(Callable callable) {
+ expectedCallables.addExpected(callable);
+ }
+
public void setExpectedMatchesCalls(int calls) {
myMatchesCalls.setExpected(calls);
}
|
|
From: Tim M. <ma...@us...> - 2003-07-07 02:24:29
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic
In directory sc8-pr-cvs1:/tmp/cvs-serv6994/core/com/mockobjects/dynamic
Modified Files:
FullConstraintMatcher.java
Log Message:
Composition of DynamicMock step - 5
MockTests now substantially cleaned up
Index: FullConstraintMatcher.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/FullConstraintMatcher.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- FullConstraintMatcher.java 18 May 2003 20:59:35 -0000 1.2
+++ FullConstraintMatcher.java 7 Jul 2003 02:24:26 -0000 1.3
@@ -40,4 +40,12 @@
return constraints;
}
+ //For testing
+ public boolean equals(Object o) {
+ if(o instanceof ConstraintMatcher) {
+ return matches(((ConstraintMatcher)o).getConstraints());
+ } else {
+ return false;
+ }
+ }
}
|
|
From: Tim M. <ma...@us...> - 2003-07-07 01:19:23
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic
In directory sc8-pr-cvs1:/tmp/cvs-serv350/core/com/mockobjects/dynamic
Modified Files:
Mock.java
Log Message:
Composition of DynamicMock step - 4
Mock now composes a core
Index: Mock.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Mock.java,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- Mock.java 7 Jul 2003 01:17:57 -0000 1.30
+++ Mock.java 7 Jul 2003 01:19:21 -0000 1.31
@@ -2,6 +2,7 @@
import junit.framework.AssertionFailedError;
+import com.mockobjects.Verifiable;
import com.mockobjects.constraint.Constraint;
public class Mock implements Verifiable {
|
|
From: Tim M. <ma...@us...> - 2003-07-07 01:17:59
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic
In directory sc8-pr-cvs1:/tmp/cvs-serv32562/core/com/mockobjects/dynamic
Modified Files:
CallOnceExpectation.java Mock.java CoreMock.java
DynamicMock.java CallSignature.java
Log Message:
Composition of DynamicMock step - 4
Mock now composes a core
Index: CallOnceExpectation.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallOnceExpectation.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- CallOnceExpectation.java 6 Jul 2003 23:24:09 -0000 1.4
+++ CallOnceExpectation.java 7 Jul 2003 01:17:57 -0000 1.5
@@ -33,6 +33,6 @@
// Implemented to aid visualisation in an IDE debugger
public String toString() {
- return Mock.className(this.getClass()) + "(" + this.getDescription() + ")";
+ return CoreMock.className(this.getClass()) + "(" + this.getDescription() + ")";
}
}
Index: Mock.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Mock.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- Mock.java 7 Jul 2003 00:19:33 -0000 1.29
+++ Mock.java 7 Jul 2003 01:17:57 -0000 1.30
@@ -4,11 +4,12 @@
import com.mockobjects.constraint.Constraint;
-public class Mock extends CoreMock {
+public class Mock implements Verifiable {
private CallableFactory callableFactory;
+ private DynamicMock coreMock;
public Mock(CallableFactory callableFactory, CallableCollection callables, Class mockedClass, String name) {
- super(mockedClass, name, callables);
+ coreMock = new CoreMock(mockedClass, name, callables);
this.callableFactory = callableFactory;
}
@@ -18,7 +19,7 @@
}
public Mock(Class mockedClass) {
- this(mockedClass, mockNameFromClass(mockedClass));
+ this(mockedClass, CoreMock.mockNameFromClass(mockedClass));
}
private ConstraintMatcher createConstraintMatcher(Object constraintArg) {
@@ -46,7 +47,7 @@
}
public void expect(String methodName, ConstraintMatcher args) {
- this.expect(callableFactory.createCallExpectation(callableFactory.createVoidCallable(methodName, args)));
+ coreMock.expect(callableFactory.createCallExpectation(callableFactory.createVoidCallable(methodName, args)));
}
public void expectAndReturn(String methodName, Object result) {
@@ -82,7 +83,7 @@
}
public void expectAndReturn(String methodName, ConstraintMatcher args, Object result) {
- this.expect(callableFactory.createCallExpectation(callableFactory.createReturnCallable(methodName, args, result)));
+ coreMock.expect(callableFactory.createCallExpectation(callableFactory.createReturnCallable(methodName, args, result)));
}
public void expectAndThrow(String methodName, Throwable exception) {
@@ -94,7 +95,7 @@
}
public void expectAndThrow(String methodName, ConstraintMatcher args, Throwable exception) {
- this.expect(callableFactory.createCallExpectation(callableFactory.createThrowableCallable(methodName, args, exception)));
+ coreMock.expect(callableFactory.createCallExpectation(callableFactory.createThrowableCallable(methodName, args, exception)));
}
public void match(String methodName) {
@@ -114,7 +115,7 @@
}
public void match(String methodName, ConstraintMatcher args) {
- this.stub(callableFactory.createVoidCallable(methodName, args));
+ coreMock.stub(callableFactory.createVoidCallable(methodName, args));
}
public void matchAndReturn(String methodName, Object result) {
@@ -158,7 +159,7 @@
}
public void matchAndReturn(String methodName, ConstraintMatcher args, Object result) {
- this.stub(callableFactory.createReturnCallable(methodName, args, result));
+ coreMock.stub(callableFactory.createReturnCallable(methodName, args, result));
}
public void matchAndThrow(String methodName, Throwable throwable) {
@@ -178,7 +179,7 @@
}
public void matchAndThrow(String methodName, ConstraintMatcher args, Throwable throwable) {
- this.stub(callableFactory.createThrowableCallable(methodName, args, throwable));
+ coreMock.stub(callableFactory.createThrowableCallable(methodName, args, throwable));
}
/** @deprecated @see OrderedMock
@@ -220,6 +221,18 @@
/** @deprecated Not required, as if methodName is called, you will get an exception
*/
public void expectNotCalled(String methodName) {
+ }
+
+ public Object proxy() {
+ return coreMock.proxy();
+ }
+
+ public void reset() {
+ coreMock.reset();
+ }
+
+ public void verify() {
+ coreMock.verify();
}
}
Index: CoreMock.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CoreMock.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- CoreMock.java 7 Jul 2003 00:19:33 -0000 1.4
+++ CoreMock.java 7 Jul 2003 01:17:57 -0000 1.5
@@ -1,15 +1,12 @@
package com.mockobjects.dynamic;
-import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
-import com.mockobjects.Verifiable;
-
import junit.framework.AssertionFailedError;
-public class CoreMock implements DynamicMock, InvocationHandler, Verifiable {
+public class CoreMock implements DynamicMock {
private CallableCollection invocationMatchers;
private Object proxy;
private String name;
Index: DynamicMock.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/DynamicMock.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DynamicMock.java 6 Jul 2003 23:06:12 -0000 1.1
+++ DynamicMock.java 7 Jul 2003 01:17:57 -0000 1.2
@@ -1,7 +1,13 @@
package com.mockobjects.dynamic;
-public interface DynamicMock {
+import java.lang.reflect.InvocationHandler;
+
+import com.mockobjects.Verifiable;
+
+public interface DynamicMock extends Verifiable, InvocationHandler {
void expect(Callable invocationMatcher);
void stub(Callable invocationMatcher);
+ Object proxy();
+
void reset();
}
Index: CallSignature.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallSignature.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- CallSignature.java 6 Jul 2003 23:24:09 -0000 1.5
+++ CallSignature.java 7 Jul 2003 01:17:57 -0000 1.6
@@ -32,6 +32,6 @@
// Implemented to aid visualisation in an IDE debugger
public String toString() {
- return Mock.className(this.getClass()) + "(" + this.getDescription() + ")";
+ return CoreMock.className(this.getClass()) + "(" + this.getDescription() + ")";
}
}
|
|
From: Tim M. <ma...@us...> - 2003-07-07 00:19:36
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic
In directory sc8-pr-cvs1:/tmp/cvs-serv26152/core/com/mockobjects/dynamic
Modified Files:
OrderedMock.java Mock.java CoreMock.java
Log Message:
Composition of DynamicMock step - 3
Separated CoreTests from MockTests
Index: OrderedMock.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/OrderedMock.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- OrderedMock.java 10 Jun 2003 17:07:45 -0000 1.3
+++ OrderedMock.java 7 Jul 2003 00:19:33 -0000 1.4
@@ -6,7 +6,7 @@
public class OrderedMock extends Mock {
public OrderedMock(Class mockedClass) {
- this(mockedClass, mockNameFromClass(mockedClass));
+ super(mockedClass);
}
public OrderedMock(Class mockedClass, String name) {
Index: Mock.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Mock.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- Mock.java 6 Jul 2003 23:06:12 -0000 1.28
+++ Mock.java 7 Jul 2003 00:19:33 -0000 1.29
@@ -21,22 +21,7 @@
this(mockedClass, mockNameFromClass(mockedClass));
}
- public static String mockNameFromClass(Class c) {
- return "mock" + className(c);
- }
-
- public static String className(Class c) {
- String name = c.getName();
- int dotIndex = name.lastIndexOf('.');
-
- if (dotIndex >= 0) {
- return name.substring(dotIndex + 1);
- } else {
- return name;
- }
- }
-
- private ConstraintMatcher createConstraintMatcher(Object constraintArg) {
+ private ConstraintMatcher createConstraintMatcher(Object constraintArg) {
// Can't overload this method as callee had an Object parameter, and java
// doesn't do a secondary dispatch on the true underlying type
Index: CoreMock.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CoreMock.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- CoreMock.java 6 Jul 2003 23:24:09 -0000 1.3
+++ CoreMock.java 7 Jul 2003 00:19:33 -0000 1.4
@@ -78,4 +78,19 @@
this.invocationMatchers.reset();
}
+ public static String mockNameFromClass(Class c) {
+ return "mock" + className(c);
+ }
+
+ public static String className(Class c) {
+ String name = c.getName();
+ int dotIndex = name.lastIndexOf('.');
+
+ if (dotIndex >= 0) {
+ return name.substring(dotIndex + 1);
+ } else {
+ return name;
+ }
+ }
+
}
|
|
From: Tim M. <ma...@us...> - 2003-07-07 00:19:36
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic
In directory sc8-pr-cvs1:/tmp/cvs-serv26152/core/test/mockobjects/dynamic
Modified Files:
MockTest.java MockCallableCollection.java DummyInterface.java
Added Files:
CoreMockTest.java
Log Message:
Composition of DynamicMock step - 3
Separated CoreTests from MockTests
--- NEW FILE: CoreMockTest.java ---
/*
* Created on 07-Jul-2003
*/
package test.mockobjects.dynamic;
import com.mockobjects.dynamic.CoreMock;
import com.mockobjects.dynamic.DynamicUtil;
import com.mockobjects.util.AssertMo;
import com.mockobjects.util.Verifier;
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
public class CoreMockTest extends TestCase {
private static final String MOCK_NAME = "Test mock";
private DummyInterface proxy;
private CoreMock mock;
private MockCallableCollection mockCallables = new MockCallableCollection();
private MockCallable mockCallable = new MockCallable("mockCallable");
public CoreMockTest(String name) {
super(name);
}
public void setUp() {
mock = new CoreMock(DummyInterface.class, MOCK_NAME, mockCallables);
try {
proxy = (DummyInterface)mock.proxy();
} catch (ClassCastException ex) {
fail("proxy is not of expected interface type");
}
}
public void testMockAnnotatesAssertionFailedErrors()
throws Throwable {
final String originalMessage = "original message";
mockCallables.setupCall(new AssertionFailedError(originalMessage));
try {
proxy.noArgVoidMethod();
} catch (AssertionFailedError err) {
AssertMo.assertIncludes("should contain original message", originalMessage, err.getMessage());
AssertMo.assertIncludes("should contain mock name", MOCK_NAME, err.getMessage());
}
}
public void testMockNameFromClass() throws Exception {
assertEquals("mockString", CoreMock.mockNameFromClass(String.class));
}
public void testMockProxyReturnsConfiguredResult() throws Throwable {
final String result = "configured result";
mockCallables.setupCall(result);
assertSame("result is returned by mock", result, proxy.oneArgMethod("arg"));
}
public void testMockProxySendsAllArgument() throws Throwable {
mockCallables.addExpectedCall(DummyInterface.METHOD_TWOARG_NAME, DummyInterface.METHOD_TWOARG_ARGS);
mockCallables.setupCall("result ignored");
proxy.twoArgMethod(DummyInterface.METHOD_TWOARG_ARGS[0], DummyInterface.METHOD_TWOARG_ARGS[1]);
// Can't use Verifier as we are verifying "verify"
mockCallables.verifyExpectations();
}
public void testMockProxySendsEmptyArrayWhenNoArguments()
throws Exception {
mockCallables.addExpectedCall(DummyInterface.METHOD_NOARGVOID_NAME, DummyInterface.METHOD_NOARGVOID_ARGS);
mockCallables.setupCall("result ignored");
proxy.noArgVoidMethod();
Verifier.verifyObject(this);
// Can't use Verifier as we are verifying "verify"
mockCallables.verifyExpectations();
}
public void testMockProxyThrowsConfiguredExceptions() throws Throwable {
final Throwable throwable = new DummyThrowable();
mockCallable.setupCallThrow(throwable);
mockCallables.setupCall(mockCallable);
try {
proxy.noArgVoidMethod();
} catch (Throwable ex) {
assertSame("exception is caught by mock", throwable, ex);
}
}
public void testMockToStringContainsName() {
AssertMo.assertIncludes("result of toString() should include name", MOCK_NAME, mock.toString());
}
public void testMockVerifies() throws Exception {
mockCallables.setExpectedVerifyCalls(1);
mock.verify();
// Can't use Verifier as we are verifying "verify"
mockCallables.verifyExpectations();
}
public void testProxyEquality() throws Exception {
mockCallables.setupCall(new Boolean(false));
mockCallables.setExpectedCallCalls(0);
assertTrue("Should handle proxy equality without checking expectations", proxy.equals(proxy));
Verifier.verifyObject(this);
}
public void testProxyInEquality() throws Exception {
mockCallables.setupCall(new Boolean(false));
mockCallables.addExpectedCall("equals", new Object[] {"not a proxy"});
assertFalse("Should handle proxy inequality by calling through", proxy.equals("not a proxy"));
Verifier.verifyObject(this);
}
public void testProxyToString() throws Exception {
assertEquals("Should get a mock name without touching the underlying mock", MOCK_NAME, DynamicUtil.proxyToString(proxy));
mock.verify(); // should not fail on a proxyToString call
}
}
Index: MockTest.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockTest.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- MockTest.java 6 Jul 2003 02:31:37 -0000 1.15
+++ MockTest.java 7 Jul 2003 00:19:33 -0000 1.16
@@ -359,98 +359,4 @@
Verifier.verifyObject(this);
mockCallables.verifyExpectations();
}
-
- public void testMockAnnotatesAssertionFailedErrors()
- throws Throwable {
- final String originalMessage = "original message";
-
- mockCallables.setupCall(new AssertionFailedError(originalMessage));
-
- try {
- proxy.noArgMethodVoid();
- } catch (AssertionFailedError err) {
- AssertMo.assertIncludes("should contain original message", originalMessage, err.getMessage());
- AssertMo.assertIncludes("should contain mock name", MOCK_NAME, err.getMessage());
- }
- }
-
- public void testMockNameFromClass() throws Exception {
- assertEquals("mockString", Mock.mockNameFromClass(String.class));
- }
-
- public void testMockProxyReturnsConfiguredResult()
- throws Throwable {
- final String result = "configured result";
-
- mockCallables.setupCall(result);
-
- assertSame("result is returned by mock", result, proxy.oneArgMethod(METHOD_TWOARG_ARGS[0]));
- }
-
- public void testMockProxySendsAllArgument() throws Throwable {
- mockCallables.addExpectedCall(METHOD_TWOARG_NAME, METHOD_TWOARG_ARGS);
- mockCallables.setupCall("result ignored");
-
- proxy.twoArgMethod(METHOD_TWOARG_ARGS[0], METHOD_TWOARG_ARGS[1]);
-
- mockCallables.verifyExpectations();
- }
-
- public void testMockProxySendsEmptyArrayWhenNoArguments()
- throws Exception {
- mockCallables.addExpectedCall(METHOD_NOARG_NAME, METHOD_NOARG_ARGS);
- mockCallables.setupCall("result ignored");
-
- proxy.noArgMethodVoid();
-
- Verifier.verifyObject(this);
- mockCallables.verifyExpectations();
- }
-
- public void testMockProxyThrowsConfiguredExceptions()
- throws Throwable {
- final Throwable throwable = new DummyThrowable();
-
- mockCallables.setupCall(new ThrowStub(throwable));
-
- try {
- proxy.noArgMethodVoid();
- } catch (Throwable ex) {
- assertSame("exception is caught by mock", throwable, ex);
- }
- }
-
- public void testMockToStringContainsName() {
- AssertMo.assertIncludes("result of toString() should include name", MOCK_NAME, mock.toString());
- }
-
- public void testMockVerifies() throws Exception {
- mockCallables.setExpectedVerifyCalls(1);
-
- mock.verify();
-
- mockCallables.verifyExpectations();
- }
-
- public void testProxyEquality() throws Exception {
- assertTrue("Should handle proxy equality without checking expectations", proxy.equals(proxy));
- }
-
- public void testProxyInEquality() throws Exception {
- boolean IGNORED_RESULT = true;
- CallStub ret = new ReturnStub(new Boolean(IGNORED_RESULT));
- mockCallFactory.setupCreateReturnStub(ret);
- mockCallFactory.setupCreateCallSignature(new CallSignature("call",C.anyArgs(1),ret));
- mockCallables.setupCall(new Boolean(false));
-
- mock.matchAndReturn("call", C.anyArgs(1), IGNORED_RESULT);
- assertFalse("Should handle proxy inequality by calling through", proxy.equals("not a proxy"));
-
- Verifier.verifyObject(this);
- }
-
- public void testProxyToString() throws Exception {
- assertEquals("Should get a mock name without touching the underlying mock", MOCK_NAME, DynamicUtil.proxyToString(proxy));
- mock.verify(); // should not fail on a proxyToString call
- }
}
Index: MockCallableCollection.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockCallableCollection.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- MockCallableCollection.java 6 Jul 2003 23:24:09 -0000 1.2
+++ MockCallableCollection.java 7 Jul 2003 00:19:33 -0000 1.3
@@ -15,13 +15,13 @@
public ExpectationList matchedCallables = new ExpectationList("CallableAddable matchedCallables");
public ExpectationList expectedCallables = new ExpectationList("CallableAddable expectedCallables");
private ExpectationCounter myMatchesCalls = new ExpectationCounter("com.mockobjects.dynamic.CallableAddable MatchesCalls");
- private ReturnValues myActualMatchesReturnValues = new ReturnValues(true);
+ private ReturnValues myActualMatchesReturnValues = new ReturnValues("Matches", true);
private ExpectationList myMatchesParameter0Values = new ExpectationList("com.mockobjects.dynamic.CallableAddable MatchesParameter0Values");
private ExpectationList myMatchesParameter1Values = new ExpectationList("com.mockobjects.dynamic.CallableAddable MatchesParameter1Values");
private ExpectationCounter myGetDescriptionCalls = new ExpectationCounter("com.mockobjects.dynamic.CallableAddable GetDescriptionCalls");
- private ReturnValues myActualGetDescriptionReturnValues = new ReturnValues(true);
+ private ReturnValues myActualGetDescriptionReturnValues = new ReturnValues("GetDescription", true);
private ExpectationCounter myCallCalls = new ExpectationCounter("com.mockobjects.dynamic.CallableAddable CallCalls");
- private ReturnValues myActualCallReturnValues = new ReturnValues(true);
+ private ReturnValues myActualCallReturnValues = new ReturnValues("CallReturn", true);
private ExpectationList myCallMethodNames = new ExpectationList("com.mockobjects.dynamic.CallableAddable methodName");
private ExpectationList myCallArguments = new ExpectationList("com.mockobjects.dynamic.CallableAddable arguments");
private ExpectationCounter myVerifyCalls = new ExpectationCounter("com.mockobjects.dynamic.CallableAddable VerifyCalls");
Index: DummyInterface.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/DummyInterface.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DummyInterface.java 18 May 2003 20:59:38 -0000 1.2
+++ DummyInterface.java 7 Jul 2003 00:19:33 -0000 1.3
@@ -1,15 +1,24 @@
-/*
- * Created on 04-Apr-2003
- */
+
package test.mockobjects.dynamic;
-/**
- * @author dev
- */
public interface DummyInterface {
- public String twoArgMethod( String arg1, String arg2 ) throws Throwable;
- public String oneArgMethod( String arg1);
+ void noArgVoidMethod();
+ String noArgMethod();
+ String oneArgMethod( String arg1);
+ String twoArgMethod( String arg1, String arg2 ) throws Throwable;
+
+ final String METHOD_NOARGVOID_NAME = "noArgVoidMethod";
+ final Object[] METHOD_NOARGVOID_ARGS = new Object[0];
+
+ final String METHOD_NOARG_NAME = "noArgMethod";
+ final Object[] METHOD_NOARG_ARGS = new Object[0];
+ final String METHOD_NOARG_RESULT = "resultNoArgs";
+
+ final String METHOD_ONEARG_NAME = "oneArgMethod";
+ final String[] METHOD_ONEARG_ARGS = new String[] { "oneP1" };
+ final String METHOD_ONEARG_RESULT = "result1Args";
- public void noArgMethodVoid();
- public String noArgMethod();
+ final String METHOD_TWOARG_NAME = "twoArgMethod";
+ final String[] METHOD_TWOARG_ARGS = new String[] { "twoP1", "twoP2" };
+ final String METHOD_TWOARG_RESULT = "resultTwoArgs";
}
|
|
From: Steve F. <st...@m3...> - 2003-07-06 23:43:46
|
Tim and I have been kicking ideas around. Take a look at our latest at: http://www.mockobjects.com/wiki/DynamicMockObjects S. -- "A LISP programmer knows the value of everything but the cost of nothing. A C programmer knows the cost of everything but the value of nothing." (Todd Proebsting) |
|
From: Steve F. <sm...@us...> - 2003-07-06 23:40:31
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv21899/src/core/com/mockobjects/dynamic Modified Files: AbstractCallableCollection.java CallableList.java Added Files: CallableArrayList.java Log Message: Extracted CallableList and CallableArrayList --- NEW FILE: CallableArrayList.java --- /* * Copyright mockobjects.com 05-Jul-2003 */ package com.mockobjects.dynamic; import java.util.ArrayList; public class CallableArrayList implements CallableList { public ArrayList list = new ArrayList(); public void add(Callable callable) { list.add(callable); } public boolean isEmpty() { return list.isEmpty(); } public Callable get(int index) { return (Callable)list.get(index); } public int size() { return list.size(); } public void clear() { list.clear(); } public Callable firstMatchingCall(final Invocation invocation) { return apply(new Handler() { public Callable handle(int index, Callable callable) { return callable.matches(invocation) ? callable : null; } }); } public Callable apply(final CallableList.Handler handler) { for (int i = 0; i < list.size(); i++) { Callable result = handler.handle(i, (Callable)list.get(i)); if (null != result) { return result; } } return null; } public void verify() { apply(new Handler() { public Callable handle(int index, Callable callable) { callable.verify(); return null; } }); } } Index: AbstractCallableCollection.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/AbstractCallableCollection.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- AbstractCallableCollection.java 6 Jul 2003 23:24:09 -0000 1.2 +++ AbstractCallableCollection.java 6 Jul 2003 23:40:29 -0000 1.3 @@ -4,6 +4,9 @@ abstract public class AbstractCallableCollection implements CallableCollection { + protected CallableList expectedCalls = new CallableArrayList(); + protected CallableList matchingCalls = new CallableArrayList(); + abstract public String getDescription(); abstract public Object call(Invocation invocation) throws Throwable; @@ -28,8 +31,13 @@ expectedCalls.verify(); } - protected CallableList expectedCalls = new CallableList(); - protected CallableList matchingCalls = new CallableList(); + protected Callable findMatchingCall(Invocation invocation) throws AssertionFailedError { + Callable foundCall = matchingCalls.firstMatchingCall(invocation); + if (foundCall == null) { + throw createUnexpectedCallError(invocation); + } + return foundCall; + } protected AssertionFailedError createUnexpectedCallError(Invocation invocation) { StringBuffer buf = new StringBuffer(); @@ -40,13 +48,4 @@ buf.append(getDescription()); return new AssertionFailedError(buf.toString()); } - - protected Callable findMatchingCall(Invocation invocation) throws AssertionFailedError { - Callable foundCall = matchingCalls.firstMatchingCall(invocation); - if (foundCall == null) { - throw createUnexpectedCallError(invocation); - } - return foundCall; - } - } Index: CallableList.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallableList.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- CallableList.java 6 Jul 2003 23:24:09 -0000 1.2 +++ CallableList.java 6 Jul 2003 23:40:29 -0000 1.3 @@ -1,63 +1,23 @@ /* - * Copyright mockobjects.com 05-Jul-2003 + * Copyright mockobjects.com 07-Jul-2003 + * */ package com.mockobjects.dynamic; -import java.util.ArrayList; - import com.mockobjects.Verifiable; -public class CallableList implements Verifiable { - public interface Handler { - Callable handle(int index, Callable callable); - } - - public ArrayList list = new ArrayList(); - - public void add(Callable callable) { - list.add(callable); - } - - public boolean isEmpty() { - return list.isEmpty(); - } - - public Callable get(int index) { - return (Callable)list.get(index); - } - - public int size() { - return list.size(); - } - - public void clear() { - list.clear(); - } - - public Callable firstMatchingCall(final Invocation invocation) { - return apply(new Handler() { - public Callable handle(int index, Callable callable) { - return callable.matches(invocation) ? callable : null; - } - }); - } - - public Callable apply(final Handler handler) { - for (int i = 0; i < list.size(); i++) { - Callable result = handler.handle(i, (Callable)list.get(i)); - if (null != result) { - return result; - } - } - return null; - } - - public void verify() { - apply(new Handler() { - public Callable handle(int index, Callable callable) { - callable.verify(); - return null; - } - }); - } -} +public interface CallableList extends Verifiable { + + public interface Handler { + Callable handle(int index, Callable callable); + } + + + void add(Callable callable); + boolean isEmpty(); + Callable get(int index); + int size(); + void clear(); + Callable firstMatchingCall(final Invocation invocation); + Callable apply(final Handler handler); +} \ No newline at end of file |
|
From: Steve F. <sm...@us...> - 2003-07-06 23:24:14
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv19884/src/core/com/mockobjects/dynamic Modified Files: AbstractCallableCollection.java CoreMock.java Callable.java CallableList.java ReturnStub.java CallBag.java VoidStub.java CallOnceExpectation.java CallStub.java CallSequence.java ThrowStub.java CallSignature.java Added Files: Invocation.java Removed Files: ActiveCall.java Log Message: Renamed ActiveCall to Invocation --- NEW FILE: Invocation.java --- /* * Copyright mockobjects.com 05-Jul-2003 */ package com.mockobjects.dynamic; import java.lang.reflect.Method; public class Invocation extends Object { final public String methodName; final public Object[] args; public Invocation(Method method, Object[] args) { this(method.getName(), args == null ? new Object[0] : args); } public Invocation(String methodName, Object[] args) { this.methodName = methodName; this.args = args; } public String getMethodName() { return methodName; } public String toString() { return DynamicUtil.methodToString(getMethodName(), args); } } Index: AbstractCallableCollection.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/AbstractCallableCollection.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- AbstractCallableCollection.java 6 Jul 2003 02:29:40 -0000 1.1 +++ AbstractCallableCollection.java 6 Jul 2003 23:24:09 -0000 1.2 @@ -5,9 +5,9 @@ abstract public class AbstractCallableCollection implements CallableCollection { abstract public String getDescription(); - abstract public Object call(ActiveCall call) throws Throwable; + abstract public Object call(Invocation invocation) throws Throwable; - public boolean matches(ActiveCall activeCall) { + public boolean matches(Invocation invocation) { throw new AssertionFailedError("matches() operation not supported in CallCollection"); } @@ -31,20 +31,20 @@ protected CallableList expectedCalls = new CallableList(); protected CallableList matchingCalls = new CallableList(); - protected AssertionFailedError createUnexpectedCallError(ActiveCall call) { + protected AssertionFailedError createUnexpectedCallError(Invocation invocation) { StringBuffer buf = new StringBuffer(); buf.append("Unexpected call: "); - buf.append(call.toString()); + buf.append(invocation.toString()); buf.append("\n"); buf.append("Expected "); buf.append(getDescription()); return new AssertionFailedError(buf.toString()); } - protected Callable findMatchingCall(ActiveCall call) throws AssertionFailedError { - Callable foundCall = matchingCalls.firstMatchingCall(call); + protected Callable findMatchingCall(Invocation invocation) throws AssertionFailedError { + Callable foundCall = matchingCalls.firstMatchingCall(invocation); if (foundCall == null) { - throw createUnexpectedCallError(call); + throw createUnexpectedCallError(invocation); } return foundCall; } Index: CoreMock.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CoreMock.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- CoreMock.java 6 Jul 2003 23:06:12 -0000 1.2 +++ CoreMock.java 6 Jul 2003 23:24:09 -0000 1.3 @@ -27,14 +27,14 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { try { - ActiveCall activeCall = new ActiveCall(method, args); + Invocation invocation = new Invocation(method, args); - if (isCheckingEqualityOnProxy(activeCall)) { + if (isCheckingEqualityOnProxy(invocation)) { return new Boolean(args[0] == this.proxy); - } else if (isMockNameGetter(activeCall)) { + } else if (isMockNameGetter(invocation)) { return this.getMockName(); } else { - return invocationMatchers.call(activeCall); + return invocationMatchers.call(invocation); } } catch (AssertionFailedError ex) { throw new AssertionFailedError(name + ": " + ex.getMessage()); @@ -65,13 +65,13 @@ invocationMatchers.addMatch(invocationMatcher); } - protected boolean isCheckingEqualityOnProxy(ActiveCall call) { - return (call.getMethodName().equals("equals")) && (call.args.length == 1) && - (Proxy.isProxyClass(call.args[0].getClass())); + protected boolean isCheckingEqualityOnProxy(Invocation invocation) { + return (invocation.getMethodName().equals("equals")) && (invocation.args.length == 1) && + (Proxy.isProxyClass(invocation.args[0].getClass())); } - protected boolean isMockNameGetter(ActiveCall call) { - return (call.getMethodName().equals("getMockName")) && (call.args.length == 0); + protected boolean isMockNameGetter(Invocation invocation) { + return (invocation.getMethodName().equals("getMockName")) && (invocation.args.length == 0); } public void reset() { Index: Callable.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Callable.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- Callable.java 5 Jul 2003 15:15:54 -0000 1.4 +++ Callable.java 6 Jul 2003 23:24:09 -0000 1.5 @@ -4,6 +4,6 @@ public interface Callable extends Verifiable { String getDescription(); - Object call( ActiveCall call ) throws Throwable; - boolean matches(ActiveCall activeCall); + Object call(Invocation invocation) throws Throwable; + boolean matches(Invocation invocation); } Index: CallableList.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallableList.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- CallableList.java 5 Jul 2003 16:35:51 -0000 1.1 +++ CallableList.java 6 Jul 2003 23:24:09 -0000 1.2 @@ -34,10 +34,10 @@ list.clear(); } - public Callable firstMatchingCall(final ActiveCall call) { + public Callable firstMatchingCall(final Invocation invocation) { return apply(new Handler() { public Callable handle(int index, Callable callable) { - return callable.matches(call) ? callable : null; + return callable.matches(invocation) ? callable : null; } }); } Index: ReturnStub.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/ReturnStub.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- ReturnStub.java 5 Jul 2003 15:15:54 -0000 1.5 +++ ReturnStub.java 6 Jul 2003 23:24:09 -0000 1.6 @@ -12,7 +12,7 @@ this.result = result; } - public Object call(ActiveCall args) throws Throwable { + public Object call(Invocation invocation) throws Throwable { return result; } Index: CallBag.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallBag.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- CallBag.java 6 Jul 2003 02:31:37 -0000 1.7 +++ CallBag.java 6 Jul 2003 23:24:09 -0000 1.8 @@ -5,14 +5,14 @@ public class CallBag extends AbstractCallableCollection { - public Object call(ActiveCall call) throws Throwable { + public Object call(Invocation invocation) throws Throwable { - Callable foundCall = expectedCalls.firstMatchingCall(call); + Callable foundCall = expectedCalls.firstMatchingCall(invocation); if (foundCall == null) { - foundCall = findMatchingCall(call); + foundCall = findMatchingCall(invocation); } - return foundCall.call(call); + return foundCall.call(invocation); } public String getDescription() { Index: VoidStub.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/VoidStub.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- VoidStub.java 5 Jul 2003 15:15:54 -0000 1.4 +++ VoidStub.java 6 Jul 2003 23:24:09 -0000 1.5 @@ -10,7 +10,7 @@ return "returns <void>"; } - public Object call(ActiveCall args) throws Throwable { + public Object call(Invocation invocation) throws Throwable { return null; } Index: CallOnceExpectation.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallOnceExpectation.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- CallOnceExpectation.java 5 Jul 2003 15:15:54 -0000 1.3 +++ CallOnceExpectation.java 6 Jul 2003 23:24:09 -0000 1.4 @@ -14,13 +14,13 @@ return delegate.getDescription() + " [" + (wasCalled ? "" : "not ") + "called]"; } - public Object call(ActiveCall args) throws Throwable { + public Object call(Invocation invocation) throws Throwable { wasCalled = true; - return delegate.call( args ); + return delegate.call( invocation ); } - public boolean matches(ActiveCall activeCall) { - return (!wasCalled) && delegate.matches( activeCall ); + public boolean matches(Invocation invocation) { + return (!wasCalled) && delegate.matches( invocation ); } public void verify() { Index: CallStub.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallStub.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- CallStub.java 5 Jul 2003 15:15:54 -0000 1.4 +++ CallStub.java 6 Jul 2003 23:24:09 -0000 1.5 @@ -6,7 +6,7 @@ public abstract class CallStub implements Callable { - public boolean matches(ActiveCall activeCall) { + public boolean matches(Invocation invocation) { return true; } Index: CallSequence.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallSequence.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- CallSequence.java 6 Jul 2003 02:31:37 -0000 1.9 +++ CallSequence.java 6 Jul 2003 23:24:09 -0000 1.10 @@ -6,19 +6,19 @@ int callIndex = 0; - public Object call(ActiveCall activeCall) throws Throwable { + public Object call(Invocation invocation) throws Throwable { if (expectedCalls.isEmpty()) - throw new AssertionFailedError("no methods defined on mock, received: " + activeCall.toString()); + throw new AssertionFailedError("no methods defined on mock, received: " + invocation.toString()); if (callIndex == expectedCalls.size()) - throw new AssertionFailedError("mock called too many times, received: " + activeCall.toString()); + throw new AssertionFailedError("mock called too many times, received: " + invocation.toString()); Callable callable = expectedCalls.get(callIndex++); - if (callable.matches(activeCall)) { + if (callable.matches(invocation)) { //TODO shouldn't callIndex be incremented here? - return callable.call(activeCall); + return callable.call(invocation); } - return findMatchingCall(activeCall).call(activeCall); + return findMatchingCall(invocation).call(invocation); } public String getDescription() { Index: ThrowStub.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/ThrowStub.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- ThrowStub.java 5 Jul 2003 15:15:54 -0000 1.5 +++ ThrowStub.java 6 Jul 2003 23:24:09 -0000 1.6 @@ -12,7 +12,7 @@ this.throwable = throwable; } - public Object call(ActiveCall args) throws Throwable { + public Object call(Invocation invocation) throws Throwable { throw throwable; } Index: CallSignature.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallSignature.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- CallSignature.java 6 Jul 2003 02:31:37 -0000 1.4 +++ CallSignature.java 6 Jul 2003 23:24:09 -0000 1.5 @@ -12,18 +12,18 @@ this.delegate = delegate; } - public Object call( ActiveCall args ) + public Object call( Invocation invocation ) throws Throwable { - return delegate.call( args ); + return delegate.call( invocation ); } public void verify() { delegate.verify(); } - public boolean matches(ActiveCall activeCall) { - return this.methodName.equals(activeCall.getMethodName()) && constraints.matches(activeCall.args); + public boolean matches(Invocation invocation) { + return this.methodName.equals(invocation.getMethodName()) && constraints.matches(invocation.args); } public String getDescription() { --- ActiveCall.java DELETED --- |
|
From: Steve F. <sm...@us...> - 2003-07-06 23:24:13
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic
In directory sc8-pr-cvs1:/tmp/cvs-serv19884/src/core/test/mockobjects/dynamic
Modified Files:
CallOnceExpectationTest.java CallSignatureTest.java
StubTest.java CallBagTest.java MockCallableCollection.java
CallSequenceTest.java MockCallable.java
Log Message:
Renamed ActiveCall to Invocation
Index: CallOnceExpectationTest.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/CallOnceExpectationTest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- CallOnceExpectationTest.java 5 Jul 2003 16:35:20 -0000 1.4
+++ CallOnceExpectationTest.java 6 Jul 2003 23:24:09 -0000 1.5
@@ -11,7 +11,7 @@
final String RESULT = "result!";
final String METHOD_NAME = "methodName";
final Object[] ARGS = { "arg1", "arg2" };
- final ActiveCall CALL = new ActiveCall(METHOD_NAME, ARGS) ;
+ final Invocation INVOCATION = new Invocation(METHOD_NAME, ARGS) ;
final String DECORATED_DESCRIPTION = DynamicUtil.methodToString( METHOD_NAME, ARGS );
@@ -51,7 +51,7 @@
mockCallable.setupCallReturn( RESULT );
mockCallable.setExpectedVerifyCalls(1);
- call.call( CALL );
+ call.call( INVOCATION );
call.verify();
mockCallable.verifyExpectations();
@@ -60,15 +60,15 @@
public void testMatchesDelegated() throws Throwable {
mockCallable.setExpectedMatches( METHOD_NAME, ARGS );
mockCallable.setupAlwaysMatchActiveCall(true);
- assertTrue( "returns matches to be true", call.matches( CALL ) );
+ assertTrue( "returns matches to be true", call.matches( INVOCATION ) );
mockCallable.verifyExpectations();
}
public void testCallArgumentsPassedThrough() throws Throwable {
- mockCallable.activeCall.setExpected(CALL);
+ mockCallable.invocation.setExpected(INVOCATION);
mockCallable.setupCallReturn(RESULT);
- call.call( CALL );
+ call.call( INVOCATION );
mockCallable.verifyExpectations();
}
@@ -77,16 +77,16 @@
mockCallable.setupAlwaysMatchActiveCall(true);
mockCallable.setupCallReturn(RESULT);
- assertTrue( "First time should match", call.matches( CALL ));
- call.call( CALL );
- assertFalse( "Second time should not match", call.matches( CALL ));
+ assertTrue( "First time should match", call.matches( INVOCATION ));
+ call.call( INVOCATION );
+ assertFalse( "Second time should not match", call.matches( INVOCATION ));
}
public void testDecoratedResultPassedThrough() throws Throwable {
mockCallable.setupCallReturn(RESULT);
assertSame( "should return decorated's result",
- RESULT, call.call( CALL ) );
+ RESULT, call.call( INVOCATION ) );
mockCallable.verifyExpectations();
}
@@ -97,7 +97,7 @@
mockCallable.setupCallThrow(exception);
try {
- call.call( CALL );
+ call.call( INVOCATION );
fail("expected decorated's throwable to be thrown");
}
catch( DummyThrowable ex ) {
Index: CallSignatureTest.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/CallSignatureTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CallSignatureTest.java 6 Jul 2003 02:31:37 -0000 1.1
+++ CallSignatureTest.java 6 Jul 2003 23:24:09 -0000 1.2
@@ -11,7 +11,7 @@
public class CallSignatureTest extends TestCase {
final String METHOD_NAME = "methodName";
final Object[] IGNORED_ARGS = new Object[0];
- final ActiveCall CALL = new ActiveCall(METHOD_NAME, IGNORED_ARGS);
+ final Invocation INVOCATION = new Invocation(METHOD_NAME, IGNORED_ARGS);
Mock mock = new Mock(DummyInterface.class, "mock");
MockCallable mockCallable = new MockCallable("mock callable");
@@ -26,10 +26,10 @@
throws Throwable {
final String result = "result";
- mockCallable.activeCall.setExpected(CALL);
+ mockCallable.invocation.setExpected(INVOCATION);
mockCallable.setupCallReturn(result);
- callSignature.call(CALL);
+ callSignature.call(INVOCATION);
mockCallable.verifyExpectations();
}
@@ -46,7 +46,7 @@
mockCallable.setExpectedVerifyCalls(1);
mockCallable.setupCallReturn("result");
- callSignature.call(CALL);
+ callSignature.call(INVOCATION);
callSignature.verify();
mockCallable.verifyExpectations();
@@ -55,8 +55,8 @@
public void testMultipleCallsSucceed() throws Throwable {
mockCallable.setupCallReturn("result");
- callSignature.call(CALL);
- callSignature.call(CALL);
+ callSignature.call(INVOCATION);
+ callSignature.call(INVOCATION);
mockCallable.verifyExpectations();
}
@@ -66,7 +66,7 @@
}
public void testCallDoesNotMatchWhenWrongName() throws Throwable {
- assertFalse("call does not match", callSignature.matches(new ActiveCall("anotherName", IGNORED_ARGS)));
+ assertFalse("call does not match", callSignature.matches(new Invocation("anotherName", IGNORED_ARGS)));
mockCallable.verifyExpectations();
}
@@ -76,10 +76,10 @@
mockConstraintMatcher.setupMatches(true);
- callSignature.call(CALL);
- assertTrue("matches after first call", callSignature.matches( CALL ));
- callSignature.call(CALL);
- assertTrue("matches after further calls", callSignature.matches( CALL ));
+ callSignature.call(INVOCATION);
+ assertTrue("matches after first call", callSignature.matches( INVOCATION ));
+ callSignature.call(INVOCATION);
+ assertTrue("matches after further calls", callSignature.matches( INVOCATION ));
mockCallable.verifyExpectations();
}
@@ -91,13 +91,13 @@
mockConstraintMatcher.addExpectedMatches(args);
mockConstraintMatcher.setupMatches(true);
- assertTrue("matches delegated to constraint matcher", callSignature.matches(new ActiveCall(METHOD_NAME, args)));
+ assertTrue("matches delegated to constraint matcher", callSignature.matches(new Invocation(METHOD_NAME, args)));
mockConstraintMatcher.verify();
}
public void testMatchesFailure() throws Throwable {
mockConstraintMatcher.setupMatches(false);
- assertFalse("Should not match if constraint matcher doesn't", callSignature.matches(CALL));
+ assertFalse("Should not match if constraint matcher doesn't", callSignature.matches(INVOCATION));
}
}
Index: StubTest.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/StubTest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- StubTest.java 5 Jul 2003 15:15:54 -0000 1.4
+++ StubTest.java 6 Jul 2003 23:24:09 -0000 1.5
@@ -5,7 +5,7 @@
import junit.framework.TestCase;
-import com.mockobjects.dynamic.ActiveCall;
+import com.mockobjects.dynamic.Invocation;
import com.mockobjects.dynamic.ReturnStub;
import com.mockobjects.dynamic.ThrowStub;
@@ -15,19 +15,19 @@
super(name);
}
- ActiveCall stubCall = new ActiveCall("ignoredName", new Object[0]);
+ Invocation invocation = new Invocation("ignoredName", new Object[0]);
public void testReturnStub() throws Throwable {
final String RESULT = "result";
- assertSame( "Should be the same result object", RESULT, new ReturnStub(RESULT).call( stubCall) );
+ assertSame( "Should be the same result object", RESULT, new ReturnStub(RESULT).call( invocation) );
}
public void testThrowStub() {
final Throwable throwable = new DummyThrowable();
try {
- new ThrowStub(throwable).call( stubCall );
+ new ThrowStub(throwable).call( invocation );
}
catch( Throwable t ) {
assertSame( "Should be the same throwable", throwable, t );
Index: CallBagTest.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/CallBagTest.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- CallBagTest.java 5 Jul 2003 16:34:14 -0000 1.7
+++ CallBagTest.java 6 Jul 2003 23:24:09 -0000 1.8
@@ -13,11 +13,11 @@
final Throwable METHOD_A_EXCEPTION = new DummyThrowable("Configured test throwable");
final String[] METHOD_A_ARGS = new String[] { "a1", "a2" };
- final ActiveCall METHOD_A_CALL = new ActiveCall(METHOD_A_NAME, METHOD_A_ARGS);
+ final Invocation METHOD_A_INVOCATION = new Invocation(METHOD_A_NAME, METHOD_A_ARGS);
final ConstraintMatcher METHOD_A_CONSTRAINTS = C.args(C.eq("a1"), C.eq("a2"));
final String[] METHOD_B_ARGS = new String[] { "b1", "b2" };
- final ActiveCall METHOD_B_CALL = new ActiveCall(METHOD_B_NAME, METHOD_B_ARGS);
+ final Invocation METHOD_B_INVOCATION = new Invocation(METHOD_B_NAME, METHOD_B_ARGS);
private CallBag callBag = new CallBag();
@@ -32,7 +32,7 @@
public void testCallFailsOnEmptySet() throws Throwable {
try {
- callBag.call(new ActiveCall("missingMethod", new Object[0]));
+ callBag.call(new Invocation("missingMethod", new Object[0]));
} catch (AssertionFailedError ex) {
AssertMo.assertIncludes("reports empty set in error message", "no methods", ex.getMessage());
@@ -45,15 +45,15 @@
public void testCallPassedToContainedElements() throws Throwable {
methodA.setExpectedMatches(METHOD_A_NAME, METHOD_A_ARGS);
methodA.setupAlwaysMatchActiveCall(true);
- methodA.activeCall.setExpected(METHOD_A_CALL);
+ methodA.invocation.setExpected(METHOD_A_INVOCATION);
methodA.setupCallReturn(METHOD_A_RESULT);
- methodB.activeCall.setExpectNothing();
+ methodB.invocation.setExpectNothing();
callBag.addExpect(methodA);
callBag.addExpect(methodB);
- assertSame("expected result from method A", METHOD_A_RESULT, callBag.call(METHOD_A_CALL));
+ assertSame("expected result from method A", METHOD_A_RESULT, callBag.call(METHOD_A_INVOCATION));
methodA.verifyExpectations();
methodB.verifyExpectations();
@@ -68,15 +68,15 @@
callBag.addExpect(new CallOnceExpectation(anotherMethodASignature));
assertSame("expected result from method B, as expect has precendence over match", "result2",
- callBag.call(METHOD_A_CALL));
+ callBag.call(METHOD_A_INVOCATION));
}
public void testCallPassedToContainedElementsOtherOrder()
throws Throwable {
methodA.setExpectedMatches(METHOD_B_NAME, METHOD_B_ARGS);
methodA.setupAlwaysMatchActiveCall(false);
- methodA.activeCall.setExpectNothing();
- methodB.activeCall.setExpected(METHOD_B_CALL);
+ methodA.invocation.setExpectNothing();
+ methodB.invocation.setExpected(METHOD_B_INVOCATION);
methodB.setupCallReturn(METHOD_B_RESULT);
methodB.setExpectedMatches(METHOD_B_NAME, METHOD_B_ARGS);
@@ -86,7 +86,7 @@
callBag.addExpect(methodB);
assertSame("expected result from method B", METHOD_B_RESULT,
- callBag.call(METHOD_B_CALL));
+ callBag.call(METHOD_B_INVOCATION));
methodA.verifyExpectations();
methodB.verifyExpectations();
@@ -100,7 +100,7 @@
callBag.addExpect(mockCallable);
- assertSame("result is returned by mock", result, callBag.call(new ActiveCall("method", new Object[0])));
+ assertSame("result is returned by mock", result, callBag.call(new Invocation("method", new Object[0])));
}
public void testCallableThrowableThrown()
@@ -113,7 +113,7 @@
callBag.addExpect(mockCallable);
try {
- callBag.call(new ActiveCall("anyMethod", new String[0]));
+ callBag.call(new Invocation("anyMethod", new String[0]));
} catch (Throwable ex) {
assertSame("exception was thrown by mock", throwable, ex);
}
@@ -126,22 +126,22 @@
public void testFailureIfNoElementMatches() throws Throwable {
final String methodCName = "methodC";
final String[] methodCArgs = { "c1", "c2" };
- final ActiveCall methodCCall = new ActiveCall(methodCName, methodCArgs);
+ final Invocation methodCInvocation = new Invocation(methodCName, methodCArgs);
methodA.setExpectedMatches(methodCName, methodCArgs);
methodA.setupAlwaysMatchActiveCall(false);
- methodA.activeCall.setExpectNothing();
+ methodA.invocation.setExpectNothing();
methodA.setupGetDescription("***methodA-description****");
- methodB.activeCall.setExpected(methodCCall);
+ methodB.invocation.setExpected(methodCInvocation);
methodB.setupAlwaysMatchActiveCall(false);
- methodB.activeCall.setExpectNothing();
+ methodB.invocation.setExpectNothing();
methodB.setupGetDescription("***methodB-description****");
callBag.addExpect(methodA);
callBag.addExpect(methodB);
try {
- callBag.call(methodCCall);
+ callBag.call(methodCInvocation);
} catch (AssertionFailedError ex) {
AssertMo.assertIncludes("method name is in error message", "methodC", ex.getMessage());
AssertMo.assertIncludes("argument is in error message (1)", methodCArgs[0], ex.getMessage());
Index: MockCallableCollection.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockCallableCollection.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- MockCallableCollection.java 6 Jul 2003 02:31:36 -0000 1.1
+++ MockCallableCollection.java 6 Jul 2003 23:24:09 -0000 1.2
@@ -4,7 +4,7 @@
import com.mockobjects.ExpectationList;
import com.mockobjects.MockObject;
import com.mockobjects.ReturnValues;
-import com.mockobjects.dynamic.ActiveCall;
+import com.mockobjects.dynamic.Invocation;
import com.mockobjects.dynamic.Callable;
import com.mockobjects.dynamic.CallableCollection;
import com.mockobjects.util.NotImplementedException;
@@ -47,10 +47,10 @@
myMatchesParameter1Values.addExpected(arg1);
}
- public boolean matches(ActiveCall call) {
+ public boolean matches(Invocation invocation) {
myMatchesCalls.inc();
- myMatchesParameter0Values.addActual(call.getMethodName());
- myMatchesParameter1Values.addActual(call.args);
+ myMatchesParameter0Values.addActual(invocation.getMethodName());
+ myMatchesParameter1Values.addActual(invocation.args);
Object nextReturnValue = myActualMatchesReturnValues.getNext();
@@ -86,11 +86,11 @@
myCallArguments.addExpectedMany(args);
}
- public Object call(ActiveCall call)
+ public Object call(Invocation invocation)
throws Throwable {
myCallCalls.inc();
- myCallMethodNames.addActual(call.getMethodName());
- myCallArguments.addActualMany(call.args);
+ myCallMethodNames.addActual(invocation.getMethodName());
+ myCallArguments.addActualMany(invocation.args);
Object nextReturnValue = myActualCallReturnValues.getNext();
Index: CallSequenceTest.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/CallSequenceTest.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- CallSequenceTest.java 5 Jul 2003 16:35:20 -0000 1.11
+++ CallSequenceTest.java 6 Jul 2003 23:24:09 -0000 1.12
@@ -24,11 +24,11 @@
final String METHOD_B_RESULT = "resultB";
final Throwable METHOD_A_EXCEPTION = new DummyThrowable("Configured test throwable");
final String[] METHOD_A_ARGS = new String[] { "a1", "a2" };
- final ActiveCall METHOD_A_CALL = new ActiveCall(METHOD_A_NAME, METHOD_A_ARGS);
+ final Invocation METHOD_A_INVOCATION = new Invocation(METHOD_A_NAME, METHOD_A_ARGS);
final ConstraintMatcher METHOD_A_CONSTRAINTS = C.args(C.eq("a1"), C.eq("a2"));
final String[] METHOD_B_ARGS = new String[] { "b1", "b2" };
- final ActiveCall METHOD_B_CALL = new ActiveCall(METHOD_B_NAME, METHOD_B_ARGS);
+ final Invocation METHOD_B_INVOCATION = new Invocation(METHOD_B_NAME, METHOD_B_ARGS);
private CallSequence callSequence = new CallSequence();
private MockCallable methodA = new MockCallable("method a");
@@ -48,7 +48,7 @@
callSequence.addExpect(mockCallable);
try {
- callSequence.call(new ActiveCall("hello", new String[0]));
+ callSequence.call(new Invocation("hello", new String[0]));
} catch (Throwable ex) {
assertSame("exception is caught by mock", throwable, ex);
}
@@ -56,7 +56,7 @@
public void testCallFailsOnEmptyList() throws Throwable {
try {
- callSequence.call(new ActiveCall("missingMethod", new Object[0]));
+ callSequence.call(new Invocation("missingMethod", new Object[0]));
} catch (AssertionFailedError ex) {
AssertMo.assertIncludes("reports empty set in error message", "no methods", ex.getMessage());
@@ -70,10 +70,10 @@
mockCallable.setupAlwaysMatchActiveCall(true);
mockCallable.setupCallReturn(METHOD_A_RESULT);
callSequence.addExpect(mockCallable);
- callSequence.call(new ActiveCall("willdefinitelyMatch", new Object[0]));
+ callSequence.call(new Invocation("willdefinitelyMatch", new Object[0]));
try {
- callSequence.call(new ActiveCall("oneMethodTooMany", new Object[0]));
+ callSequence.call(new Invocation("oneMethodTooMany", new Object[0]));
} catch (AssertionFailedError ex) {
AssertMo.assertIncludes("reports one method call too many", "too many", ex.getMessage());
@@ -86,15 +86,15 @@
public void testCallPassedToContainedElements() throws Throwable {
methodA.setExpectedMatches(METHOD_A_NAME, METHOD_A_ARGS);
methodA.setupAlwaysMatchActiveCall(true);
- methodA.activeCall.setExpected(METHOD_A_CALL);
+ methodA.invocation.setExpected(METHOD_A_INVOCATION);
methodA.setupCallReturn(METHOD_A_RESULT);
- methodB.activeCall.setExpectNothing();
+ methodB.invocation.setExpectNothing();
callSequence.addExpect(methodA);
callSequence.addExpect(methodB);
- assertSame("expected result from method A", METHOD_A_RESULT, callSequence.call(METHOD_A_CALL));
+ assertSame("expected result from method A", METHOD_A_RESULT, callSequence.call(METHOD_A_INVOCATION));
methodA.verifyExpectations();
methodB.verifyExpectations();
@@ -111,7 +111,7 @@
callSequence.addExpect(methodB);
try {
- assertSame("expected result from method B", METHOD_B_RESULT, callSequence.call(METHOD_B_CALL));
+ assertSame("expected result from method B", METHOD_B_RESULT, callSequence.call(METHOD_B_INVOCATION));
} catch (AssertionFailedError ex) {
String message = ex.getMessage();
AssertMo.assertIncludes("Should have expected error message", "Unexpected call: methodB", message);
@@ -137,7 +137,7 @@
callSequence.addExpect(mockCallable);
- assertSame("result is returned by mock", result, callSequence.call(new ActiveCall("method", new Object[0])));
+ assertSame("result is returned by mock", result, callSequence.call(new Invocation("method", new Object[0])));
}
public void testEmptySetVerifies() throws Exception {
@@ -147,22 +147,22 @@
public void testFailureIfNoElementMatches() throws Throwable {
final String methodCName = "methodC";
final String[] methodCArgs = { "c1", "c2" };
- final ActiveCall methodCCall = new ActiveCall(methodCName, methodCArgs);
+ final Invocation methodCInvocation = new Invocation(methodCName, methodCArgs);
methodA.setExpectedMatches(methodCName, methodCArgs);
methodA.setupAlwaysMatchActiveCall(false);
- methodA.activeCall.setExpectNothing();
+ methodA.invocation.setExpectNothing();
methodA.setupGetDescription("***methodA-description****");
- methodB.activeCall.setExpected(methodCCall);
+ methodB.invocation.setExpected(methodCInvocation);
methodB.setupAlwaysMatchActiveCall(false);
- methodB.activeCall.setExpectNothing();
+ methodB.invocation.setExpectNothing();
methodB.setupGetDescription("***methodB-description****");
callSequence.addExpect(methodA);
callSequence.addExpect(methodB);
try {
- callSequence.call(methodCCall);
+ callSequence.call(methodCInvocation);
} catch (AssertionFailedError ex) {
AssertMo.assertIncludes("method name is in error message", "methodC", ex.getMessage());
AssertMo.assertIncludes("argument is in error message (1)", methodCArgs[0], ex.getMessage());
@@ -216,6 +216,6 @@
callSequence.addExpect(new CallOnceExpectation(anotherMethodASignature));
assertSame("expected result from method B, as expect has precendence over match", "result2",
- callSequence.call(METHOD_A_CALL));
+ callSequence.call(METHOD_A_INVOCATION));
}
}
Index: MockCallable.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockCallable.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- MockCallable.java 5 Jul 2003 16:35:20 -0000 1.5
+++ MockCallable.java 6 Jul 2003 23:24:09 -0000 1.6
@@ -6,7 +6,7 @@
import com.mockobjects.ExpectationList;
import com.mockobjects.ExpectationValue;
import com.mockobjects.ReturnValue;
-import com.mockobjects.dynamic.ActiveCall;
+import com.mockobjects.dynamic.Invocation;
import com.mockobjects.dynamic.Callable;
import com.mockobjects.util.Verifier;
@@ -14,7 +14,7 @@
final public String name;
- public ExpectationValue activeCall = new ExpectationValue("call") ;
+ public ExpectationValue invocation = new ExpectationValue("call") ;
private ReturnValue callResult = new ReturnValue("call.return");
private Throwable callThrow = null;
@@ -41,8 +41,8 @@
callThrow = thrown;
}
- public Object call(ActiveCall anActiveCall) throws Throwable {
- activeCall.setActual(anActiveCall);
+ public Object call(Invocation anInvocation) throws Throwable {
+ invocation.setActual(anInvocation);
if( callThrow != null ) {
throw callThrow;
@@ -64,9 +64,9 @@
matchesResult.setValue(result);
}
- public boolean matches(ActiveCall call) {
- matchesMethodName.setActual(call.getMethodName());
- matchesArgs.addActualMany(call.args);
+ public boolean matches(Invocation invocation) {
+ matchesMethodName.setActual(invocation.getMethodName());
+ matchesArgs.addActualMany(invocation.args);
matchesCount.inc();
return matchesResult.getBooleanValue();
}
|
|
From: Tim M. <ma...@us...> - 2003-07-06 23:06:14
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic
In directory sc8-pr-cvs1:/tmp/cvs-serv17710/core/com/mockobjects/dynamic
Modified Files:
Mock.java CoreMock.java
Added Files:
DynamicMock.java
Log Message:
Composition of DynamicMock step - 2
--- NEW FILE: DynamicMock.java ---
package com.mockobjects.dynamic;
public interface DynamicMock {
void expect(Callable invocationMatcher);
void stub(Callable invocationMatcher);
void reset();
}
Index: Mock.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Mock.java,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- Mock.java 6 Jul 2003 22:45:24 -0000 1.27
+++ Mock.java 6 Jul 2003 23:06:12 -0000 1.28
@@ -21,11 +21,7 @@
this(mockedClass, mockNameFromClass(mockedClass));
}
- public void reset() {
- this.callables.reset();
- }
-
- public static String mockNameFromClass(Class c) {
+ public static String mockNameFromClass(Class c) {
return "mock" + className(c);
}
@@ -65,7 +61,7 @@
}
public void expect(String methodName, ConstraintMatcher args) {
- callables.addExpect(callableFactory.createCallExpectation(callableFactory.createVoidCallable(methodName, args)));
+ this.expect(callableFactory.createCallExpectation(callableFactory.createVoidCallable(methodName, args)));
}
public void expectAndReturn(String methodName, Object result) {
@@ -101,7 +97,7 @@
}
public void expectAndReturn(String methodName, ConstraintMatcher args, Object result) {
- callables.addExpect(callableFactory.createCallExpectation(callableFactory.createReturnCallable(methodName, args, result)));
+ this.expect(callableFactory.createCallExpectation(callableFactory.createReturnCallable(methodName, args, result)));
}
public void expectAndThrow(String methodName, Throwable exception) {
@@ -113,7 +109,7 @@
}
public void expectAndThrow(String methodName, ConstraintMatcher args, Throwable exception) {
- callables.addExpect(callableFactory.createCallExpectation(callableFactory.createThrowableCallable(methodName, args, exception)));
+ this.expect(callableFactory.createCallExpectation(callableFactory.createThrowableCallable(methodName, args, exception)));
}
public void match(String methodName) {
@@ -133,7 +129,7 @@
}
public void match(String methodName, ConstraintMatcher args) {
- callables.addMatch(callableFactory.createVoidCallable(methodName, args));
+ this.stub(callableFactory.createVoidCallable(methodName, args));
}
public void matchAndReturn(String methodName, Object result) {
@@ -177,7 +173,7 @@
}
public void matchAndReturn(String methodName, ConstraintMatcher args, Object result) {
- callables.addMatch(callableFactory.createReturnCallable(methodName, args, result));
+ this.stub(callableFactory.createReturnCallable(methodName, args, result));
}
public void matchAndThrow(String methodName, Throwable throwable) {
@@ -197,7 +193,7 @@
}
public void matchAndThrow(String methodName, ConstraintMatcher args, Throwable throwable) {
- callables.addMatch(callableFactory.createThrowableCallable(methodName, args, throwable));
+ this.stub(callableFactory.createThrowableCallable(methodName, args, throwable));
}
/** @deprecated @see OrderedMock
Index: CoreMock.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CoreMock.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CoreMock.java 6 Jul 2003 22:45:24 -0000 1.1
+++ CoreMock.java 6 Jul 2003 23:06:12 -0000 1.2
@@ -9,14 +9,14 @@
import junit.framework.AssertionFailedError;
-public class CoreMock implements InvocationHandler, Verifiable {
- protected CallableCollection callables;
+public class CoreMock implements DynamicMock, InvocationHandler, Verifiable {
+ private CallableCollection invocationMatchers;
private Object proxy;
private String name;
public CoreMock(Class mockedClass, String name, CallableCollection callables) {
this.name = name;
- this.callables = callables;
+ this.invocationMatchers = callables;
this.proxy = Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { mockedClass }, this);
}
@@ -34,7 +34,7 @@
} else if (isMockNameGetter(activeCall)) {
return this.getMockName();
} else {
- return callables.call(activeCall);
+ return invocationMatchers.call(activeCall);
}
} catch (AssertionFailedError ex) {
throw new AssertionFailedError(name + ": " + ex.getMessage());
@@ -43,7 +43,7 @@
public void verify() {
try {
- callables.verify();
+ invocationMatchers.verify();
} catch (AssertionFailedError ex) {
throw new AssertionFailedError(name + ": " + ex.getMessage());
}
@@ -57,6 +57,14 @@
return this.name;
}
+ public void expect(Callable invocationMatcher) {
+ invocationMatchers.addExpect(invocationMatcher);
+ }
+
+ public void stub(Callable invocationMatcher) {
+ invocationMatchers.addMatch(invocationMatcher);
+ }
+
protected boolean isCheckingEqualityOnProxy(ActiveCall call) {
return (call.getMethodName().equals("equals")) && (call.args.length == 1) &&
(Proxy.isProxyClass(call.args[0].getClass()));
@@ -64,6 +72,10 @@
protected boolean isMockNameGetter(ActiveCall call) {
return (call.getMethodName().equals("getMockName")) && (call.args.length == 0);
+ }
+
+ public void reset() {
+ this.invocationMatchers.reset();
}
}
|
|
From: Tim M. <ma...@us...> - 2003-07-06 22:45:27
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic
In directory sc8-pr-cvs1:/tmp/cvs-serv14872/core/com/mockobjects/dynamic
Modified Files:
DynamicUtil.java Mock.java
Added Files:
CoreMock.java
Log Message:
Move to delegation of core mock functionality - step 1.
--- NEW FILE: CoreMock.java ---
package com.mockobjects.dynamic;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import com.mockobjects.Verifiable;
import junit.framework.AssertionFailedError;
public class CoreMock implements InvocationHandler, Verifiable {
protected CallableCollection callables;
private Object proxy;
private String name;
public CoreMock(Class mockedClass, String name, CallableCollection callables) {
this.name = name;
this.callables = callables;
this.proxy = Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { mockedClass }, this);
}
public Object proxy() {
return this.proxy;
}
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
try {
ActiveCall activeCall = new ActiveCall(method, args);
if (isCheckingEqualityOnProxy(activeCall)) {
return new Boolean(args[0] == this.proxy);
} else if (isMockNameGetter(activeCall)) {
return this.getMockName();
} else {
return callables.call(activeCall);
}
} catch (AssertionFailedError ex) {
throw new AssertionFailedError(name + ": " + ex.getMessage());
}
}
public void verify() {
try {
callables.verify();
} catch (AssertionFailedError ex) {
throw new AssertionFailedError(name + ": " + ex.getMessage());
}
}
public String toString() {
return this.name;
}
public String getMockName() {
return this.name;
}
protected boolean isCheckingEqualityOnProxy(ActiveCall call) {
return (call.getMethodName().equals("equals")) && (call.args.length == 1) &&
(Proxy.isProxyClass(call.args[0].getClass()));
}
protected boolean isMockNameGetter(ActiveCall call) {
return (call.getMethodName().equals("getMockName")) && (call.args.length == 0);
}
}
Index: DynamicUtil.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/DynamicUtil.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DynamicUtil.java 6 Jul 2003 02:25:19 -0000 1.4
+++ DynamicUtil.java 6 Jul 2003 22:45:24 -0000 1.5
@@ -77,7 +77,7 @@
public static String proxyToString(Object element) {
if (Proxy.isProxyClass(element.getClass())) {
try {
- Method mockNameMethod = Mock.class.getDeclaredMethod("getMockName", new Class[0]);
+ Method mockNameMethod = CoreMock.class.getDeclaredMethod("getMockName", new Class[0]);
Object debugableResult = Proxy.getInvocationHandler(element).invoke(element, mockNameMethod, new Object[0]);
return debugableResult.toString();
} catch (Throwable e) {
Index: Mock.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Mock.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- Mock.java 6 Jul 2003 02:31:37 -0000 1.26
+++ Mock.java 6 Jul 2003 22:45:24 -0000 1.27
@@ -1,24 +1,16 @@
package com.mockobjects.dynamic;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
import junit.framework.AssertionFailedError;
-import com.mockobjects.Verifiable;
import com.mockobjects.constraint.Constraint;
-public class Mock implements InvocationHandler, Verifiable {
- private String name;
- private Object proxy;
+public class Mock extends CoreMock {
private CallableFactory callableFactory;
- private CallableCollection callables;
-
- public Mock(CallableFactory callableFactory, CallableCollection callableAddable, Class mockedClass, String name) {
- this.name = name;
+
+ public Mock(CallableFactory callableFactory, CallableCollection callables, Class mockedClass, String name) {
+ super(mockedClass, name, callables);
+
this.callableFactory = callableFactory;
- this.callables = callableAddable;
- this.proxy = Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { mockedClass }, this);
}
public Mock(Class mockedClass, String nonDefaultName) {
@@ -64,52 +56,6 @@
}
}
- public String getMockName() {
- return this.name;
- }
-
- public String toString() {
- return this.name;
- }
-
- public Object proxy() {
- return this.proxy;
- }
-
- public Object invoke(Object proxy, Method method, Object[] args)
- throws Throwable {
- try {
- ActiveCall activeCall = new ActiveCall(method, args);
-
- if (isCheckingEqualityOnProxy(activeCall)) {
- return new Boolean(args[0] == this.proxy);
- } else if (isMockNameGetter(activeCall)) {
- return this.getMockName();
- } else {
- return callables.call(activeCall);
- }
- } catch (AssertionFailedError ex) {
- throw new AssertionFailedError(name + ": " + ex.getMessage());
- }
- }
-
- private boolean isCheckingEqualityOnProxy(ActiveCall call) {
- return (call.getMethodName().equals("equals")) && (call.args.length == 1)
- && (Proxy.isProxyClass(call.args[0].getClass()));
- }
-
- private boolean isMockNameGetter(ActiveCall call) {
- return (call.getMethodName().equals("getMockName")) && (call.args.length == 0);
- }
-
- public void verify() {
- try {
- callables.verify();
- } catch (AssertionFailedError ex) {
- throw new AssertionFailedError(name + ": " + ex.getMessage());
- }
- }
-
public void expect(String methodName) {
expect(methodName, C.NO_ARGS);
}
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic
In directory sc8-pr-cvs1:/tmp/cvs-serv12659/core/com/mockobjects/dynamic
Modified Files:
Tag: MethodMatcherAlternative
DefaultCallFactory.java C.java CallFactory.java
CallSignature.java Mock.java
Log Message:
Little experiment to do Mocks a different way.
Broken tests - and nothing interesting yet.
Index: DefaultCallFactory.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/DefaultCallFactory.java,v
retrieving revision 1.5
retrieving revision 1.5.4.1
diff -u -r1.5 -r1.5.4.1
--- DefaultCallFactory.java 20 May 2003 00:05:24 -0000 1.5
+++ DefaultCallFactory.java 6 Jul 2003 14:21:28 -0000 1.5.4.1
@@ -1,25 +1,23 @@
package com.mockobjects.dynamic;
-public class DefaultCallFactory implements CallFactory {
-
- public Callable createReturnStub(Object result) {
- return new ReturnStub(result);
- }
+import com.mockobjects.constraint.Constraint;
- public Callable createThrowStub( Throwable exception ) {
- return new ThrowStub(exception);
- }
+public class DefaultCallFactory implements CallFactory {
public Callable createCallExpectation(Callable call) {
- return new CallOnceExpectation(call);
+ return new CallOnceExpectation(call);
+ }
+
+ public Callable createMethodCallWithException(String methodName, Constraint[] constraints, Throwable ex) {
+ return new CallSignature( methodName, constraints, new ThrowStub(ex));
}
- public Callable createCallSignature(String methodName, ConstraintMatcher constraints, Callable call) {
- return new CallSignature( methodName, constraints, call );
+ public Callable createMethodCallWithReturn(String methodName, Constraint[] constraints, Object result) {
+ return new CallSignature( methodName, constraints, new ReturnStub(result));
}
- public Callable createVoidStub() {
- return new VoidStub();
+ public Callable createMethodCallWithVoid(String methodName, Constraint[] constraints) {
+ return new CallSignature( methodName, constraints, new VoidStub());
}
}
Index: C.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/C.java,v
retrieving revision 1.3
retrieving revision 1.3.4.1
diff -u -r1.3 -r1.3.4.1
--- C.java 1 Jun 2003 11:40:45 -0000 1.3
+++ C.java 6 Jul 2003 14:21:28 -0000 1.3.4.1
@@ -19,8 +19,8 @@
public static final Constraint IS_ZERO = eq(new Integer(0));
public static final Constraint IS_NOT_ZERO = not(IS_ZERO);
- public static final ConstraintMatcher NO_ARGS = new FullConstraintMatcher(new Constraint[0]);
- public static final ConstraintMatcher ANY_ARGS = new AnyConstraintMatcher();
+ public static final Constraint[] NO_ARGS = new Constraint[0];
+ public static final Constraint[] ANY_ARGS = new Constraint[0];
public static Constraint same( Object o ) {
return new IsSame(o);
@@ -30,15 +30,15 @@
return new IsEqual(o);
}
- public static ConstraintMatcher eq( Object arg0, Object arg1 ) {
+ public static Constraint[] eq( Object arg0, Object arg1 ) {
return args(eq(arg0), eq(arg1));
}
- public static ConstraintMatcher eq( Object arg0, Object arg1, Object arg2 ) {
+ public static Constraint[] eq( Object arg0, Object arg1, Object arg2 ) {
return args(eq(arg0), eq(arg1), eq(arg2));
}
- public static ConstraintMatcher eq( Object arg0, Object arg1, Object arg2, Object arg3 ) {
+ public static Constraint[] eq( Object arg0, Object arg1, Object arg2, Object arg3 ) {
return args(eq(arg0), eq(arg1), eq(arg2), eq(arg3));
}
@@ -107,32 +107,32 @@
/* Helper methods for succinctly constructing Constraint arrays
*/
- public static ConstraintMatcher args() {
+ public static Constraint[] args() {
return NO_ARGS;
}
- public static ConstraintMatcher args(Constraint p) {
- return new FullConstraintMatcher(new Constraint[]{p});
+ public static Constraint[] args(Constraint p) {
+ return new Constraint[]{p};
}
- public static ConstraintMatcher args(Constraint p1, Constraint p2) {
- return new FullConstraintMatcher(new Constraint[]{p1, p2});
+ public static Constraint[] args(Constraint p1, Constraint p2) {
+ return new Constraint[]{p1, p2};
}
- public static ConstraintMatcher args(Constraint p1, Constraint p2, Constraint p3) {
- return new FullConstraintMatcher(new Constraint[]{p1, p2, p3});
+ public static Constraint[] args(Constraint p1, Constraint p2, Constraint p3) {
+ return new Constraint[]{p1, p2, p3};
}
- public static ConstraintMatcher args(Constraint p1, Constraint p2, Constraint p3, Constraint p4) {
- return new FullConstraintMatcher(new Constraint[]{p1, p2, p3, p4});
+ public static Constraint[] args(Constraint p1, Constraint p2, Constraint p3, Constraint p4) {
+ return new Constraint[]{p1, p2, p3, p4};
}
- public static ConstraintMatcher anyArgs( int argCount) {
+ public static Constraint[] anyArgs( int argCount) {
Constraint[] constraints = new Constraint[argCount];
for (int i = 0; i < constraints.length; i++) {
constraints[i] = new IsAnything();
}
- return new FullConstraintMatcher(constraints);
+ return constraints;
}
}
Index: CallFactory.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Attic/CallFactory.java,v
retrieving revision 1.4
retrieving revision 1.4.4.1
diff -u -r1.4 -r1.4.4.1
--- CallFactory.java 19 May 2003 23:56:23 -0000 1.4
+++ CallFactory.java 6 Jul 2003 14:21:28 -0000 1.4.4.1
@@ -1,9 +1,11 @@
package com.mockobjects.dynamic;
+import com.mockobjects.constraint.Constraint;
+
public interface CallFactory {
- Callable createReturnStub( Object result );
- Callable createThrowStub( Throwable throwable );
- Callable createVoidStub();
Callable createCallExpectation( Callable call );
- Callable createCallSignature( String methodName, ConstraintMatcher constraints, Callable call );
+
+ Callable createMethodCallWithVoid(String methodName, Constraint[] constraints);
+ Callable createMethodCallWithException(String methodName, Constraint[] constraints, Throwable ex);
+ Callable createMethodCallWithReturn(String methodName, Constraint[] constraints, Object result);
}
Index: CallSignature.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallSignature.java,v
retrieving revision 1.3
retrieving revision 1.3.2.1
diff -u -r1.3 -r1.3.2.1
--- CallSignature.java 5 Jul 2003 15:15:54 -0000 1.3
+++ CallSignature.java 6 Jul 2003 14:21:29 -0000 1.3.2.1
@@ -1,14 +1,16 @@
package com.mockobjects.dynamic;
+import com.mockobjects.constraint.Constraint;
+
import junit.framework.Assert;
public class CallSignature extends Assert implements Callable
{
private String methodName;
- private ConstraintMatcher constraints;
+ private Constraint[] constraints;
private Callable delegate;
- public CallSignature( String methodName, ConstraintMatcher constraints, Callable delegate ) {
+ public CallSignature( String methodName, Constraint[] constraints, Callable delegate ) {
this.methodName = methodName;
this.constraints = constraints;
this.delegate = delegate;
@@ -24,12 +26,22 @@
delegate.verify();
}
+ private boolean matches(Constraint[] constraints, Object[] args) {
+
+ if( args.length != constraints.length ) return false;
+
+ for (int i = 0; i < args.length; i++) {
+ if( !constraints[i].eval(args[i]) ) return false;
+ }
+ return true;
+ }
+
public boolean matches(ActiveCall activeCall) {
- return this.methodName.equals(activeCall.getMethodName()) && constraints.matches(activeCall.args);
+ return this.methodName.equals(activeCall.getMethodName()) && matches(constraints, activeCall.args);
}
public String getDescription() {
- return DynamicUtil.methodToString(methodName, constraints.getConstraints());
+ return DynamicUtil.methodToString(methodName, constraints);
}
// Implemented to aid visualisation in an IDE debugger
Index: Mock.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Mock.java,v
retrieving revision 1.25
retrieving revision 1.25.2.1
diff -u -r1.25 -r1.25.2.1
--- Mock.java 5 Jul 2003 15:15:54 -0000 1.25
+++ Mock.java 6 Jul 2003 14:21:29 -0000 1.25.2.1
@@ -49,13 +49,13 @@
}
}
- private ConstraintMatcher createConstraintMatcher(Object constraintArg) {
+ private Constraint[] createConstraints(Object constraintArg) {
// Can't overload this method as callee had an Object parameter, and java
// doesn't do a secondary dispatch on the true underlying type
if (constraintArg instanceof Constraint[]) {
// to support possible legacy usage of new Contraint[] {...}
- return new FullConstraintMatcher((Constraint[])constraintArg);
+ return (Constraint[])constraintArg;
} else if (constraintArg instanceof Constraint) {
// to support usage of C.lt(5) type constraints
return C.args((Constraint)constraintArg);
@@ -116,13 +116,20 @@
}
public void expect(String methodName, Object singleEqualArg) {
- expect(methodName, createConstraintMatcher(singleEqualArg));
+ expect(methodName, createConstraints(singleEqualArg));
}
+ /** @deprecated */
public void expect(String methodName, ConstraintMatcher args) {
- calls.addExpect(callFactory.createCallExpectation(callFactory.createCallSignature(methodName, args, callFactory.createVoidStub())));
+ expect(methodName, args.getConstraints());
}
+ public void expect(String methodName, Constraint[] args) {
+ calls.addExpect(callFactory.createCallExpectation(
+ callFactory.createMethodCallWithVoid(methodName, args)));
+ }
+
+
public void expectAndReturn(String methodName, Object result) {
this.expectAndReturn(methodName, C.NO_ARGS, result);
}
@@ -136,7 +143,7 @@
}
public void expectAndReturn(String methodName, Object singleEqualArg, Object result) {
- this.expectAndReturn(methodName, createConstraintMatcher(singleEqualArg), result);
+ this.expectAndReturn(methodName, createConstraints(singleEqualArg), result);
}
public void expectAndReturn(String methodName, Object singleEqualArg, boolean result) {
@@ -147,16 +154,32 @@
this.expectAndReturn(methodName, singleEqualArg, new Integer(result));
}
- public void expectAndReturn(String methodName, ConstraintMatcher args, boolean result) {
+ public void expectAndReturn(String methodName, Constraint[] args, boolean result) {
this.expectAndReturn(methodName, args, new Boolean(result));
}
- public void expectAndReturn(String methodName, ConstraintMatcher args, int result) {
+ public void expectAndReturn(String methodName, Constraint[] args, int result) {
this.expectAndReturn(methodName, args, new Integer(result));
}
+ /** @deprecated */
+ public void expectAndReturn(String methodName, ConstraintMatcher args, boolean result) {
+ this.expectAndReturn(methodName, args.getConstraints(), result);
+ }
+
+ /** @deprecated */
+ public void expectAndReturn(String methodName, ConstraintMatcher args, int result) {
+ this.expectAndReturn(methodName, args.getConstraints(), result);
+ }
+
+ /** @deprecated */
public void expectAndReturn(String methodName, ConstraintMatcher args, Object result) {
- calls.addExpect(callFactory.createCallExpectation(callFactory.createCallSignature(methodName, args, callFactory.createReturnStub(result))));
+ this.expectAndReturn(methodName, args.getConstraints(), result);
+ }
+
+ public void expectAndReturn(String methodName, Constraint[] constraints, Object result) {
+ calls.addExpect(callFactory.createCallExpectation(
+ callFactory.createMethodCallWithReturn(methodName, constraints, result)));
}
public void expectAndThrow(String methodName, Throwable exception) {
@@ -164,11 +187,17 @@
}
public void expectAndThrow(String methodName, Object singleEqualArg, Throwable exception) {
- this.expectAndThrow(methodName, createConstraintMatcher(singleEqualArg), exception);
+ this.expectAndThrow(methodName, createConstraints(singleEqualArg), exception);
}
+ /** @deprecated */
public void expectAndThrow(String methodName, ConstraintMatcher args, Throwable exception) {
- calls.addExpect(callFactory.createCallExpectation(callFactory.createCallSignature(methodName, args, callFactory.createThrowStub(exception))));
+ expectAndThrow(methodName, args.getConstraints(), exception);
+ }
+
+ public void expectAndThrow(String methodName, Constraint[] constraints, Throwable exception) {
+ calls.addExpect(callFactory.createCallExpectation(
+ callFactory.createMethodCallWithException(methodName, constraints, exception)));
}
public void match(String methodName) {
@@ -176,7 +205,7 @@
}
public void match(String methodName, Object singleEqualArg) {
- match(methodName, createConstraintMatcher(singleEqualArg));
+ match(methodName, createConstraints(singleEqualArg));
}
public void match(String methodName, int singleEqualArg) {
@@ -187,8 +216,13 @@
match(methodName, new Boolean(singleEqualArg));
}
+ /** @deprecated */
public void match(String methodName, ConstraintMatcher args) {
- calls.addMatch(callFactory.createCallSignature(methodName, args, callFactory.createVoidStub()));
+ match(methodName, args.getConstraints());
+ }
+
+ public void match(String methodName, Constraint[] args) {
+ calls.addMatch(callFactory.createMethodCallWithVoid(methodName, args));
}
public void matchAndReturn(String methodName, Object result) {
@@ -204,7 +238,7 @@
}
public void matchAndReturn(String methodName, Object singleEqualArg, Object result) {
- this.matchAndReturn(methodName, createConstraintMatcher(singleEqualArg), result);
+ this.matchAndReturn(methodName, createConstraints(singleEqualArg), result);
}
public void matchAndReturn(String methodName, boolean singleEqualArg, Object result) {
@@ -227,12 +261,18 @@
this.matchAndReturn(methodName, args, new Boolean(result));
}
+ /** @deprecated */
public void matchAndReturn(String methodName, ConstraintMatcher args, int result) {
this.matchAndReturn(methodName, args, new Integer(result));
}
+ /** @deprecated */
public void matchAndReturn(String methodName, ConstraintMatcher args, Object result) {
- calls.addMatch(callFactory.createCallSignature(methodName, args, callFactory.createReturnStub(result)));
+ matchAndReturn(methodName, args.getConstraints(), result);
+ }
+
+ public void matchAndReturn(String methodName, Constraint[] args, Object result) {
+ calls.addMatch(callFactory.createMethodCallWithReturn(methodName, args, result));
}
public void matchAndThrow(String methodName, Throwable throwable) {
@@ -240,7 +280,7 @@
}
public void matchAndThrow(String methodName, Object singleEqualArg, Throwable throwable) {
- this.matchAndThrow(methodName, createConstraintMatcher(singleEqualArg), throwable);
+ this.matchAndThrow(methodName, createConstraints(singleEqualArg), throwable);
}
public void matchAndThrow(String methodName, boolean singleEqualArg, Throwable throwable) {
@@ -251,27 +291,14 @@
this.matchAndThrow(methodName,new Integer(singleEqualArg), throwable);
}
+ /** @deprecated */
public void matchAndThrow(String methodName, ConstraintMatcher args, Throwable throwable) {
- calls.addMatch(callFactory.createCallSignature(methodName, args, callFactory.createThrowStub(throwable)));
- }
-
- /** @deprecated @see OrderedMock
- */
- public void expect(String methodName, CallSequence deprecated) {
- throw new AssertionFailedError("method is deprecated! Use: new OrderedMock() instead...");
- }
-
- /** @deprecated @see OrderedMock
- */
- public void expectAndReturn(String methodName, CallSequence deprecated, Object result) {
- throw new AssertionFailedError("method is deprecated! Use: new OrderedMock() instead...");
- }
-
- /** @deprecated @see OrderedMock
- */
- public void expectAndThrow(String methodName, CallSequence deprecated, Throwable throwable) {
- throw new AssertionFailedError("method is deprecated! Use: new OrderedMock() instead...");
+ matchAndThrow(methodName, args.getConstraints(), throwable);
}
+
+ public void matchAndThrow(String methodName, Constraint[] args, Throwable throwable) {
+ calls.addMatch(callFactory.createMethodCallWithException(methodName, args, throwable));
+ }
/** @deprecated @see expect
*/
|
|
From: Tim M. <ma...@us...> - 2003-07-06 14:21:33
|
Update of /cvsroot/mockobjects/mockobjects-java/src
In directory sc8-pr-cvs1:/tmp/cvs-serv12659
Added Files:
Tag: MethodMatcherAlternative
.classpath
Log Message:
Little experiment to do Mocks a different way.
Broken tests - and nothing interesting yet.
--- NEW FILE: .classpath ---
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="core"/>
<classpathentry kind="src" path="examples"/>
<classpathentry kind="src" path="extensions"/>
<classpathentry kind="src" path="j2ee/1.3"/>
<classpathentry kind="src" path="j2ee/common"/>
<classpathentry kind="src" path="jdk/1.4"/>
<classpathentry kind="src" path="jdk/common"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path="/J2EE"/>
<classpathentry kind="src" path="/JSDK"/>
<classpathentry kind="src" path="/org.junit"/>
<classpathentry kind="output" path="bin"/>
</classpath>
|
|
From: Tim M. <ma...@us...> - 2003-07-06 14:21:33
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/constraint
In directory sc8-pr-cvs1:/tmp/cvs-serv12659/core/com/mockobjects/constraint
Modified Files:
Tag: MethodMatcherAlternative
IsEqual.java
Log Message:
Little experiment to do Mocks a different way.
Broken tests - and nothing interesting yet.
Index: IsEqual.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/constraint/IsEqual.java,v
retrieving revision 1.3
retrieving revision 1.3.4.1
diff -u -r1.3 -r1.3.4.1
--- IsEqual.java 18 May 2003 20:59:40 -0000 1.3
+++ IsEqual.java 6 Jul 2003 14:21:29 -0000 1.3.4.1
@@ -35,6 +35,11 @@
}
public boolean equals(Object anObject) {
- return eval(anObject);
+ if(anObject instanceof IsEqual) {
+ return eval(((IsEqual)anObject)._object);
+ } else {
+ return eval(anObject);
+ }
}
+
}
|
|
From: Tim M. <ma...@us...> - 2003-07-06 14:21:32
|
Update of /cvsroot/mockobjects/mockobjects-java/src/examples/com/mockobjects/examples/dynamic
In directory sc8-pr-cvs1:/tmp/cvs-serv12659/examples/com/mockobjects/examples/dynamic
Modified Files:
Tag: MethodMatcherAlternative
SimpleServletTest.java
Log Message:
Little experiment to do Mocks a different way.
Broken tests - and nothing interesting yet.
Index: SimpleServletTest.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/examples/com/mockobjects/examples/dynamic/SimpleServletTest.java,v
retrieving revision 1.3
retrieving revision 1.3.4.1
diff -u -r1.3 -r1.3.4.1
--- SimpleServletTest.java 19 May 2003 23:37:49 -0000 1.3
+++ SimpleServletTest.java 6 Jul 2003 14:21:29 -0000 1.3.4.1
@@ -58,6 +58,19 @@
mockHttpServletRequest.matchAndReturn( "getParameter", C.eq("browser-identifier"), "MSIE-5.0" );
mockHttpServletRequest.matchAndReturn("getIntHeader", C.ANY_ARGS, 20);
+ /*
+ mock.expect(new CallOnce("getP", C.eq("browser")));
+ mock.match(new CallMany("getP", C.eq("browser")));
+ mock.match(new CallCount(5, "getP"))
+ mock.match(new CallAny(""))
+
+
+ mock.expectAndReturn(Call.once("getP", C.eq("browser")), "result");
+ mock.expectAndThrow
+
+ */
+
+
mockHttpServletRequest.expectAndReturn( "getParameter", "subject", SUBJECT );
mockHttpServletRequest.expectAndReturn("getParameterValues", "recipients", RECIPIENTS);
mockHttpServletRequest.expectAndReturn( "getParameter", C.args(C.eq("body")), BODY );
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic
In directory sc8-pr-cvs1:/tmp/cvs-serv12659/core/test/mockobjects/dynamic
Modified Files:
Tag: MethodMatcherAlternative
MockTest.java MockCallFactory.java CallSequenceTest.java
Added Files:
Tag: MethodMatcherAlternative
CallFactoryTest.java
Log Message:
Little experiment to do Mocks a different way.
Broken tests - and nothing interesting yet.
--- NEW FILE: CallFactoryTest.java ---
/*
* Created on 06-Jul-2003
*/
package test.mockobjects.dynamic;
import com.mockobjects.dynamic.ActiveCall;
import com.mockobjects.dynamic.C;
import com.mockobjects.dynamic.CallFactory;
import com.mockobjects.dynamic.Callable;
import com.mockobjects.dynamic.DefaultCallFactory;
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
public class CallFactoryTest extends TestCase {
private final String METHOD_NAME1 = "method1";
private final String METHOD_NAME2 = "method2";
private final Object[] METHOD_ARGS = new Object[0];
private CallFactory myCallFactory = new DefaultCallFactory();
private ActiveCall myMethod1 = new ActiveCall(METHOD_NAME1, METHOD_ARGS);
private ActiveCall myMethod2 = new ActiveCall(METHOD_NAME2, METHOD_ARGS);
public CallFactoryTest(String name) {
super(name);
}
public void testCreateReturnStub() throws Throwable {
Callable methodCall = myCallFactory.createMethodCallWithReturn(METHOD_NAME1, C.NO_ARGS, "result");
assertTrue("Should match method1", methodCall.matches(myMethod1));
assertFalse("Should not match method2", methodCall.matches(myMethod2));
assertEquals("Should get a result", "result", methodCall.call(myMethod1));
}
public void testCreateVoidStub() throws Throwable {
Callable methodCall = myCallFactory.createMethodCallWithVoid(METHOD_NAME1, C.NO_ARGS);
assertTrue("Should match method1", methodCall.matches(myMethod1));
assertFalse("Should not match method2", methodCall.matches(myMethod2));
assertEquals("Should get a void result", null, methodCall.call(myMethod1));
}
public void testCreateMethodCallWithException() throws Throwable {
Callable methodCall = myCallFactory.createMethodCallWithException(METHOD_NAME1, C.NO_ARGS, new RuntimeException("An exception"));
assertTrue("Should match method1", methodCall.matches(myMethod1));
assertFalse("Should not match method2", methodCall.matches(myMethod2));
try {
methodCall.call(myMethod1);
fail("Should get an exception");
} catch(RuntimeException e) {
//pass
}
}
}
Index: MockTest.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockTest.java,v
retrieving revision 1.14
retrieving revision 1.14.2.1
diff -u -r1.14 -r1.14.2.1
--- MockTest.java 5 Jul 2003 15:15:54 -0000 1.14
+++ MockTest.java 6 Jul 2003 14:21:29 -0000 1.14.2.1
@@ -4,7 +4,6 @@
package test.mockobjects.dynamic;
import com.mockobjects.constraint.*;
-import com.mockobjects.constraint.IsEqual;
import com.mockobjects.dynamic.*;
import com.mockobjects.util.*;
@@ -13,27 +12,33 @@
public class MockTest extends TestCase {
private static final String MOCK_NAME = "Test mock";
+
final String METHOD_NOARG_NAME = "noArgMethodVoid";
- final String METHOD_NOARGANDRETURN_NAME = "noArgMethod";
- final String METHOD_NOARGANDRETURN_RESULT = "resultNoArgs";
+ final int METHOD_NOARG_RESULT = 100;
+
final String METHOD_ONEARG_NAME = "oneArgMethod";
final String METHOD_ONEARG_RESULT = "result1Args";
+
final String METHOD_TWOARG_NAME = "twoArgMethod";
- final String METHOD_TWOARG_RESULT = "resultTwoArgs";
+ final boolean METHOD_TWOARG_RESULT = true;
+
+ final String ONE_PARAM_VALUE = "p1";
+ final int TWO_PARAM_VALUE = 54;
+
+ final Constraint[] ONE_PARAM_CONSTRAINT = C.args(C.eq(ONE_PARAM_VALUE));
+ final Constraint[] TWO_PARAM_CONSTRAINT = C.args(C.eq(ONE_PARAM_VALUE), C.gt(TWO_PARAM_VALUE));
+
final Throwable METHOD_EXCEPTION = new DummyThrowable("Configured test throwable");
final Object[] METHOD_NOARG_ARGS = new Object[0];
final String[] METHOD_ONEARG_ARGS = new String[] { "oneP1" };
- final ConstraintMatcher METHOD_ONEARG_CONSTRAINTS = C.args(C.eq("oneP1"));
+ final Constraint[] METHOD_ONEARG_CONSTRAINTS = C.args(C.eq("oneP1"));
final String[] METHOD_TWOARG_ARGS = new String[] { "twoP1", "twoP2" };
- final ConstraintMatcher METHOD_TWOARG_CONSTRAINTS = C.args(C.eq("twoP1"), C.eq("twoP2"));
+ final Constraint[] METHOD_TWOARG_CONSTRAINTS = C.args(C.eq("twoP1"), C.eq("twoP2"));
private DummyInterface proxy;
private Mock mock;
private MockCallFactory mockCallFactory = new MockCallFactory();
- private MockCallable mockCallMatch = new MockCallable("call match");
- private MockCallable mockExpectedCall = new MockCallable("expected call");
- private MockCallable mockReturnStub = new MockCallable("return stub");
- private MockCallable mockThrowStub = new MockCallable("throw stub");
- private MockCallable mockVoidStub = new MockCallable("void stub");
+ private MockCallable mockCall = new MockCallable("call match");
+
private MockCallableAddable mockCallableAddable = new MockCallableAddable();
public MockTest(String name) throws Exception {
@@ -48,319 +53,197 @@
} catch (ClassCastException ex) {
fail("proxy is not of expected interface type");
}
+
+ mockCallFactory.setupCreateCallExpectation(mockCall);
}
public void testExpectManyAndVoid() throws Throwable {
- mockCallFactory.setExpectedCreateVoidStubCalls(1);
- mockCallFactory.setupCreateVoidStub(mockVoidStub);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockVoidStub);
- mockCallFactory.setupCreateCallSignature(mockCallMatch);
- mockCallFactory.addExpectedCreateCallExpectation(mockCallMatch);
- mockCallFactory.setupCreateCallExpectation(mockExpectedCall);
-
- mockCallableAddable.addExpectedAddExpect(mockExpectedCall);
-
- mock.expect(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS);
-
+ mockCallFactory.addExpectedCreateMethodCallWithVoid(METHOD_TWOARG_NAME, TWO_PARAM_CONSTRAINT);
+ mockCallFactory.setupCreateMethodCallWithVoid(mockCall);
+ mockCallFactory.addExpectedCreateCallExpectation(mockCall);
+ mockCallableAddable.addExpectedAddExpect(mockCall);
+
+ mock.expect(METHOD_TWOARG_NAME, TWO_PARAM_CONSTRAINT);
+
Verifier.verifyObject(this);
- mockCallableAddable.verifyExpectations();
}
public void testExpectNoneAndReturn() throws Throwable {
- mockCallFactory.addExpectedCreateReturnStub(METHOD_NOARGANDRETURN_RESULT);
- mockCallFactory.setupCreateReturnStub(mockReturnStub);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_NOARGANDRETURN_NAME, C.NO_ARGS, mockReturnStub);
- mockCallFactory.setupCreateCallSignature(mockCallMatch);
- mockCallFactory.addExpectedCreateCallExpectation(mockCallMatch);
- mockCallFactory.setupCreateCallExpectation(mockExpectedCall);
-
- mockCallableAddable.addExpectedAddExpect(mockExpectedCall);
-
- mock.expectAndReturn(METHOD_NOARGANDRETURN_NAME, METHOD_NOARGANDRETURN_RESULT);
-
+ mockCallFactory.addExpectedCreateMethodCallWithReturn(METHOD_NOARG_NAME, C.NO_ARGS, new Integer(METHOD_NOARG_RESULT));
+ mockCallFactory.setupCreateMethodCallWithReturn(mockCall);
+ mockCallFactory.addExpectedCreateCallExpectation(mockCall);
+ mockCallableAddable.addExpectedAddExpect(mockCall);
+
+ mock.expectAndReturn(METHOD_NOARG_NAME, METHOD_NOARG_RESULT);
+
Verifier.verifyObject(this);
- mockCallableAddable.verifyExpectations();
}
public void testExpectNoneAndThrow() throws Throwable {
- mockCallFactory.addExpectedCreateThrowStub(METHOD_EXCEPTION);
- mockCallFactory.setupCreateThrowStub(mockThrowStub);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_NOARGANDRETURN_NAME, C.NO_ARGS, mockThrowStub);
- mockCallFactory.setupCreateCallSignature(mockCallMatch);
- mockCallFactory.addExpectedCreateCallExpectation(mockCallMatch);
- mockCallFactory.setupCreateCallExpectation(mockExpectedCall);
+ mockCallFactory.addExpectedCreateMethodCallWithException(METHOD_NOARG_NAME, C.NO_ARGS, METHOD_EXCEPTION);
+ mockCallFactory.setupCreateMethodCallWithException(mockCall);
+ mockCallFactory.addExpectedCreateCallExpectation(mockCall);
+ mockCallableAddable.addExpectedAddExpect(mockCall);
- mockCallableAddable.addExpectedAddExpect(mockExpectedCall);
-
- mock.expectAndThrow(METHOD_NOARGANDRETURN_NAME, METHOD_EXCEPTION);
+ mock.expectAndThrow(METHOD_NOARG_NAME, METHOD_EXCEPTION);
Verifier.verifyObject(this);
- mockCallableAddable.verifyExpectations();
}
public void testExpectOneAndThrow() throws Throwable {
- mockCallFactory.addExpectedCreateThrowStub(METHOD_EXCEPTION);
- mockCallFactory.setupCreateThrowStub(mockThrowStub);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockThrowStub);
- mockCallFactory.setupCreateCallSignature(mockCallMatch);
- mockCallFactory.addExpectedCreateCallExpectation(mockCallMatch);
- mockCallFactory.setupCreateCallExpectation(mockExpectedCall);
+ mockCallFactory.addExpectedCreateMethodCallWithException(METHOD_ONEARG_NAME, ONE_PARAM_CONSTRAINT, METHOD_EXCEPTION);
+ mockCallFactory.setupCreateMethodCallWithException(mockCall);
+ mockCallFactory.addExpectedCreateCallExpectation(mockCall);
+ mockCallableAddable.addExpectedAddExpect(mockCall);
- mockCallableAddable.addExpectedAddExpect(mockExpectedCall);
-
- mock.expectAndThrow(METHOD_ONEARG_NAME, METHOD_ONEARG_ARGS[0], METHOD_EXCEPTION);
+ mock.expectAndThrow(METHOD_ONEARG_NAME, ONE_PARAM_VALUE, METHOD_EXCEPTION);
Verifier.verifyObject(this);
- mockCallableAddable.verifyExpectations();
}
public void testExpectNoneAndVoid() throws Throwable {
- mockCallFactory.setExpectedCreateVoidStubCalls(1);
- mockCallFactory.setupCreateVoidStub(mockVoidStub);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_NOARG_NAME, C.NO_ARGS, mockVoidStub);
- mockCallFactory.setupCreateCallSignature(mockCallMatch);
- mockCallFactory.addExpectedCreateCallExpectation(mockCallMatch);
- mockCallFactory.setupCreateCallExpectation(mockExpectedCall);
-
- mockCallableAddable.addExpectedAddExpect(mockExpectedCall);
+ mockCallFactory.addExpectedCreateMethodCallWithVoid(METHOD_NOARG_NAME, C.NO_ARGS);
+ mockCallFactory.setupCreateMethodCallWithVoid(mockCall);
+ mockCallFactory.addExpectedCreateCallExpectation(mockCall);
+ mockCallableAddable.addExpectedAddExpect(mockCall);
mock.expect(METHOD_NOARG_NAME);
Verifier.verifyObject(this);
- mockCallableAddable.verifyExpectations();
}
public void testExpectOneAndVoid() throws Throwable {
- mockCallFactory.setExpectedCreateVoidStubCalls(1);
- mockCallFactory.setupCreateVoidStub(mockVoidStub);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockVoidStub);
- mockCallFactory.setupCreateCallSignature(mockCallMatch);
- mockCallFactory.addExpectedCreateCallExpectation(mockCallMatch);
- mockCallFactory.setupCreateCallExpectation(mockExpectedCall);
-
- mockCallableAddable.addExpectedAddExpect(mockExpectedCall);
-
- mock.expect(METHOD_ONEARG_NAME, METHOD_ONEARG_ARGS[0]);
-
- Verifier.verifyObject(this);
- mockCallableAddable.verifyExpectations();
- }
+ mockCallFactory.addExpectedCreateMethodCallWithVoid(METHOD_ONEARG_NAME, ONE_PARAM_CONSTRAINT);
+ mockCallFactory.setupCreateMethodCallWithVoid(mockCall);
+ mockCallFactory.addExpectedCreateCallExpectation(mockCall);
+ mockCallableAddable.addExpectedAddExpect(mockCall);
- public void testExpectWithConstraint() throws Throwable {
- mockCallFactory.setupCreateVoidStub(mockVoidStub);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockVoidStub);
- mockCallFactory.setupCreateCallSignature(mockCallMatch);
- mockCallFactory.setupCreateCallExpectation(mockExpectedCall);
-
- mockCallableAddable.addExpectedAddExpect(mockExpectedCall);
-
- mock.expect(METHOD_ONEARG_NAME, new IsEqual(METHOD_ONEARG_ARGS[0]));
-
- Verifier.verifyObject(this);
- mockCallableAddable.verifyExpectations();
- }
+ mock.expect(METHOD_ONEARG_NAME, ONE_PARAM_VALUE);
- public void testExpectWithConstraintArray() throws Throwable {
- mockCallFactory.setupCreateVoidStub(mockVoidStub);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockVoidStub);
- mockCallFactory.setupCreateCallSignature(mockCallMatch);
- mockCallFactory.setupCreateCallExpectation(mockExpectedCall);
-
- mockCallableAddable.addExpectedAddExpect(mockExpectedCall);
-
- mock.expect(METHOD_ONEARG_NAME, new Constraint[] { new IsEqual(METHOD_ONEARG_ARGS[0])});
-
Verifier.verifyObject(this);
- mockCallableAddable.verifyExpectations();
}
-
-
+
public void testExpectManyAndReturn() throws Throwable {
- mockCallFactory.addExpectedCreateReturnStub(METHOD_TWOARG_RESULT);
- mockCallFactory.setupCreateReturnStub(mockReturnStub);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockReturnStub);
- mockCallFactory.setupCreateCallSignature(mockCallMatch);
- mockCallFactory.addExpectedCreateCallExpectation(mockCallMatch);
- mockCallFactory.setupCreateCallExpectation(mockExpectedCall);
-
- mockCallableAddable.addExpectedAddExpect(mockExpectedCall);
- mockCallableAddable.setupCall(METHOD_TWOARG_RESULT);
-
- mock.expectAndReturn(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, METHOD_TWOARG_RESULT);
+ mockCallFactory.addExpectedCreateMethodCallWithReturn(METHOD_TWOARG_NAME, TWO_PARAM_CONSTRAINT, new Boolean(METHOD_TWOARG_RESULT));
+ mockCallFactory.setupCreateMethodCallWithReturn(mockCall);
+ mockCallFactory.addExpectedCreateCallExpectation(mockCall);
+ mockCallableAddable.addExpectedAddExpect(mockCall);
+
+ mock.expectAndReturn(METHOD_TWOARG_NAME, TWO_PARAM_CONSTRAINT, METHOD_TWOARG_RESULT);
- Verifier.verifyObject(this);
- mockCallableAddable.verifyExpectations();
+ mockCallFactory.verify();
}
public void testExpectManyAndThrow() throws Throwable {
- mockCallFactory.addExpectedCreateThrowStub(METHOD_EXCEPTION);
- mockCallFactory.setupCreateThrowStub(mockThrowStub);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockThrowStub);
- mockCallFactory.setupCreateCallSignature(mockCallMatch);
- mockCallFactory.addExpectedCreateCallExpectation(mockCallMatch);
- mockCallFactory.setupCreateCallExpectation(mockExpectedCall);
+ mockCallFactory.addExpectedCreateMethodCallWithException(METHOD_TWOARG_NAME, TWO_PARAM_CONSTRAINT, METHOD_EXCEPTION);
+ mockCallFactory.setupCreateMethodCallWithException(mockCall);
+ mockCallFactory.addExpectedCreateCallExpectation(mockCall);
+ mockCallableAddable.addExpectedAddExpect(mockCall);
- mockCallableAddable.addExpectedAddExpect(mockExpectedCall);
- mockCallableAddable.setupCall(METHOD_TWOARG_RESULT);
-
- mock.expectAndThrow(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, METHOD_EXCEPTION);
+ mock.expectAndThrow(METHOD_TWOARG_NAME, TWO_PARAM_CONSTRAINT, METHOD_EXCEPTION);
Verifier.verifyObject(this);
- mockCallableAddable.verifyExpectations();
}
public void testExpectOneAndReturn() throws Throwable {
- mockCallFactory.addExpectedCreateReturnStub(METHOD_ONEARG_RESULT);
- mockCallFactory.setupCreateReturnStub(mockReturnStub);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockReturnStub);
- mockCallFactory.setupCreateCallSignature(mockCallMatch);
- mockCallFactory.addExpectedCreateCallExpectation(mockCallMatch);
- mockCallFactory.setupCreateCallExpectation(mockExpectedCall);
-
- mockCallableAddable.addExpectedAddExpect(mockExpectedCall);
- mockCallableAddable.setupCall(METHOD_ONEARG_RESULT);
-
- mock.expectAndReturn(METHOD_ONEARG_NAME, METHOD_ONEARG_ARGS[0], METHOD_ONEARG_RESULT);
+ mockCallFactory.addExpectedCreateMethodCallWithReturn(METHOD_ONEARG_NAME, ONE_PARAM_CONSTRAINT, METHOD_ONEARG_RESULT);
+ mockCallFactory.setupCreateMethodCallWithReturn(mockCall);
+ mockCallFactory.addExpectedCreateCallExpectation(mockCall);
+ mockCallableAddable.addExpectedAddExpect(mockCall);
+
+ mock.expectAndReturn(METHOD_ONEARG_NAME, ONE_PARAM_VALUE, METHOD_ONEARG_RESULT);
Verifier.verifyObject(this);
- mockCallableAddable.verifyExpectations();
}
public void testMatchNoneAndVoid() throws Throwable {
- mockCallFactory.setExpectedCreateVoidStubCalls(1);
- mockCallFactory.setupCreateVoidStub(mockVoidStub);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_NOARG_NAME, C.NO_ARGS, mockVoidStub);
- mockCallFactory.setupCreateCallSignature(mockCallMatch);
+ mockCallFactory.addExpectedCreateMethodCallWithVoid(METHOD_NOARG_NAME, C.NO_ARGS);
+ mockCallFactory.setupCreateMethodCallWithVoid(mockCall);
+ mockCallableAddable.addExpectedAddMatch(mockCall);
- mockCallableAddable.addExpectedAddMatch(mockCallMatch);
- mockCallableAddable.setupCall(METHOD_NOARGANDRETURN_RESULT);
-
mock.match(METHOD_NOARG_NAME);
Verifier.verifyObject(this);
- mockCallableAddable.verifyExpectations();
}
public void testMatchNoneAndReturn() throws Throwable {
- mockCallFactory.addExpectedCreateReturnStub(METHOD_NOARGANDRETURN_RESULT);
- mockCallFactory.setupCreateReturnStub(mockReturnStub);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_NOARG_NAME, C.NO_ARGS, mockReturnStub);
- mockCallFactory.setupCreateCallSignature(mockCallMatch);
-
- mockCallableAddable.addExpectedAddMatch(mockCallMatch);
- mockCallableAddable.setupCall(METHOD_ONEARG_RESULT);
-
- mock.matchAndReturn(METHOD_NOARG_NAME, METHOD_NOARGANDRETURN_RESULT);
-
+ mockCallFactory.addExpectedCreateMethodCallWithReturn(METHOD_NOARG_NAME, C.NO_ARGS, new Integer(METHOD_NOARG_RESULT));
+ mockCallFactory.setupCreateMethodCallWithReturn(mockCall);
+ mockCallableAddable.addExpectedAddMatch(mockCall);
+
+ mock.matchAndReturn(METHOD_NOARG_NAME, METHOD_NOARG_RESULT);
+
Verifier.verifyObject(this);
- mockCallableAddable.verifyExpectations();
}
public void testMatchNoneAndThrow() throws Throwable {
- mockCallFactory.addExpectedCreateThrowStub(METHOD_EXCEPTION);
- mockCallFactory.setupCreateThrowStub(mockThrowStub);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_NOARG_NAME, C.NO_ARGS, mockThrowStub);
- mockCallFactory.setupCreateCallSignature(mockCallMatch);
-
- mockCallableAddable.addExpectedAddMatch(mockCallMatch);
- mockCallableAddable.setupCall(METHOD_NOARGANDRETURN_RESULT);
+ mockCallFactory.addExpectedCreateMethodCallWithException(METHOD_NOARG_NAME, C.NO_ARGS, METHOD_EXCEPTION);
+ mockCallFactory.setupCreateMethodCallWithException(mockCall);
+ mockCallableAddable.addExpectedAddMatch(mockCall);
mock.matchAndThrow(METHOD_NOARG_NAME, METHOD_EXCEPTION);
Verifier.verifyObject(this);
- mockCallableAddable.verifyExpectations();
}
public void testMatchOneAndVoid() throws Throwable {
- mockCallFactory.setExpectedCreateVoidStubCalls(1);
- mockCallFactory.setupCreateVoidStub(mockVoidStub);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockVoidStub);
- mockCallFactory.setupCreateCallSignature(mockCallMatch);
- mockCallFactory.addExpectedCreateCallExpectation(mockCallMatch);
- mockCallFactory.setupCreateCallExpectation(mockExpectedCall);
-
- mockCallableAddable.addExpectedAddMatch(mockCallMatch);
-
- mock.match(METHOD_ONEARG_NAME, METHOD_ONEARG_ARGS[0]);
-
+ mockCallFactory.addExpectedCreateMethodCallWithVoid(METHOD_ONEARG_NAME, ONE_PARAM_CONSTRAINT);
+ mockCallFactory.setupCreateMethodCallWithVoid(mockCall);
+ mockCallableAddable.addExpectedAddMatch(mockCall);
+
+ mock.match(METHOD_ONEARG_NAME, ONE_PARAM_VALUE);
+
Verifier.verifyObject(this);
- mockCallableAddable.verifyExpectations();
}
public void testMatchOneAndReturn() throws Throwable {
- mockCallFactory.addExpectedCreateReturnStub(METHOD_ONEARG_RESULT);
- mockCallFactory.setupCreateReturnStub(mockReturnStub);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockReturnStub);
- mockCallFactory.setupCreateCallSignature(mockCallMatch);
-
- mockCallableAddable.addExpectedAddMatch(mockCallMatch);
- mockCallableAddable.setupCall(METHOD_ONEARG_RESULT);
-
- mock.matchAndReturn(METHOD_ONEARG_NAME, METHOD_ONEARG_ARGS[0], METHOD_ONEARG_RESULT);
+ mockCallFactory.addExpectedCreateMethodCallWithReturn(METHOD_ONEARG_NAME, ONE_PARAM_CONSTRAINT, METHOD_ONEARG_RESULT);
+ mockCallFactory.setupCreateMethodCallWithReturn(mockCall);
+ mockCallableAddable.addExpectedAddMatch(mockCall);
+
+ mock.matchAndReturn(METHOD_ONEARG_NAME, ONE_PARAM_VALUE, METHOD_ONEARG_RESULT);
Verifier.verifyObject(this);
- mockCallableAddable.verifyExpectations();
}
public void testMatchOneAndThrow() throws Throwable {
- mockCallFactory.addExpectedCreateThrowStub(METHOD_EXCEPTION);
- mockCallFactory.setupCreateThrowStub(mockThrowStub);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockThrowStub);
- mockCallFactory.setupCreateCallSignature(mockCallMatch);
+ mockCallFactory.addExpectedCreateMethodCallWithException(METHOD_ONEARG_NAME, ONE_PARAM_CONSTRAINT, METHOD_EXCEPTION);
+ mockCallFactory.setupCreateMethodCallWithException(mockCall);
+ mockCallableAddable.addExpectedAddMatch(mockCall);
- mockCallableAddable.addExpectedAddMatch(mockCallMatch);
- mockCallableAddable.setupCall(METHOD_ONEARG_RESULT);
-
- mock.matchAndThrow(METHOD_ONEARG_NAME, METHOD_ONEARG_ARGS[0], METHOD_EXCEPTION);
+ mock.matchAndThrow(METHOD_ONEARG_NAME, ONE_PARAM_VALUE, METHOD_EXCEPTION);
Verifier.verifyObject(this);
- mockCallableAddable.verifyExpectations();
}
public void testMatchManyAndVoid() throws Throwable {
- mockCallFactory.setExpectedCreateVoidStubCalls(1);
- mockCallFactory.setupCreateVoidStub(mockVoidStub);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockVoidStub);
- mockCallFactory.setupCreateCallSignature(mockCallMatch);
- mockCallFactory.addExpectedCreateCallExpectation(mockCallMatch);
- mockCallFactory.setupCreateCallExpectation(mockExpectedCall);
-
- mockCallableAddable.addExpectedAddMatch(mockCallMatch);
-
- mock.match(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS);
-
+ mockCallFactory.addExpectedCreateMethodCallWithVoid(METHOD_TWOARG_NAME, TWO_PARAM_CONSTRAINT);
+ mockCallFactory.setupCreateMethodCallWithVoid(mockCall);
+ mockCallableAddable.addExpectedAddMatch(mockCall);
+
+ mock.match(METHOD_TWOARG_NAME, TWO_PARAM_CONSTRAINT);
+
Verifier.verifyObject(this);
- mockCallableAddable.verifyExpectations();
}
public void testMatchManyAndReturn() throws Throwable {
- mockCallFactory.addExpectedCreateReturnStub(METHOD_TWOARG_RESULT);
- mockCallFactory.setupCreateReturnStub(mockReturnStub);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockReturnStub);
- mockCallFactory.setupCreateCallSignature(mockCallMatch);
-
- mockCallableAddable.addExpectedAddMatch(mockCallMatch);
- mockCallableAddable.setupCall(METHOD_TWOARG_RESULT);
-
- mock.matchAndReturn(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, METHOD_TWOARG_RESULT);
+ mockCallFactory.addExpectedCreateMethodCallWithReturn(METHOD_TWOARG_NAME, TWO_PARAM_CONSTRAINT, new Boolean(METHOD_TWOARG_RESULT));
+ mockCallFactory.setupCreateMethodCallWithReturn(mockCall);
+ mockCallableAddable.addExpectedAddMatch(mockCall);
+
+ mock.matchAndReturn(METHOD_TWOARG_NAME, TWO_PARAM_CONSTRAINT, METHOD_TWOARG_RESULT);
Verifier.verifyObject(this);
- mockCallableAddable.verifyExpectations();
}
public void testMatchManyAndThrow() throws Throwable {
- mockCallFactory.addExpectedCreateThrowStub(METHOD_EXCEPTION);
- mockCallFactory.setupCreateThrowStub(mockThrowStub);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockThrowStub);
- mockCallFactory.setupCreateCallSignature(mockCallMatch);
+ mockCallFactory.addExpectedCreateMethodCallWithException(METHOD_TWOARG_NAME, TWO_PARAM_CONSTRAINT, METHOD_EXCEPTION);
+ mockCallFactory.setupCreateMethodCallWithException(mockCall);
+ mockCallableAddable.addExpectedAddMatch(mockCall);
- mockCallableAddable.addExpectedAddMatch(mockCallMatch);
- mockCallableAddable.setupCall(METHOD_TWOARG_RESULT);
-
- mock.matchAndThrow(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, METHOD_EXCEPTION);
+ mock.matchAndThrow(METHOD_TWOARG_NAME, TWO_PARAM_CONSTRAINT, METHOD_EXCEPTION);
Verifier.verifyObject(this);
- mockCallableAddable.verifyExpectations();
}
public void testMockAnnotatesAssertionFailedErrors()
@@ -440,10 +323,8 @@
}
public void testProxyInEquality() throws Exception {
- boolean IGNORED_RESULT = true;
- CallStub ret = new ReturnStub(new Boolean(IGNORED_RESULT));
- mockCallFactory.setupCreateReturnStub(ret);
- mockCallFactory.setupCreateCallSignature(new CallSignature("call",C.anyArgs(1),ret));
+ int IGNORED_RESULT = -1;
+ mockCallFactory.setupCreateMethodCallWithReturn(new VoidStub());
mockCallableAddable.setupCall(new Boolean(false));
mock.matchAndReturn("call", C.anyArgs(1), IGNORED_RESULT);
Index: MockCallFactory.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockCallFactory.java,v
retrieving revision 1.4
retrieving revision 1.4.4.1
diff -u -r1.4 -r1.4.4.1
--- MockCallFactory.java 19 May 2003 23:56:23 -0000 1.4
+++ MockCallFactory.java 6 Jul 2003 14:21:29 -0000 1.4.4.1
@@ -3,161 +3,150 @@
import com.mockobjects.*;
import com.mockobjects.dynamic.CallFactory;
import com.mockobjects.dynamic.Callable;
-import com.mockobjects.dynamic.ConstraintMatcher;
+import com.mockobjects.constraint.Constraint;
-public class MockCallFactory implements CallFactory{
- private ExpectationCounter myCreateReturnStubCalls = new ExpectationCounter("MockCallFactory.createReturnStub(Object)");
- private ReturnValues myActualCreateReturnStubReturnValues = new ReturnValues("MockCallFactory.createReturnStub(Object)", true);
- private ExpectationList myCreateReturnStubParameter0Values = new ExpectationList("MockCallFactory.createReturnStub(Object) java.lang.Object");
- private ExpectationCounter myCreateThrowStubCalls = new ExpectationCounter("MockCallFactory.createThrowStub(Throwable)");
- private ReturnValues myActualCreateThrowStubReturnValues = new ReturnValues("MockCallFactory.createThrowStub(Throwable)", true);
- private ExpectationList myCreateThrowStubParameter0Values = new ExpectationList("MockCallFactory.createThrowStub(Throwable) java.lang.Throwable");
- private ExpectationCounter myCreateVoidStubCalls = new ExpectationCounter("MockCallFactory.createVoidStub()");
- private ReturnValues myActualCreateVoidStubReturnValues = new ReturnValues("MockCallFactory.createVoidStub()", true);
+public class MockCallFactory implements CallFactory, Verifiable {
private ExpectationCounter myCreateCallExpectationCalls = new ExpectationCounter("MockCallFactory.createCallExpectation(Callable)");
private ReturnValues myActualCreateCallExpectationReturnValues = new ReturnValues("MockCallFactory.createCallExpectation(Callable)", true);
private ExpectationList myCreateCallExpectationParameter0Values = new ExpectationList("MockCallFactory.createCallExpectation(Callable) com.mockobjects.dynamic.Callable");
- private ExpectationCounter myCreateCallSignatureCalls = new ExpectationCounter("MockCallFactory.createCallMatch(String, ConstraintMatcher, Callable)");
- private ReturnValues myActualCreateCallSignatureReturnValues = new ReturnValues("MockCallFactory.createCallMatch(String, ConstraintMatcher, Callable)", true);
- private ExpectationList myCreateCallSignatureParameter0Values = new ExpectationList("MockCallFactory.createCallMatch(String, ConstraintMatcher, Callable) java.lang.String");
- private ExpectationList myCreateCallSignatureParameter1Values = new ExpectationList("MockCallFactory.createCallMatch(String, ConstraintMatcher, Callable) com.mockobjects.dynamic.ConstraintMatcher");
- private ExpectationList myCreateCallSignatureParameter2Values = new ExpectationList("MockCallFactory.createCallMatch(String, ConstraintMatcher, Callable) com.mockobjects.dynamic.Callable");
+ private ExpectationCounter myCreateMethodCallWithVoidCalls = new ExpectationCounter("MockCallFactory.createMethodCallWithVoid(String, Constraint[])");
+ private ReturnValues myActualCreateMethodCallWithVoidReturnValues = new ReturnValues("MockCallFactory.createMethodCallWithVoid(String, Constraint[])", true);
+ private ExpectationList myCreateMethodCallWithVoidParameter0Values = new ExpectationList("MockCallFactory.createMethodCallWithVoid(String, Constraint[]) java.lang.String");
+ private ExpectationList myCreateMethodCallWithVoidParameter1Values = new ExpectationList("MockCallFactory.createMethodCallWithVoid(String, Constraint[]) com.mockobjects.constraint.Constraint");
+ private ExpectationCounter myCreateMethodCallWithExceptionCalls = new ExpectationCounter("MockCallFactory.createMethodCallWithException(String, Constraint[], Throwable)");
+ private ReturnValues myActualCreateMethodCallWithExceptionReturnValues = new ReturnValues("MockCallFactory.createMethodCallWithException(String, Constraint[], Throwable)", true);
+ private ExpectationList myCreateMethodCallWithExceptionParameter0Values = new ExpectationList("MockCallFactory.createMethodCallWithException(String, Constraint[], Throwable) java.lang.String");
+ private ExpectationList myCreateMethodCallWithExceptionParameter1Values = new ExpectationList("MockCallFactory.createMethodCallWithException(String, Constraint[], Throwable) com.mockobjects.constraint.Constraint");
+ private ExpectationList myCreateMethodCallWithExceptionParameter2Values = new ExpectationList("MockCallFactory.createMethodCallWithException(String, Constraint[], Throwable) java.lang.Throwable");
+ private ExpectationCounter myCreateMethodCallWithReturnCalls = new ExpectationCounter("MockCallFactory.createMethodCallWithReturn(String, Constraint[], Object)");
+ private ReturnValues myActualCreateMethodCallWithReturnReturnValues = new ReturnValues("MockCallFactory.createMethodCallWithReturn(String, Constraint[], Object)", true);
+ private ExpectationList myCreateMethodCallWithReturnParameter0Values = new ExpectationList("MockCallFactory.createMethodCallWithReturn(String, Constraint[], Object) java.lang.String");
+ private ExpectationList myCreateMethodCallWithReturnParameter1Values = new ExpectationList("MockCallFactory.createMethodCallWithReturn(String, Constraint[], Object) com.mockobjects.constraint.Constraint");
+ private ExpectationList myCreateMethodCallWithReturnParameter2Values = new ExpectationList("MockCallFactory.createMethodCallWithReturn(String, Constraint[], Object) java.lang.Object");
- public void setExpectedCreateReturnStubCalls(int calls){
- myCreateReturnStubCalls.setExpected(calls);
+ public void setExpectedCreateCallExpectationCalls(int calls){
+ myCreateCallExpectationCalls.setExpected(calls);
}
- public void addExpectedCreateReturnStub(Object arg0){
- myCreateReturnStubParameter0Values.addExpected(arg0);
+ public void addExpectedCreateCallExpectation(Callable arg0){
+ myCreateCallExpectationParameter0Values.addExpected(arg0);
}
- public Callable createReturnStub(Object arg0){
- myCreateReturnStubCalls.inc();
- myCreateReturnStubParameter0Values.addActual(arg0);
- Object nextReturnValue = myActualCreateReturnStubReturnValues.getNext();
+ public Callable createCallExpectation(Callable arg0){
+ myCreateCallExpectationCalls.inc();
+ myCreateCallExpectationParameter0Values.addActual(arg0);
+ Object nextReturnValue = myActualCreateCallExpectationReturnValues.getNext();
if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException)
throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException();
return (Callable) nextReturnValue;
}
- public void setupExceptionCreateReturnStub(Throwable arg){
- myActualCreateReturnStubReturnValues.add(new ExceptionalReturnValue(arg));
- }
-
- public void setupCreateReturnStub(Callable arg){
- myActualCreateReturnStubReturnValues.add(arg);
- }
-
- public void setExpectedCreateThrowStubCalls(int calls){
- myCreateThrowStubCalls.setExpected(calls);
- }
-
- public void addExpectedCreateThrowStub(Throwable 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;
+ public void setupExceptionCreateCallExpectation(Throwable arg){
+ myActualCreateCallExpectationReturnValues.add(new ExceptionalReturnValue(arg));
}
- public void setupExceptionCreateThrowStub(Throwable arg){
- myActualCreateThrowStubReturnValues.add(new ExceptionalReturnValue(arg));
+ public void setupCreateCallExpectation(Callable arg){
+ myActualCreateCallExpectationReturnValues.add(arg);
}
- public void setupCreateThrowStub(Callable arg){
- myActualCreateThrowStubReturnValues.add(arg);
+ public void setExpectedCreateMethodCallWithVoidCalls(int calls){
+ myCreateMethodCallWithVoidCalls.setExpected(calls);
}
- public void setExpectedCreateVoidStubCalls(int calls){
- myCreateVoidStubCalls.setExpected(calls);
+ public void addExpectedCreateMethodCallWithVoid(String arg0, Constraint[] arg1){
+ myCreateMethodCallWithVoidParameter0Values.addExpected(arg0);
+ myCreateMethodCallWithVoidParameter1Values.addExpectedMany(arg1);
}
- public Callable createVoidStub(){
- myCreateVoidStubCalls.inc();
- Object nextReturnValue = myActualCreateVoidStubReturnValues.getNext();
+ public Callable createMethodCallWithVoid(String arg0, Constraint[] arg1){
+ myCreateMethodCallWithVoidCalls.inc();
+ myCreateMethodCallWithVoidParameter0Values.addActual(arg0);
+ myCreateMethodCallWithVoidParameter1Values.addActualMany(arg1);
+ Object nextReturnValue = myActualCreateMethodCallWithVoidReturnValues.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));
+ public void setupExceptionCreateMethodCallWithVoid(Throwable arg){
+ myActualCreateMethodCallWithVoidReturnValues.add(new ExceptionalReturnValue(arg));
}
- public void setupCreateVoidStub(Callable arg){
- myActualCreateVoidStubReturnValues.add(arg);
+ public void setupCreateMethodCallWithVoid(Callable arg){
+ myActualCreateMethodCallWithVoidReturnValues.add(arg);
}
- public void setExpectedCreateCallExpectationCalls(int calls){
- myCreateCallExpectationCalls.setExpected(calls);
+ public void setExpectedCreateMethodCallWithExceptionCalls(int calls){
+ myCreateMethodCallWithExceptionCalls.setExpected(calls);
}
- public void addExpectedCreateCallExpectation(Callable arg0){
- myCreateCallExpectationParameter0Values.addExpected(arg0);
+ public void addExpectedCreateMethodCallWithException(String arg0, Constraint[] arg1, Throwable arg2){
+ myCreateMethodCallWithExceptionParameter0Values.addExpected(arg0);
+ myCreateMethodCallWithExceptionParameter1Values.addExpectedMany(arg1);
+ myCreateMethodCallWithExceptionParameter2Values.addExpected(arg2);
}
- public Callable createCallExpectation(Callable arg0){
- myCreateCallExpectationCalls.inc();
- myCreateCallExpectationParameter0Values.addActual(arg0);
- Object nextReturnValue = myActualCreateCallExpectationReturnValues.getNext();
+ public Callable createMethodCallWithException(String arg0, Constraint[] arg1, Throwable arg2){
+ myCreateMethodCallWithExceptionCalls.inc();
+ myCreateMethodCallWithExceptionParameter0Values.addActual(arg0);
+ myCreateMethodCallWithExceptionParameter1Values.addActualMany(arg1);
+ myCreateMethodCallWithExceptionParameter2Values.addActual(arg2);
+ Object nextReturnValue = myActualCreateMethodCallWithExceptionReturnValues.getNext();
if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException)
throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException();
return (Callable) nextReturnValue;
}
- public void setupExceptionCreateCallExpectation(Throwable arg){
- myActualCreateCallExpectationReturnValues.add(new ExceptionalReturnValue(arg));
+ public void setupExceptionCreateMethodCallWithException(Throwable arg){
+ myActualCreateMethodCallWithExceptionReturnValues.add(new ExceptionalReturnValue(arg));
}
- public void setupCreateCallExpectation(Callable arg){
- myActualCreateCallExpectationReturnValues.add(arg);
+ public void setupCreateMethodCallWithException(Callable arg){
+ myActualCreateMethodCallWithExceptionReturnValues.add(arg);
+ }
+
+ public void setExpectedCreateMethodCallWithReturnCalls(int calls){
+ myCreateMethodCallWithReturnCalls.setExpected(calls);
}
- public void setExpectedCreateCallSignatureCalls(int calls){
- myCreateCallSignatureCalls.setExpected(calls);
+ public void addExpectedCreateMethodCallWithReturn(String arg0, Constraint[] arg1, Object arg2){
+ myCreateMethodCallWithReturnParameter0Values.addExpected(arg0);
+ myCreateMethodCallWithReturnParameter1Values.addExpectedMany(arg1);
+ myCreateMethodCallWithReturnParameter2Values.addExpected(arg2);
}
- public void addExpectedCreateCallSignature(String arg0, ConstraintMatcher arg1, Callable arg2){
- myCreateCallSignatureParameter0Values.addExpected(arg0);
- myCreateCallSignatureParameter1Values.addExpectedMany(arg1.getConstraints());
- myCreateCallSignatureParameter2Values.addExpected(arg2);
- }
-
- public Callable createCallSignature(String arg0, ConstraintMatcher arg1, Callable arg2){
- myCreateCallSignatureCalls.inc();
- myCreateCallSignatureParameter0Values.addActual(arg0);
- myCreateCallSignatureParameter1Values.addActualMany(arg1.getConstraints());
- myCreateCallSignatureParameter2Values.addActual(arg2);
- Object nextReturnValue = myActualCreateCallSignatureReturnValues.getNext();
+ public Callable createMethodCallWithReturn(String arg0, Constraint[] arg1, Object arg2){
+ myCreateMethodCallWithReturnCalls.inc();
+ myCreateMethodCallWithReturnParameter0Values.addActual(arg0);
+ myCreateMethodCallWithReturnParameter1Values.addActualMany(arg1);
+ myCreateMethodCallWithReturnParameter2Values.addActual(arg2);
+ Object nextReturnValue = myActualCreateMethodCallWithReturnReturnValues.getNext();
if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException)
throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException();
return (Callable) nextReturnValue;
}
- public void setupExceptionCreateCallSignature(Throwable arg){
- myActualCreateCallSignatureReturnValues.add(new ExceptionalReturnValue(arg));
+ public void setupExceptionCreateMethodCallWithReturn(Throwable arg){
+ myActualCreateMethodCallWithReturnReturnValues.add(new ExceptionalReturnValue(arg));
}
- public void setupCreateCallSignature(Callable arg){
- myActualCreateCallSignatureReturnValues.add(arg);
+ public void setupCreateMethodCallWithReturn(Callable arg){
+ myActualCreateMethodCallWithReturnReturnValues.add(arg);
}
public void verify(){
- myCreateReturnStubCalls.verify();
- myCreateReturnStubParameter0Values.verify();
- myCreateThrowStubCalls.verify();
- myCreateThrowStubParameter0Values.verify();
- myCreateVoidStubCalls.verify();
myCreateCallExpectationCalls.verify();
myCreateCallExpectationParameter0Values.verify();
- myCreateCallSignatureCalls.verify();
- myCreateCallSignatureParameter0Values.verify();
- myCreateCallSignatureParameter1Values.verify();
- myCreateCallSignatureParameter2Values.verify();
+ myCreateMethodCallWithVoidCalls.verify();
+ myCreateMethodCallWithVoidParameter0Values.verify();
+ myCreateMethodCallWithVoidParameter1Values.verify();
+ myCreateMethodCallWithExceptionCalls.verify();
+ myCreateMethodCallWithExceptionParameter0Values.verify();
+ myCreateMethodCallWithExceptionParameter1Values.verify();
+ myCreateMethodCallWithExceptionParameter2Values.verify();
+ myCreateMethodCallWithReturnCalls.verify();
+ myCreateMethodCallWithReturnParameter0Values.verify();
+ myCreateMethodCallWithReturnParameter1Values.verify();
+ myCreateMethodCallWithReturnParameter2Values.verify();
}
}
Index: CallSequenceTest.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/CallSequenceTest.java,v
retrieving revision 1.11
retrieving revision 1.11.2.1
diff -u -r1.11 -r1.11.2.1
--- CallSequenceTest.java 5 Jul 2003 16:35:20 -0000 1.11
+++ CallSequenceTest.java 6 Jul 2003 14:21:29 -0000 1.11.2.1
@@ -3,6 +3,7 @@
*/
package test.mockobjects.dynamic;
+import com.mockobjects.constraint.Constraint;
import com.mockobjects.dynamic.*;
import com.mockobjects.dynamic.C;
import com.mockobjects.dynamic.CallSignature;
@@ -26,7 +27,7 @@
final String[] METHOD_A_ARGS = new String[] { "a1", "a2" };
final ActiveCall METHOD_A_CALL = new ActiveCall(METHOD_A_NAME, METHOD_A_ARGS);
- final ConstraintMatcher METHOD_A_CONSTRAINTS = C.args(C.eq("a1"), C.eq("a2"));
+ final Constraint[] METHOD_A_CONSTRAINTS = C.args(C.eq("a1"), C.eq("a2"));
final String[] METHOD_B_ARGS = new String[] { "b1", "b2" };
final ActiveCall METHOD_B_CALL = new ActiveCall(METHOD_B_NAME, METHOD_B_ARGS);
|
|
From: Steve F. <sm...@us...> - 2003-07-06 02:31:39
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic
In directory sc8-pr-cvs1:/tmp/cvs-serv6790/src/core/com/mockobjects/dynamic
Modified Files:
CallBag.java DefaultCallFactory.java Mock.java
CallSequence.java CallSignature.java
Added Files:
CallableFactory.java
Removed Files:
CallFactory.java
Log Message:
General tidy up
Renaming Call types to Callable
Collapsed CallableFactory interface
--- NEW FILE: CallableFactory.java ---
package com.mockobjects.dynamic;
public interface CallableFactory {
Callable createCallExpectation( Callable callable );
Callable createReturnCallable( String methodName, ConstraintMatcher constraints, Object result );
Callable createThrowableCallable( String methodName, ConstraintMatcher constraints, Throwable throwable);
Callable createVoidCallable( String methodName, ConstraintMatcher constraints);
}
Index: CallBag.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallBag.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- CallBag.java 5 Jul 2003 16:35:51 -0000 1.6
+++ CallBag.java 6 Jul 2003 02:31:37 -0000 1.7
@@ -4,9 +4,8 @@
package com.mockobjects.dynamic;
-public class CallBag extends CallCollection {
- public Object call(ActiveCall call)
- throws Throwable {
+public class CallBag extends AbstractCallableCollection {
+ public Object call(ActiveCall call) throws Throwable {
Callable foundCall = expectedCalls.firstMatchingCall(call);
if (foundCall == null) {
Index: DefaultCallFactory.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/DefaultCallFactory.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DefaultCallFactory.java 20 May 2003 00:05:24 -0000 1.5
+++ DefaultCallFactory.java 6 Jul 2003 02:31:37 -0000 1.6
@@ -1,25 +1,37 @@
package com.mockobjects.dynamic;
-public class DefaultCallFactory implements CallFactory {
+public class DefaultCallFactory implements CallableFactory {
- public Callable createReturnStub(Object result) {
+ private Callable createReturnStub(Object result) {
return new ReturnStub(result);
}
- public Callable createThrowStub( Throwable exception ) {
+ private Callable createThrowStub( Throwable exception ) {
return new ThrowStub(exception);
}
- public Callable createCallExpectation(Callable call) {
- return new CallOnceExpectation(call);
+ private Callable createVoidStub() {
+ return new VoidStub();
}
- public Callable createCallSignature(String methodName, ConstraintMatcher constraints, Callable call) {
- return new CallSignature( methodName, constraints, call );
+ public Callable createCallExpectation(Callable callable) {
+ return new CallOnceExpectation(callable);
}
- public Callable createVoidStub() {
- return new VoidStub();
+ private Callable createCallSignature(String methodName, ConstraintMatcher constraints, Callable callable) {
+ return new CallSignature( methodName, constraints, callable );
+ }
+
+ public Callable createReturnCallable(String methodName, ConstraintMatcher constraints, Object result) {
+ return createCallSignature(methodName, constraints, createReturnStub(result));
+ }
+
+ public Callable createThrowableCallable(String methodName, ConstraintMatcher constraints, Throwable throwable) {
+ return createCallSignature(methodName, constraints, createThrowStub(throwable));
+ }
+
+ public Callable createVoidCallable(String methodName, ConstraintMatcher constraints) {
+ return createCallSignature(methodName, constraints, createVoidStub());
}
}
Index: Mock.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Mock.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- Mock.java 5 Jul 2003 15:15:54 -0000 1.25
+++ Mock.java 6 Jul 2003 02:31:37 -0000 1.26
@@ -3,22 +3,21 @@
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
-
import junit.framework.AssertionFailedError;
-
import com.mockobjects.Verifiable;
+
import com.mockobjects.constraint.Constraint;
public class Mock implements InvocationHandler, Verifiable {
private String name;
private Object proxy;
- private CallFactory callFactory;
- private CallableAddable calls;
+ private CallableFactory callableFactory;
+ private CallableCollection callables;
- public Mock(CallFactory callFactory, CallableAddable callableAddable, Class mockedClass, String name) {
+ public Mock(CallableFactory callableFactory, CallableCollection callableAddable, Class mockedClass, String name) {
this.name = name;
- this.callFactory = callFactory;
- this.calls = callableAddable;
+ this.callableFactory = callableFactory;
+ this.callables = callableAddable;
this.proxy = Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { mockedClass }, this);
}
@@ -31,7 +30,7 @@
}
public void reset() {
- this.calls.reset();
+ this.callables.reset();
}
public static String mockNameFromClass(Class c) {
@@ -87,7 +86,7 @@
} else if (isMockNameGetter(activeCall)) {
return this.getMockName();
} else {
- return calls.call(activeCall);
+ return callables.call(activeCall);
}
} catch (AssertionFailedError ex) {
throw new AssertionFailedError(name + ": " + ex.getMessage());
@@ -105,7 +104,7 @@
public void verify() {
try {
- calls.verify();
+ callables.verify();
} catch (AssertionFailedError ex) {
throw new AssertionFailedError(name + ": " + ex.getMessage());
}
@@ -120,7 +119,7 @@
}
public void expect(String methodName, ConstraintMatcher args) {
- calls.addExpect(callFactory.createCallExpectation(callFactory.createCallSignature(methodName, args, callFactory.createVoidStub())));
+ callables.addExpect(callableFactory.createCallExpectation(callableFactory.createVoidCallable(methodName, args)));
}
public void expectAndReturn(String methodName, Object result) {
@@ -156,7 +155,7 @@
}
public void expectAndReturn(String methodName, ConstraintMatcher args, Object result) {
- calls.addExpect(callFactory.createCallExpectation(callFactory.createCallSignature(methodName, args, callFactory.createReturnStub(result))));
+ callables.addExpect(callableFactory.createCallExpectation(callableFactory.createReturnCallable(methodName, args, result)));
}
public void expectAndThrow(String methodName, Throwable exception) {
@@ -168,7 +167,7 @@
}
public void expectAndThrow(String methodName, ConstraintMatcher args, Throwable exception) {
- calls.addExpect(callFactory.createCallExpectation(callFactory.createCallSignature(methodName, args, callFactory.createThrowStub(exception))));
+ callables.addExpect(callableFactory.createCallExpectation(callableFactory.createThrowableCallable(methodName, args, exception)));
}
public void match(String methodName) {
@@ -188,7 +187,7 @@
}
public void match(String methodName, ConstraintMatcher args) {
- calls.addMatch(callFactory.createCallSignature(methodName, args, callFactory.createVoidStub()));
+ callables.addMatch(callableFactory.createVoidCallable(methodName, args));
}
public void matchAndReturn(String methodName, Object result) {
@@ -232,7 +231,7 @@
}
public void matchAndReturn(String methodName, ConstraintMatcher args, Object result) {
- calls.addMatch(callFactory.createCallSignature(methodName, args, callFactory.createReturnStub(result)));
+ callables.addMatch(callableFactory.createReturnCallable(methodName, args, result));
}
public void matchAndThrow(String methodName, Throwable throwable) {
@@ -252,7 +251,7 @@
}
public void matchAndThrow(String methodName, ConstraintMatcher args, Throwable throwable) {
- calls.addMatch(callFactory.createCallSignature(methodName, args, callFactory.createThrowStub(throwable)));
+ callables.addMatch(callableFactory.createThrowableCallable(methodName, args, throwable));
}
/** @deprecated @see OrderedMock
Index: CallSequence.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallSequence.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- CallSequence.java 5 Jul 2003 16:35:51 -0000 1.8
+++ CallSequence.java 6 Jul 2003 02:31:37 -0000 1.9
@@ -2,15 +2,15 @@
import junit.framework.AssertionFailedError;
-public class CallSequence extends CallCollection {
+public class CallSequence extends AbstractCallableCollection {
int callIndex = 0;
public Object call(ActiveCall activeCall) throws Throwable {
if (expectedCalls.isEmpty())
- throw new AssertionFailedError("no methods defined on mock, received: " + DynamicUtil.methodToString(activeCall));
+ throw new AssertionFailedError("no methods defined on mock, received: " + activeCall.toString());
if (callIndex == expectedCalls.size())
- throw new AssertionFailedError("mock called too many times, received: " + DynamicUtil.methodToString(activeCall));
+ throw new AssertionFailedError("mock called too many times, received: " + activeCall.toString());
Callable callable = expectedCalls.get(callIndex++);
if (callable.matches(activeCall)) {
Index: CallSignature.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallSignature.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- CallSignature.java 5 Jul 2003 15:15:54 -0000 1.3
+++ CallSignature.java 6 Jul 2003 02:31:37 -0000 1.4
@@ -1,8 +1,6 @@
package com.mockobjects.dynamic;
-import junit.framework.Assert;
-
-public class CallSignature extends Assert implements Callable
+public class CallSignature implements Callable
{
private String methodName;
private ConstraintMatcher constraints;
--- CallFactory.java DELETED ---
|
|
From: Steve F. <sm...@us...> - 2003-07-06 02:31:39
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic
In directory sc8-pr-cvs1:/tmp/cvs-serv6790/src/core/test/mockobjects/dynamic
Modified Files:
MockCallFactory.java MockTest.java
Added Files:
MockCallableCollection.java CallSignatureTest.java
Removed Files:
CallMatchTest.java MockCallableAddable.java
Log Message:
General tidy up
Renaming Call types to Callable
Collapsed CallableFactory interface
--- NEW FILE: MockCallableCollection.java ---
package test.mockobjects.dynamic;
import com.mockobjects.ExpectationCounter;
import com.mockobjects.ExpectationList;
import com.mockobjects.MockObject;
import com.mockobjects.ReturnValues;
import com.mockobjects.dynamic.ActiveCall;
import com.mockobjects.dynamic.Callable;
import com.mockobjects.dynamic.CallableCollection;
import com.mockobjects.util.NotImplementedException;
import com.mockobjects.util.Verifier;
//Mock modified for []args
public class MockCallableCollection extends MockObject implements CallableCollection {
public ExpectationList matchedCallables = new ExpectationList("CallableAddable matchedCallables");
public ExpectationList expectedCallables = new ExpectationList("CallableAddable expectedCallables");
private ExpectationCounter myMatchesCalls = new ExpectationCounter("com.mockobjects.dynamic.CallableAddable MatchesCalls");
private ReturnValues myActualMatchesReturnValues = new ReturnValues(true);
private ExpectationList myMatchesParameter0Values = new ExpectationList("com.mockobjects.dynamic.CallableAddable MatchesParameter0Values");
private ExpectationList myMatchesParameter1Values = new ExpectationList("com.mockobjects.dynamic.CallableAddable MatchesParameter1Values");
private ExpectationCounter myGetDescriptionCalls = new ExpectationCounter("com.mockobjects.dynamic.CallableAddable GetDescriptionCalls");
private ReturnValues myActualGetDescriptionReturnValues = new ReturnValues(true);
private ExpectationCounter myCallCalls = new ExpectationCounter("com.mockobjects.dynamic.CallableAddable CallCalls");
private ReturnValues myActualCallReturnValues = new ReturnValues(true);
private ExpectationList myCallMethodNames = new ExpectationList("com.mockobjects.dynamic.CallableAddable methodName");
private ExpectationList myCallArguments = new ExpectationList("com.mockobjects.dynamic.CallableAddable arguments");
private ExpectationCounter myVerifyCalls = new ExpectationCounter("com.mockobjects.dynamic.CallableAddable VerifyCalls");
public void reset() {
throw new NotImplementedException();
}
public void addMatch(Callable callable) {
matchedCallables.addActual(callable);
}
public void addExpect(Callable callable) {
expectedCallables.addActual(callable);
}
public void setExpectedMatchesCalls(int calls) {
myMatchesCalls.setExpected(calls);
}
public void addExpectedMatches(String arg0, Object[] arg1) {
myMatchesParameter0Values.addExpected(arg0);
myMatchesParameter1Values.addExpected(arg1);
}
public boolean matches(ActiveCall call) {
myMatchesCalls.inc();
myMatchesParameter0Values.addActual(call.getMethodName());
myMatchesParameter1Values.addActual(call.args);
Object nextReturnValue = myActualMatchesReturnValues.getNext();
return ((Boolean) nextReturnValue).booleanValue();
}
public void setupMatches(boolean arg) {
myActualMatchesReturnValues.add(new Boolean(arg));
}
public void setExpectedGetDescriptionCalls(int calls) {
myGetDescriptionCalls.setExpected(calls);
}
public String getDescription() {
myGetDescriptionCalls.inc();
Object nextReturnValue = myActualGetDescriptionReturnValues.getNext();
return (String) nextReturnValue;
}
public void setupGetDescription(String arg) {
myActualGetDescriptionReturnValues.add(arg);
}
public void setExpectedCallCalls(int calls) {
myCallCalls.setExpected(calls);
}
public void addExpectedCall(String methodName, Object[] args) {
myCallMethodNames.addExpected(methodName);
myCallArguments.addExpectedMany(args);
}
public Object call(ActiveCall call)
throws Throwable {
myCallCalls.inc();
myCallMethodNames.addActual(call.getMethodName());
myCallArguments.addActualMany(call.args);
Object nextReturnValue = myActualCallReturnValues.getNext();
return (Object) nextReturnValue;
}
public void setupCall(Object arg) {
myActualCallReturnValues.add(arg);
}
public void setExpectedVerifyCalls(int calls) {
myVerifyCalls.setExpected(calls);
}
/** @deprected use verifyExpectations as this is a mockmock */
public void verify() {
myVerifyCalls.inc();
}
public void verifyExpectations() {
Verifier.verifyObject(this);
}
}
--- NEW FILE: CallSignatureTest.java ---
/*
* Created on 04-Apr-2003
*/
package test.mockobjects.dynamic;
import junit.framework.TestCase;
import com.mockobjects.dynamic.*;
public class CallSignatureTest extends TestCase {
final String METHOD_NAME = "methodName";
final Object[] IGNORED_ARGS = new Object[0];
final ActiveCall CALL = new ActiveCall(METHOD_NAME, IGNORED_ARGS);
Mock mock = new Mock(DummyInterface.class, "mock");
MockCallable mockCallable = new MockCallable("mock callable");
MockConstraintMatcher mockConstraintMatcher = new MockConstraintMatcher();
CallSignature callSignature = new CallSignature(METHOD_NAME, mockConstraintMatcher, mockCallable);
public CallSignatureTest(String name) {
super(name);
}
public void testCallArgumentsArePropagatedToDecorated()
throws Throwable {
final String result = "result";
mockCallable.activeCall.setExpected(CALL);
mockCallable.setupCallReturn(result);
callSignature.call(CALL);
mockCallable.verifyExpectations();
}
public void testUncalledCallVerifies() {
mockCallable.setExpectedVerifyCalls(1);
callSignature.verify();
mockCallable.verifyExpectations();
}
public void testCallSuccessVerifies() throws Throwable {
mockCallable.setExpectedVerifyCalls(1);
mockCallable.setupCallReturn("result");
callSignature.call(CALL);
callSignature.verify();
mockCallable.verifyExpectations();
}
public void testMultipleCallsSucceed() throws Throwable {
mockCallable.setupCallReturn("result");
callSignature.call(CALL);
callSignature.call(CALL);
mockCallable.verifyExpectations();
}
public void testCallFailure() throws Throwable {
// na
}
public void testCallDoesNotMatchWhenWrongName() throws Throwable {
assertFalse("call does not match", callSignature.matches(new ActiveCall("anotherName", IGNORED_ARGS)));
mockCallable.verifyExpectations();
}
public void testMatchesAfterCalls() throws Throwable {
mockCallable.setupCallReturn("result");
mockCallable.setupAlwaysMatchActiveCall(true);
mockConstraintMatcher.setupMatches(true);
callSignature.call(CALL);
assertTrue("matches after first call", callSignature.matches( CALL ));
callSignature.call(CALL);
assertTrue("matches after further calls", callSignature.matches( CALL ));
mockCallable.verifyExpectations();
}
public void testMatchesDelegatesToContraintMatcher()
throws Throwable {
final String[] args = new String[] { "a1", "a2" };
mockConstraintMatcher.addExpectedMatches(args);
mockConstraintMatcher.setupMatches(true);
assertTrue("matches delegated to constraint matcher", callSignature.matches(new ActiveCall(METHOD_NAME, args)));
mockConstraintMatcher.verify();
}
public void testMatchesFailure() throws Throwable {
mockConstraintMatcher.setupMatches(false);
assertFalse("Should not match if constraint matcher doesn't", callSignature.matches(CALL));
}
}
Index: MockCallFactory.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockCallFactory.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- MockCallFactory.java 19 May 2003 23:56:23 -0000 1.4
+++ MockCallFactory.java 6 Jul 2003 02:31:37 -0000 1.5
@@ -1,17 +1,16 @@
package test.mockobjects.dynamic;
import com.mockobjects.*;
-import com.mockobjects.dynamic.CallFactory;
+import com.mockobjects.dynamic.CallableFactory;
import com.mockobjects.dynamic.Callable;
import com.mockobjects.dynamic.ConstraintMatcher;
+import com.mockobjects.util.Verifier;
-public class MockCallFactory implements CallFactory{
- private ExpectationCounter myCreateReturnStubCalls = new ExpectationCounter("MockCallFactory.createReturnStub(Object)");
+public class MockCallFactory implements CallableFactory{
private ReturnValues myActualCreateReturnStubReturnValues = new ReturnValues("MockCallFactory.createReturnStub(Object)", true);
- private ExpectationList myCreateReturnStubParameter0Values = new ExpectationList("MockCallFactory.createReturnStub(Object) java.lang.Object");
- private ExpectationCounter myCreateThrowStubCalls = new ExpectationCounter("MockCallFactory.createThrowStub(Throwable)");
+ public ExpectationValue createReturnStub = new ExpectationValue("createReturnStub");
private ReturnValues myActualCreateThrowStubReturnValues = new ReturnValues("MockCallFactory.createThrowStub(Throwable)", true);
- private ExpectationList myCreateThrowStubParameter0Values = new ExpectationList("MockCallFactory.createThrowStub(Throwable) java.lang.Throwable");
+ public ExpectationValue createThrowStub = new ExpectationValue("createThrowStub");
private ExpectationCounter myCreateVoidStubCalls = new ExpectationCounter("MockCallFactory.createVoidStub()");
private ReturnValues myActualCreateVoidStubReturnValues = new ReturnValues("MockCallFactory.createVoidStub()", true);
private ExpectationCounter myCreateCallExpectationCalls = new ExpectationCounter("MockCallFactory.createCallExpectation(Callable)");
@@ -23,42 +22,20 @@
private ExpectationList myCreateCallSignatureParameter1Values = new ExpectationList("MockCallFactory.createCallMatch(String, ConstraintMatcher, Callable) com.mockobjects.dynamic.ConstraintMatcher");
private ExpectationList myCreateCallSignatureParameter2Values = new ExpectationList("MockCallFactory.createCallMatch(String, ConstraintMatcher, Callable) com.mockobjects.dynamic.Callable");
- public void setExpectedCreateReturnStubCalls(int calls){
- myCreateReturnStubCalls.setExpected(calls);
- }
-
- public void addExpectedCreateReturnStub(Object arg0){
- myCreateReturnStubParameter0Values.addExpected(arg0);
- }
-
- public Callable createReturnStub(Object arg0){
- myCreateReturnStubCalls.inc();
- myCreateReturnStubParameter0Values.addActual(arg0);
+ private Callable createReturnStub(Object arg0){
+ createReturnStub.setActual(arg0);
Object nextReturnValue = myActualCreateReturnStubReturnValues.getNext();
if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException)
throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException();
return (Callable) nextReturnValue;
}
- public void setupExceptionCreateReturnStub(Throwable arg){
- myActualCreateReturnStubReturnValues.add(new ExceptionalReturnValue(arg));
- }
-
public void setupCreateReturnStub(Callable arg){
myActualCreateReturnStubReturnValues.add(arg);
}
- public void setExpectedCreateThrowStubCalls(int calls){
- myCreateThrowStubCalls.setExpected(calls);
- }
-
- public void addExpectedCreateThrowStub(Throwable arg0){
- myCreateThrowStubParameter0Values.addExpected(arg0);
- }
-
- public Callable createThrowStub(Throwable arg0){
- myCreateThrowStubCalls.inc();
- myCreateThrowStubParameter0Values.addActual(arg0);
+ private Callable createThrowStub(Throwable arg0){
+ createThrowStub.setActual(arg0);
Object nextReturnValue = myActualCreateThrowStubReturnValues.getNext();
if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException)
throw (RuntimeException)((ExceptionalReturnValue)nextReturnValue).getException();
@@ -77,7 +54,7 @@
myCreateVoidStubCalls.setExpected(calls);
}
- public Callable createVoidStub(){
+ private Callable createVoidStub(){
myCreateVoidStubCalls.inc();
Object nextReturnValue = myActualCreateVoidStubReturnValues.getNext();
if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException)
@@ -128,7 +105,7 @@
myCreateCallSignatureParameter2Values.addExpected(arg2);
}
- public Callable createCallSignature(String arg0, ConstraintMatcher arg1, Callable arg2){
+ private Callable createCallSignature(String arg0, ConstraintMatcher arg1, Callable arg2){
myCreateCallSignatureCalls.inc();
myCreateCallSignatureParameter0Values.addActual(arg0);
myCreateCallSignatureParameter1Values.addActualMany(arg1.getConstraints());
@@ -147,17 +124,20 @@
myActualCreateCallSignatureReturnValues.add(arg);
}
+ public Callable createReturnCallable(String methodName, ConstraintMatcher constraints, Object result) {
+ return createCallSignature(methodName, constraints, createReturnStub(result));
+ }
+
+
+ public Callable createThrowableCallable(String methodName, ConstraintMatcher constraints, Throwable throwable) {
+ return createCallSignature(methodName, constraints, createThrowStub(throwable));
+ }
+
+ public Callable createVoidCallable(String methodName, ConstraintMatcher constraints) {
+ return createCallSignature(methodName, constraints, createVoidStub());
+ }
+
public void verify(){
- myCreateReturnStubCalls.verify();
- myCreateReturnStubParameter0Values.verify();
- myCreateThrowStubCalls.verify();
- myCreateThrowStubParameter0Values.verify();
- myCreateVoidStubCalls.verify();
- myCreateCallExpectationCalls.verify();
- myCreateCallExpectationParameter0Values.verify();
- myCreateCallSignatureCalls.verify();
- myCreateCallSignatureParameter0Values.verify();
- myCreateCallSignatureParameter1Values.verify();
- myCreateCallSignatureParameter2Values.verify();
+ Verifier.verifyObject(this);
}
}
Index: MockTest.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockTest.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- MockTest.java 5 Jul 2003 15:15:54 -0000 1.14
+++ MockTest.java 6 Jul 2003 02:31:37 -0000 1.15
@@ -34,340 +34,337 @@
private MockCallable mockReturnStub = new MockCallable("return stub");
private MockCallable mockThrowStub = new MockCallable("throw stub");
private MockCallable mockVoidStub = new MockCallable("void stub");
- private MockCallableAddable mockCallableAddable = new MockCallableAddable();
+ private MockCallableCollection mockCallables = new MockCallableCollection();
public MockTest(String name) throws Exception {
super(name);
}
public void setUp() {
- mock = new Mock(mockCallFactory, mockCallableAddable, DummyInterface.class, MOCK_NAME);
+ mock = new Mock(mockCallFactory, mockCallables, DummyInterface.class, MOCK_NAME);
try {
proxy = (DummyInterface)mock.proxy();
} catch (ClassCastException ex) {
fail("proxy is not of expected interface type");
}
+
+ mockCallFactory.setupCreateReturnStub(mockReturnStub);
+ mockCallFactory.setupCreateVoidStub(mockVoidStub);
+ mockCallFactory.setupCreateThrowStub(mockThrowStub);
}
public void testExpectManyAndVoid() throws Throwable {
+ mockCallFactory.setupCreateCallSignature(mockCallMatch);
+ mockCallFactory.setupCreateCallExpectation(mockExpectedCall);
+
mockCallFactory.setExpectedCreateVoidStubCalls(1);
- mockCallFactory.setupCreateVoidStub(mockVoidStub);
mockCallFactory.addExpectedCreateCallSignature(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockVoidStub);
- mockCallFactory.setupCreateCallSignature(mockCallMatch);
mockCallFactory.addExpectedCreateCallExpectation(mockCallMatch);
- mockCallFactory.setupCreateCallExpectation(mockExpectedCall);
- mockCallableAddable.addExpectedAddExpect(mockExpectedCall);
+ mockCallables.expectedCallables.addExpected(mockExpectedCall);
mock.expect(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS);
Verifier.verifyObject(this);
- mockCallableAddable.verifyExpectations();
+ mockCallables.verifyExpectations();
}
public void testExpectNoneAndReturn() throws Throwable {
- mockCallFactory.addExpectedCreateReturnStub(METHOD_NOARGANDRETURN_RESULT);
- mockCallFactory.setupCreateReturnStub(mockReturnStub);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_NOARGANDRETURN_NAME, C.NO_ARGS, mockReturnStub);
mockCallFactory.setupCreateCallSignature(mockCallMatch);
- mockCallFactory.addExpectedCreateCallExpectation(mockCallMatch);
mockCallFactory.setupCreateCallExpectation(mockExpectedCall);
- mockCallableAddable.addExpectedAddExpect(mockExpectedCall);
+ mockCallFactory.createReturnStub.setExpected(METHOD_NOARGANDRETURN_RESULT);
+ mockCallFactory.addExpectedCreateCallSignature(METHOD_NOARGANDRETURN_NAME, C.NO_ARGS, mockReturnStub);
+ mockCallFactory.addExpectedCreateCallExpectation(mockCallMatch);
+
+ mockCallables.expectedCallables.addExpected(mockExpectedCall);
mock.expectAndReturn(METHOD_NOARGANDRETURN_NAME, METHOD_NOARGANDRETURN_RESULT);
Verifier.verifyObject(this);
- mockCallableAddable.verifyExpectations();
+ mockCallables.verifyExpectations();
}
public void testExpectNoneAndThrow() throws Throwable {
- mockCallFactory.addExpectedCreateThrowStub(METHOD_EXCEPTION);
- mockCallFactory.setupCreateThrowStub(mockThrowStub);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_NOARGANDRETURN_NAME, C.NO_ARGS, mockThrowStub);
mockCallFactory.setupCreateCallSignature(mockCallMatch);
- mockCallFactory.addExpectedCreateCallExpectation(mockCallMatch);
mockCallFactory.setupCreateCallExpectation(mockExpectedCall);
- mockCallableAddable.addExpectedAddExpect(mockExpectedCall);
+ mockCallFactory.createThrowStub.setExpected(METHOD_EXCEPTION);
+ mockCallFactory.addExpectedCreateCallSignature(METHOD_NOARGANDRETURN_NAME, C.NO_ARGS, mockThrowStub);
+ mockCallFactory.addExpectedCreateCallExpectation(mockCallMatch);
+
+ mockCallables.expectedCallables.addExpected(mockExpectedCall);
mock.expectAndThrow(METHOD_NOARGANDRETURN_NAME, METHOD_EXCEPTION);
Verifier.verifyObject(this);
- mockCallableAddable.verifyExpectations();
+ mockCallables.verifyExpectations();
}
public void testExpectOneAndThrow() throws Throwable {
- mockCallFactory.addExpectedCreateThrowStub(METHOD_EXCEPTION);
- mockCallFactory.setupCreateThrowStub(mockThrowStub);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockThrowStub);
mockCallFactory.setupCreateCallSignature(mockCallMatch);
- mockCallFactory.addExpectedCreateCallExpectation(mockCallMatch);
mockCallFactory.setupCreateCallExpectation(mockExpectedCall);
- mockCallableAddable.addExpectedAddExpect(mockExpectedCall);
+ mockCallFactory.createThrowStub.setExpected(METHOD_EXCEPTION);
+ mockCallFactory.addExpectedCreateCallSignature(METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockThrowStub);
+ mockCallFactory.addExpectedCreateCallExpectation(mockCallMatch);
+
+ mockCallables.expectedCallables.addExpected(mockExpectedCall);
mock.expectAndThrow(METHOD_ONEARG_NAME, METHOD_ONEARG_ARGS[0], METHOD_EXCEPTION);
Verifier.verifyObject(this);
- mockCallableAddable.verifyExpectations();
+ mockCallables.verifyExpectations();
}
public void testExpectNoneAndVoid() throws Throwable {
+ mockCallFactory.setupCreateCallSignature(mockCallMatch);
+ mockCallFactory.setupCreateCallExpectation(mockExpectedCall);
+
mockCallFactory.setExpectedCreateVoidStubCalls(1);
- mockCallFactory.setupCreateVoidStub(mockVoidStub);
mockCallFactory.addExpectedCreateCallSignature(METHOD_NOARG_NAME, C.NO_ARGS, mockVoidStub);
- mockCallFactory.setupCreateCallSignature(mockCallMatch);
mockCallFactory.addExpectedCreateCallExpectation(mockCallMatch);
- mockCallFactory.setupCreateCallExpectation(mockExpectedCall);
- mockCallableAddable.addExpectedAddExpect(mockExpectedCall);
+ mockCallables.expectedCallables.addExpected(mockExpectedCall);
mock.expect(METHOD_NOARG_NAME);
Verifier.verifyObject(this);
- mockCallableAddable.verifyExpectations();
+ mockCallables.verifyExpectations();
}
public void testExpectOneAndVoid() throws Throwable {
+ mockCallFactory.setupCreateCallSignature(mockCallMatch);
+ mockCallFactory.setupCreateCallExpectation(mockExpectedCall);
+
mockCallFactory.setExpectedCreateVoidStubCalls(1);
- mockCallFactory.setupCreateVoidStub(mockVoidStub);
mockCallFactory.addExpectedCreateCallSignature(METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockVoidStub);
- mockCallFactory.setupCreateCallSignature(mockCallMatch);
mockCallFactory.addExpectedCreateCallExpectation(mockCallMatch);
- mockCallFactory.setupCreateCallExpectation(mockExpectedCall);
- mockCallableAddable.addExpectedAddExpect(mockExpectedCall);
+ mockCallables.expectedCallables.addExpected(mockExpectedCall);
mock.expect(METHOD_ONEARG_NAME, METHOD_ONEARG_ARGS[0]);
Verifier.verifyObject(this);
- mockCallableAddable.verifyExpectations();
+ mockCallables.verifyExpectations();
}
public void testExpectWithConstraint() throws Throwable {
- mockCallFactory.setupCreateVoidStub(mockVoidStub);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockVoidStub);
mockCallFactory.setupCreateCallSignature(mockCallMatch);
mockCallFactory.setupCreateCallExpectation(mockExpectedCall);
- mockCallableAddable.addExpectedAddExpect(mockExpectedCall);
+ mockCallFactory.addExpectedCreateCallSignature(METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockVoidStub);
+ mockCallables.expectedCallables.addExpected(mockExpectedCall);
mock.expect(METHOD_ONEARG_NAME, new IsEqual(METHOD_ONEARG_ARGS[0]));
Verifier.verifyObject(this);
- mockCallableAddable.verifyExpectations();
+ mockCallables.verifyExpectations();
}
public void testExpectWithConstraintArray() throws Throwable {
- mockCallFactory.setupCreateVoidStub(mockVoidStub);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockVoidStub);
mockCallFactory.setupCreateCallSignature(mockCallMatch);
mockCallFactory.setupCreateCallExpectation(mockExpectedCall);
- mockCallableAddable.addExpectedAddExpect(mockExpectedCall);
+ mockCallFactory.addExpectedCreateCallSignature(METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockVoidStub);
+ mockCallables.expectedCallables.addExpected(mockExpectedCall);
mock.expect(METHOD_ONEARG_NAME, new Constraint[] { new IsEqual(METHOD_ONEARG_ARGS[0])});
Verifier.verifyObject(this);
- mockCallableAddable.verifyExpectations();
+ mockCallables.verifyExpectations();
}
public void testExpectManyAndReturn() throws Throwable {
- mockCallFactory.addExpectedCreateReturnStub(METHOD_TWOARG_RESULT);
- mockCallFactory.setupCreateReturnStub(mockReturnStub);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockReturnStub);
mockCallFactory.setupCreateCallSignature(mockCallMatch);
- mockCallFactory.addExpectedCreateCallExpectation(mockCallMatch);
mockCallFactory.setupCreateCallExpectation(mockExpectedCall);
- mockCallableAddable.addExpectedAddExpect(mockExpectedCall);
- mockCallableAddable.setupCall(METHOD_TWOARG_RESULT);
+ mockCallFactory.createReturnStub.setExpected(METHOD_TWOARG_RESULT);
+ mockCallFactory.addExpectedCreateCallSignature(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockReturnStub);
+ mockCallFactory.addExpectedCreateCallExpectation(mockCallMatch);
+
+ mockCallables.expectedCallables.addExpected(mockExpectedCall);
+ mockCallables.setupCall(METHOD_TWOARG_RESULT);
mock.expectAndReturn(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, METHOD_TWOARG_RESULT);
Verifier.verifyObject(this);
- mockCallableAddable.verifyExpectations();
+ mockCallables.verifyExpectations();
}
public void testExpectManyAndThrow() throws Throwable {
- mockCallFactory.addExpectedCreateThrowStub(METHOD_EXCEPTION);
- mockCallFactory.setupCreateThrowStub(mockThrowStub);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockThrowStub);
mockCallFactory.setupCreateCallSignature(mockCallMatch);
- mockCallFactory.addExpectedCreateCallExpectation(mockCallMatch);
mockCallFactory.setupCreateCallExpectation(mockExpectedCall);
- mockCallableAddable.addExpectedAddExpect(mockExpectedCall);
- mockCallableAddable.setupCall(METHOD_TWOARG_RESULT);
+ mockCallFactory.createThrowStub.setExpected(METHOD_EXCEPTION);
+ mockCallFactory.addExpectedCreateCallSignature(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockThrowStub);
+ mockCallFactory.addExpectedCreateCallExpectation(mockCallMatch);
+
+ mockCallables.expectedCallables.addExpected(mockExpectedCall);
+ mockCallables.setupCall(METHOD_TWOARG_RESULT);
mock.expectAndThrow(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, METHOD_EXCEPTION);
Verifier.verifyObject(this);
- mockCallableAddable.verifyExpectations();
+ mockCallables.verifyExpectations();
}
public void testExpectOneAndReturn() throws Throwable {
- mockCallFactory.addExpectedCreateReturnStub(METHOD_ONEARG_RESULT);
- mockCallFactory.setupCreateReturnStub(mockReturnStub);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockReturnStub);
mockCallFactory.setupCreateCallSignature(mockCallMatch);
- mockCallFactory.addExpectedCreateCallExpectation(mockCallMatch);
mockCallFactory.setupCreateCallExpectation(mockExpectedCall);
- mockCallableAddable.addExpectedAddExpect(mockExpectedCall);
- mockCallableAddable.setupCall(METHOD_ONEARG_RESULT);
+ mockCallFactory.createReturnStub.setExpected(METHOD_ONEARG_RESULT);
+ mockCallFactory.addExpectedCreateCallSignature(METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockReturnStub);
+ mockCallFactory.addExpectedCreateCallExpectation(mockCallMatch);
+
+ mockCallables.expectedCallables.addExpected(mockExpectedCall);
+ mockCallables.setupCall(METHOD_ONEARG_RESULT);
mock.expectAndReturn(METHOD_ONEARG_NAME, METHOD_ONEARG_ARGS[0], METHOD_ONEARG_RESULT);
Verifier.verifyObject(this);
- mockCallableAddable.verifyExpectations();
+ mockCallables.verifyExpectations();
}
public void testMatchNoneAndVoid() throws Throwable {
+ mockCallFactory.setupCreateCallSignature(mockCallMatch);
+ mockCallables.setupCall(METHOD_NOARGANDRETURN_RESULT);
+
mockCallFactory.setExpectedCreateVoidStubCalls(1);
- mockCallFactory.setupCreateVoidStub(mockVoidStub);
mockCallFactory.addExpectedCreateCallSignature(METHOD_NOARG_NAME, C.NO_ARGS, mockVoidStub);
- mockCallFactory.setupCreateCallSignature(mockCallMatch);
- mockCallableAddable.addExpectedAddMatch(mockCallMatch);
- mockCallableAddable.setupCall(METHOD_NOARGANDRETURN_RESULT);
+ mockCallables.matchedCallables.addExpected(mockCallMatch);
mock.match(METHOD_NOARG_NAME);
Verifier.verifyObject(this);
- mockCallableAddable.verifyExpectations();
+ mockCallables.verifyExpectations();
}
public void testMatchNoneAndReturn() throws Throwable {
- mockCallFactory.addExpectedCreateReturnStub(METHOD_NOARGANDRETURN_RESULT);
- mockCallFactory.setupCreateReturnStub(mockReturnStub);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_NOARG_NAME, C.NO_ARGS, mockReturnStub);
mockCallFactory.setupCreateCallSignature(mockCallMatch);
+ mockCallables.setupCall(METHOD_ONEARG_RESULT);
+
+ mockCallFactory.createReturnStub.setExpected(METHOD_NOARGANDRETURN_RESULT);
+ mockCallFactory.addExpectedCreateCallSignature(METHOD_NOARG_NAME, C.NO_ARGS, mockReturnStub);
- mockCallableAddable.addExpectedAddMatch(mockCallMatch);
- mockCallableAddable.setupCall(METHOD_ONEARG_RESULT);
+ mockCallables.matchedCallables.addExpected(mockCallMatch);
mock.matchAndReturn(METHOD_NOARG_NAME, METHOD_NOARGANDRETURN_RESULT);
Verifier.verifyObject(this);
- mockCallableAddable.verifyExpectations();
+ mockCallables.verifyExpectations();
}
public void testMatchNoneAndThrow() throws Throwable {
- mockCallFactory.addExpectedCreateThrowStub(METHOD_EXCEPTION);
mockCallFactory.setupCreateThrowStub(mockThrowStub);
- mockCallFactory.addExpectedCreateCallSignature(METHOD_NOARG_NAME, C.NO_ARGS, mockThrowStub);
mockCallFactory.setupCreateCallSignature(mockCallMatch);
- mockCallableAddable.addExpectedAddMatch(mockCallMatch);
- mockCallableAddable.setupCall(METHOD_NOARGANDRETURN_RESULT);
+ mockCallFactory.createThrowStub.setExpected(METHOD_EXCEPTION);
+ mockCallFactory.addExpectedCreateCallSignature(METHOD_NOARG_NAME, C.NO_ARGS, mockThrowStub);
+
+ mockCallables.matchedCallables.addExpected(mockCallMatch);
+ mockCallables.setupCall(METHOD_NOARGANDRETURN_RESULT);
mock.matchAndThrow(METHOD_NOARG_NAME, METHOD_EXCEPTION);
Verifier.verifyObject(this);
- mockCallableAddable.verifyExpectations();
+ mockCallables.verifyExpectations();
}
public void testMatchOneAndVoid() throws Throwable {
mockCallFactory.setExpectedCreateVoidStubCalls(1);
- mockCallFactory.setupCreateVoidStub(mockVoidStub);
mockCallFactory.addExpectedCreateCallSignature(METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockVoidStub);
mockCallFactory.setupCreateCallSignature(mockCallMatch);
mockCallFactory.addExpectedCreateCallExpectation(mockCallMatch);
mockCallFactory.setupCreateCallExpectation(mockExpectedCall);
- mockCallableAddable.addExpectedAddMatch(mockCallMatch);
+ mockCallables.matchedCallables.addExpected(mockCallMatch);
mock.match(METHOD_ONEARG_NAME, METHOD_ONEARG_ARGS[0]);
Verifier.verifyObject(this);
- mockCallableAddable.verifyExpectations();
+ mockCallables.verifyExpectations();
}
public void testMatchOneAndReturn() throws Throwable {
- mockCallFactory.addExpectedCreateReturnStub(METHOD_ONEARG_RESULT);
- mockCallFactory.setupCreateReturnStub(mockReturnStub);
+ mockCallFactory.createReturnStub.setExpected(METHOD_ONEARG_RESULT);
mockCallFactory.addExpectedCreateCallSignature(METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockReturnStub);
mockCallFactory.setupCreateCallSignature(mockCallMatch);
- mockCallableAddable.addExpectedAddMatch(mockCallMatch);
- mockCallableAddable.setupCall(METHOD_ONEARG_RESULT);
+ mockCallables.matchedCallables.addExpected(mockCallMatch);
+ mockCallables.setupCall(METHOD_ONEARG_RESULT);
mock.matchAndReturn(METHOD_ONEARG_NAME, METHOD_ONEARG_ARGS[0], METHOD_ONEARG_RESULT);
Verifier.verifyObject(this);
- mockCallableAddable.verifyExpectations();
+ mockCallables.verifyExpectations();
}
public void testMatchOneAndThrow() throws Throwable {
- mockCallFactory.addExpectedCreateThrowStub(METHOD_EXCEPTION);
- mockCallFactory.setupCreateThrowStub(mockThrowStub);
+ mockCallFactory.createThrowStub.setExpected(METHOD_EXCEPTION);
mockCallFactory.addExpectedCreateCallSignature(METHOD_ONEARG_NAME, METHOD_ONEARG_CONSTRAINTS, mockThrowStub);
mockCallFactory.setupCreateCallSignature(mockCallMatch);
- mockCallableAddable.addExpectedAddMatch(mockCallMatch);
- mockCallableAddable.setupCall(METHOD_ONEARG_RESULT);
+ mockCallables.matchedCallables.addExpected(mockCallMatch);
+ mockCallables.setupCall(METHOD_ONEARG_RESULT);
mock.matchAndThrow(METHOD_ONEARG_NAME, METHOD_ONEARG_ARGS[0], METHOD_EXCEPTION);
Verifier.verifyObject(this);
- mockCallableAddable.verifyExpectations();
+ mockCallables.verifyExpectations();
}
public void testMatchManyAndVoid() throws Throwable {
mockCallFactory.setExpectedCreateVoidStubCalls(1);
- mockCallFactory.setupCreateVoidStub(mockVoidStub);
mockCallFactory.addExpectedCreateCallSignature(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockVoidStub);
mockCallFactory.setupCreateCallSignature(mockCallMatch);
mockCallFactory.addExpectedCreateCallExpectation(mockCallMatch);
mockCallFactory.setupCreateCallExpectation(mockExpectedCall);
- mockCallableAddable.addExpectedAddMatch(mockCallMatch);
+ mockCallables.matchedCallables.addExpected(mockCallMatch);
mock.match(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS);
Verifier.verifyObject(this);
- mockCallableAddable.verifyExpectations();
+ mockCallables.verifyExpectations();
}
public void testMatchManyAndReturn() throws Throwable {
- mockCallFactory.addExpectedCreateReturnStub(METHOD_TWOARG_RESULT);
- mockCallFactory.setupCreateReturnStub(mockReturnStub);
+ mockCallFactory.createReturnStub.setExpected(METHOD_TWOARG_RESULT);
mockCallFactory.addExpectedCreateCallSignature(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockReturnStub);
mockCallFactory.setupCreateCallSignature(mockCallMatch);
- mockCallableAddable.addExpectedAddMatch(mockCallMatch);
- mockCallableAddable.setupCall(METHOD_TWOARG_RESULT);
+ mockCallables.matchedCallables.addExpected(mockCallMatch);
+ mockCallables.setupCall(METHOD_TWOARG_RESULT);
mock.matchAndReturn(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, METHOD_TWOARG_RESULT);
Verifier.verifyObject(this);
- mockCallableAddable.verifyExpectations();
+ mockCallables.verifyExpectations();
}
public void testMatchManyAndThrow() throws Throwable {
- mockCallFactory.addExpectedCreateThrowStub(METHOD_EXCEPTION);
- mockCallFactory.setupCreateThrowStub(mockThrowStub);
+ mockCallFactory.createThrowStub.setExpected(METHOD_EXCEPTION);
mockCallFactory.addExpectedCreateCallSignature(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, mockThrowStub);
mockCallFactory.setupCreateCallSignature(mockCallMatch);
- mockCallableAddable.addExpectedAddMatch(mockCallMatch);
- mockCallableAddable.setupCall(METHOD_TWOARG_RESULT);
+ mockCallables.matchedCallables.addExpected(mockCallMatch);
+ mockCallables.setupCall(METHOD_TWOARG_RESULT);
mock.matchAndThrow(METHOD_TWOARG_NAME, METHOD_TWOARG_CONSTRAINTS, METHOD_EXCEPTION);
Verifier.verifyObject(this);
- mockCallableAddable.verifyExpectations();
+ mockCallables.verifyExpectations();
}
public void testMockAnnotatesAssertionFailedErrors()
throws Throwable {
final String originalMessage = "original message";
- mockCallableAddable.setupCall(new AssertionFailedError(originalMessage));
+ mockCallables.setupCall(new AssertionFailedError(originalMessage));
try {
proxy.noArgMethodVoid();
@@ -385,36 +382,36 @@
throws Throwable {
final String result = "configured result";
- mockCallableAddable.setupCall(result);
+ mockCallables.setupCall(result);
assertSame("result is returned by mock", result, proxy.oneArgMethod(METHOD_TWOARG_ARGS[0]));
}
public void testMockProxySendsAllArgument() throws Throwable {
- mockCallableAddable.addExpectedCall(METHOD_TWOARG_NAME, METHOD_TWOARG_ARGS);
- mockCallableAddable.setupCall("result ignored");
+ mockCallables.addExpectedCall(METHOD_TWOARG_NAME, METHOD_TWOARG_ARGS);
+ mockCallables.setupCall("result ignored");
proxy.twoArgMethod(METHOD_TWOARG_ARGS[0], METHOD_TWOARG_ARGS[1]);
- mockCallableAddable.verifyExpectations();
+ mockCallables.verifyExpectations();
}
public void testMockProxySendsEmptyArrayWhenNoArguments()
throws Exception {
- mockCallableAddable.addExpectedCall(METHOD_NOARG_NAME, METHOD_NOARG_ARGS);
- mockCallableAddable.setupCall("result ignored");
+ mockCallables.addExpectedCall(METHOD_NOARG_NAME, METHOD_NOARG_ARGS);
+ mockCallables.setupCall("result ignored");
proxy.noArgMethodVoid();
Verifier.verifyObject(this);
- mockCallableAddable.verifyExpectations();
+ mockCallables.verifyExpectations();
}
public void testMockProxyThrowsConfiguredExceptions()
throws Throwable {
final Throwable throwable = new DummyThrowable();
- mockCallableAddable.setupCall(new ThrowStub(throwable));
+ mockCallables.setupCall(new ThrowStub(throwable));
try {
proxy.noArgMethodVoid();
@@ -428,11 +425,11 @@
}
public void testMockVerifies() throws Exception {
- mockCallableAddable.setExpectedVerifyCalls(1);
+ mockCallables.setExpectedVerifyCalls(1);
mock.verify();
- mockCallableAddable.verifyExpectations();
+ mockCallables.verifyExpectations();
}
public void testProxyEquality() throws Exception {
@@ -444,7 +441,7 @@
CallStub ret = new ReturnStub(new Boolean(IGNORED_RESULT));
mockCallFactory.setupCreateReturnStub(ret);
mockCallFactory.setupCreateCallSignature(new CallSignature("call",C.anyArgs(1),ret));
- mockCallableAddable.setupCall(new Boolean(false));
+ mockCallables.setupCall(new Boolean(false));
mock.matchAndReturn("call", C.anyArgs(1), IGNORED_RESULT);
assertFalse("Should handle proxy inequality by calling through", proxy.equals("not a proxy"));
--- CallMatchTest.java DELETED ---
--- MockCallableAddable.java DELETED ---
|
|
From: Steve F. <sm...@us...> - 2003-07-06 02:29:43
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic
In directory sc8-pr-cvs1:/tmp/cvs-serv6575/src/core/com/mockobjects/dynamic
Added Files:
AbstractCallableCollection.java
Removed Files:
CallCollection.java
Log Message:
Renamed CallCollection to AbstractCallableCollection
--- NEW FILE: AbstractCallableCollection.java ---
package com.mockobjects.dynamic;
import junit.framework.AssertionFailedError;
abstract public class AbstractCallableCollection implements CallableCollection {
abstract public String getDescription();
abstract public Object call(ActiveCall call) throws Throwable;
public boolean matches(ActiveCall activeCall) {
throw new AssertionFailedError("matches() operation not supported in CallCollection");
}
public void reset() {
expectedCalls.clear();
matchingCalls.clear();
}
public void addExpect(Callable call) {
this.expectedCalls.add(call);
}
public void addMatch(Callable call) {
this.matchingCalls.add(call);
}
public void verify() {
expectedCalls.verify();
}
protected CallableList expectedCalls = new CallableList();
protected CallableList matchingCalls = new CallableList();
protected AssertionFailedError createUnexpectedCallError(ActiveCall call) {
StringBuffer buf = new StringBuffer();
buf.append("Unexpected call: ");
buf.append(call.toString());
buf.append("\n");
buf.append("Expected ");
buf.append(getDescription());
return new AssertionFailedError(buf.toString());
}
protected Callable findMatchingCall(ActiveCall call) throws AssertionFailedError {
Callable foundCall = matchingCalls.firstMatchingCall(call);
if (foundCall == null) {
throw createUnexpectedCallError(call);
}
return foundCall;
}
}
--- CallCollection.java DELETED ---
|
|
From: Steve F. <sm...@us...> - 2003-07-06 02:28:54
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic
In directory sc8-pr-cvs1:/tmp/cvs-serv6415/src/core/com/mockobjects/dynamic
Added Files:
CallableCollection.java
Removed Files:
CallableAddable.java
Log Message:
Renamed CallableAddable to CallableCollection
--- NEW FILE: CallableCollection.java ---
package com.mockobjects.dynamic;
public interface CallableCollection extends Callable {
void addExpect(Callable call);
void addMatch(Callable call);
/**
* Resets all expected calls and expected matches.
*/
void reset();
}
--- CallableAddable.java DELETED ---
|
|
From: Steve F. <sm...@us...> - 2003-07-06 02:27:11
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic
In directory sc8-pr-cvs1:/tmp/cvs-serv6257/src/core/com/mockobjects/dynamic
Modified Files:
C.java
Removed Files:
AnyConstraintMatcher.java
Log Message:
Inlined AnyConstraintMatcher
Index: C.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/C.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- C.java 1 Jun 2003 11:40:45 -0000 1.3
+++ C.java 6 Jul 2003 02:27:06 -0000 1.4
@@ -20,7 +20,11 @@
public static final Constraint IS_NOT_ZERO = not(IS_ZERO);
public static final ConstraintMatcher NO_ARGS = new FullConstraintMatcher(new Constraint[0]);
- public static final ConstraintMatcher ANY_ARGS = new AnyConstraintMatcher();
+ public static final ConstraintMatcher ANY_ARGS =
+ new ConstraintMatcher() {
+ public boolean matches(Object[] args) { return true; }
+ public Object[] getConstraints() { return new String[] {"ANY"};}
+ };
public static Constraint same( Object o ) {
return new IsSame(o);
--- AnyConstraintMatcher.java DELETED ---
|
|
From: Steve F. <sm...@us...> - 2003-07-06 02:25:23
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic
In directory sc8-pr-cvs1:/tmp/cvs-serv6114/src/core/com/mockobjects/dynamic
Modified Files:
DynamicUtil.java ActiveCall.java
Log Message:
moved toString to ActiveCall
Index: DynamicUtil.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/DynamicUtil.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DynamicUtil.java 5 Jul 2003 15:15:54 -0000 1.3
+++ DynamicUtil.java 6 Jul 2003 02:25:19 -0000 1.4
@@ -96,10 +96,6 @@
}
}
- public static String methodToString(ActiveCall call) {
- return methodToString(call.getMethodName(), call.args);
- }
-
public static String methodToString(String name, Object[] args) {
StringBuffer buf = new StringBuffer();
Index: ActiveCall.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/ActiveCall.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ActiveCall.java 5 Jul 2003 15:15:54 -0000 1.2
+++ ActiveCall.java 6 Jul 2003 02:25:19 -0000 1.3
@@ -21,4 +21,7 @@
return methodName;
}
+ public String toString() {
+ return DynamicUtil.methodToString(getMethodName(), args);
+ }
}
|