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. <st...@m3...> - 2003-07-05 23:14:29
|
Nat Pryce wrote: > Perhaps Invocation would be a better name. +1 I think you're right about Call, but that's just too confusing a name. We should move more things named Call, such as the CallFactory, to Callable. S. |
From: Tim M. <tim...@po...> - 2003-07-05 22:56:15
|
The way I see it - you are (or want to) construct a MethodMatcher based on a name or name constraint and parameters or parameter contraints (in dot net I believe you additional get a return type as well). I would expect this object to compare itself to a java Method object (at invoke time) and if it matches, do something (e.g. throw an exception or answer a value etc.) - the doing could involve a series of decorations as we have now (although my hunch is that we can simplify these down a bit). So the code that I see now - doesn't really work in this manner? I also feel - given some of the questions/features that other people have asked for, that matching is sometimes something people want different policies for on a method by method basis (e.g. match once only, match one or more) - (which combined with your excellent auto-return type stub, can give useful behavior especially in a name match constraint scenario like StartsWith("get")) So I think I would take the pieces that we have and combine them in a much different way. Tim > -----Original Message----- > From: moc...@li... > [mailto:moc...@li...]On Behalf Of > Nat Pryce > Sent: 05 July 2003 22:55 > To: Tim Mackinnon; Steve Freeman; 'Mockobjects-Java-Dev' > Subject: Re: [MO-java-dev] ActiveCall class > > > The name was meant to indicate that it represents the call currently > "active" in the mock. I agree that there is a better name. Personally I > would like to name it "Call" because all the other uses of the word "call" > don't actually refer to calls but to things that can be called. > > Perhaps Invocation would be a better name. > > There is actually very little behaviour required, as far as I > have used it. > It doesn't need to be compared to a method: it is constructed *from* a > method. Other objects (matchers, stubs, etc.) examine the state that it > carries. I guess some of that behaviour could be moved into the > ActiveCall > class but that feels wrong to me. Why should an invocation have knowledge > of the behaviour caused by that invocation? > > Cheers, > Nat. > _______________________ > Dr. Nathaniel Pryce > B13media Ltd. > http://www.b13media.com > +44 (0)7712 526 661 > > ----- Original Message ----- > From: "Tim Mackinnon" <tim...@po...> > To: "Steve Freeman" <st...@m3...>; "'Mockobjects-Java-Dev'" > <moc...@li...> > Sent: Saturday, July 05, 2003 8:28 PM > Subject: RE: [MO-java-dev] ActiveCall class > > > > The idea of ActiveCall is a good one (I'm not too keen on the name > myself - > > why is it active?) - Actually more to the point I'm kind of suprised its > got > > no behavior at all (making it even less active?). > > > > I would expect it to do work in deciding whether it was equal > to a Method > > (e.g. what invoke() gets) ...??? > > > > Tim --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.495 / Virus Database: 294 - Release Date: 30/06/2003 |
From: Nat P. <nat...@b1...> - 2003-07-05 21:58:54
|
The name was meant to indicate that it represents the call currently "active" in the mock. I agree that there is a better name. Personally I would like to name it "Call" because all the other uses of the word "call" don't actually refer to calls but to things that can be called. Perhaps Invocation would be a better name. There is actually very little behaviour required, as far as I have used it. It doesn't need to be compared to a method: it is constructed *from* a method. Other objects (matchers, stubs, etc.) examine the state that it carries. I guess some of that behaviour could be moved into the ActiveCall class but that feels wrong to me. Why should an invocation have knowledge of the behaviour caused by that invocation? Cheers, Nat. _______________________ Dr. Nathaniel Pryce B13media Ltd. http://www.b13media.com +44 (0)7712 526 661 ----- Original Message ----- From: "Tim Mackinnon" <tim...@po...> To: "Steve Freeman" <st...@m3...>; "'Mockobjects-Java-Dev'" <moc...@li...> Sent: Saturday, July 05, 2003 8:28 PM Subject: RE: [MO-java-dev] ActiveCall class > The idea of ActiveCall is a good one (I'm not too keen on the name myself - > why is it active?) - Actually more to the point I'm kind of suprised its got > no behavior at all (making it even less active?). > > I would expect it to do work in deciding whether it was equal to a Method > (e.g. what invoke() gets) ...??? > > Tim > > > -----Original Message----- > > From: moc...@li... > > [mailto:moc...@li...]On Behalf Of > > Steve Freeman > > Sent: 05 July 2003 16:18 > > To: 'Mockobjects-Java-Dev' > > Subject: [MO-java-dev] ActiveCall class > > > > > > being at a loose end, I took an executive decision and added a first cut > > at ActiveCall to the head release. I tagged before doing this so we can > > always roll back. It really starts to make the code collapse and I can > > see how some of the tests could be simplified. > > > > Any objections? > > > > S. > > > > > > > > ------------------------------------------------------- > > This SF.Net email sponsored by: Free pre-built ASP.NET sites including > > Data Reports, E-commerce, Portals, and Forums are available now. > > Download today and enter to win an XBOX or Visual Studio .NET. > > http://aspnet.click-url.com/go/psa00100006ave/direct;at.asp_061203_01/01 > > _______________________________________________ > > Mockobjects-java-dev mailing list > > Moc...@li... > > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev > > > > --- > > Incoming mail is certified Virus Free. > > Checked by AVG anti-virus system (http://www.grisoft.com). > > Version: 6.0.495 / Virus Database: 294 - Release Date: 30/06/2003 > > > --- > Outgoing mail is certified Virus Free. > Checked by AVG anti-virus system (http://www.grisoft.com). > Version: 6.0.495 / Virus Database: 294 - Release Date: 30/06/2003 > > > > ------------------------------------------------------- > This SF.Net email sponsored by: Free pre-built ASP.NET sites including > Data Reports, E-commerce, Portals, and Forums are available now. > Download today and enter to win an XBOX or Visual Studio .NET. > http://aspnet.click-url.com/go/psa00100006ave/direct;at.asp_061203_01/01 > _______________________________________________ > Mockobjects-java-dev mailing list > Moc...@li... > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev |
From: Joe W. <jo...@tr...> - 2003-07-05 19:37:13
|
Tim Mackinnon wrote: >The idea of ActiveCall is a good one (I'm not too keen on the name myself - >why is it active?) - Actually more to the point I'm kind of suprised its got >no behavior at all (making it even less active?). > How about InactiveCall? -joe |
From: Tim M. <tim...@po...> - 2003-07-05 19:24:55
|
The idea of ActiveCall is a good one (I'm not too keen on the name myself - why is it active?) - Actually more to the point I'm kind of suprised its got no behavior at all (making it even less active?). I would expect it to do work in deciding whether it was equal to a Method (e.g. what invoke() gets) ...??? Tim > -----Original Message----- > From: moc...@li... > [mailto:moc...@li...]On Behalf Of > Steve Freeman > Sent: 05 July 2003 16:18 > To: 'Mockobjects-Java-Dev' > Subject: [MO-java-dev] ActiveCall class > > > being at a loose end, I took an executive decision and added a first cut > at ActiveCall to the head release. I tagged before doing this so we can > always roll back. It really starts to make the code collapse and I can > see how some of the tests could be simplified. > > Any objections? > > S. > > > > ------------------------------------------------------- > This SF.Net email sponsored by: Free pre-built ASP.NET sites including > Data Reports, E-commerce, Portals, and Forums are available now. > Download today and enter to win an XBOX or Visual Studio .NET. > http://aspnet.click-url.com/go/psa00100006ave/direct;at.asp_061203_01/01 > _______________________________________________ > Mockobjects-java-dev mailing list > Moc...@li... > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev > > --- > Incoming mail is certified Virus Free. > Checked by AVG anti-virus system (http://www.grisoft.com). > Version: 6.0.495 / Virus Database: 294 - Release Date: 30/06/2003 > --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.495 / Virus Database: 294 - Release Date: 30/06/2003 |
From: Steve F. <sm...@us...> - 2003-07-05 16:35:53
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv1086/src/core/com/mockobjects/dynamic Modified Files: CallBag.java CallCollection.java CallSequence.java Added Files: CallableList.java Log Message: restructured CallBag, CallCollection, and CallSequence. Factored out CallableList --- NEW FILE: CallableList.java --- /* * Copyright mockobjects.com 05-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 ActiveCall call) { return apply(new Handler() { public Callable handle(int index, Callable callable) { return callable.matches(call) ? 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; } }); } } Index: CallBag.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallBag.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- CallBag.java 5 Jul 2003 15:15:54 -0000 1.5 +++ CallBag.java 5 Jul 2003 16:35:51 -0000 1.6 @@ -3,82 +3,37 @@ */ package com.mockobjects.dynamic; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - - -public class CallBag extends CallCollection implements Callable, CallableAddable { - private List expectedCalls = new ArrayList(); - private List expectedMatches = new ArrayList(); - - public CallBag() { - } - - public void reset() { - this.expectedCalls.clear(); - this.expectedMatches.clear(); - } +public class CallBag extends CallCollection { public Object call(ActiveCall call) throws Throwable { - Callable matchingCall = findMatchingCall(call, this.expectedCalls); - if(matchingCall == null) { - matchingCall = findMatchingCall(call, this.expectedMatches); - } - if(matchingCall == null) { - throw createUnexpectedCallError(call); + Callable foundCall = expectedCalls.firstMatchingCall(call); + if (foundCall == null) { + foundCall = findMatchingCall(call); } - return matchingCall.call(call); - } - - private Callable findMatchingCall(ActiveCall call, List callList) { - for (Iterator nextCall = callList.iterator(); nextCall.hasNext();) { - Callable element = (Callable) nextCall.next(); - - if (element.matches(call)) { - return element; - } - } - - return null; + return foundCall.call(call); } public String getDescription() { - if (this.expectedCalls.isEmpty()) { + if (expectedCalls.isEmpty()) { return "no methods"; } else { - StringBuffer buf = new StringBuffer(); + final StringBuffer buf = new StringBuffer(); buf.append("one of:\n"); - for (Iterator i = this.expectedCalls.iterator(); i.hasNext();) { - buf.append(((Callable) i.next()).getDescription()); - buf.append("\n"); - } + expectedCalls.apply( + new CallableList.Handler() { + public Callable handle(int index, Callable callable) { + buf.append(callable.getDescription()); + buf.append("\n"); + return null; + } + }); return buf.toString(); } - } - - public boolean matches(ActiveCall activeCall) { - throw new Error("not implemented"); - } - - public void verify() { - for (Iterator call = this.expectedCalls.iterator(); call.hasNext();) { - Callable element = (Callable) call.next(); - element.verify(); - } - } - - public void addExpect(Callable call) { - this.expectedCalls.add(call); - } - - public void addMatch(Callable call) { - this.expectedMatches.add(call); } } Index: CallCollection.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallCollection.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- CallCollection.java 5 Jul 2003 15:15:54 -0000 1.4 +++ CallCollection.java 5 Jul 2003 16:35:51 -0000 1.5 @@ -2,10 +2,35 @@ import junit.framework.AssertionFailedError; -abstract public class CallCollection { +abstract public class CallCollection implements Callable, CallableAddable { - protected AssertionFailedError createUnexpectedCallError(ActiveCall call) { - + abstract public String getDescription(); + + 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(DynamicUtil.methodToString(call)); @@ -15,5 +40,12 @@ return new AssertionFailedError(buf.toString()); } - abstract protected String getDescription(); + protected Callable findMatchingCall(ActiveCall call) throws AssertionFailedError { + Callable foundCall = matchingCalls.firstMatchingCall(call); + if (foundCall == null) { + throw createUnexpectedCallError(call); + } + return foundCall; + } + } Index: CallSequence.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallSequence.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- CallSequence.java 5 Jul 2003 15:15:54 -0000 1.7 +++ CallSequence.java 5 Jul 2003 16:35:51 -0000 1.8 @@ -1,73 +1,45 @@ package com.mockobjects.dynamic; -import java.util.ArrayList; -import java.util.Iterator; - import junit.framework.AssertionFailedError; -public class CallSequence extends CallCollection implements Callable, CallableAddable { +public class CallSequence extends CallCollection { - private ArrayList expectedCalls = new ArrayList(); - private CallBag matchedCalls = new CallBag(); int callIndex = 0; - public void reset() - { - this.expectedCalls.clear(); - this.matchedCalls.reset(); - } - - public Object call(ActiveCall activeCall) throws Throwable { - if (expectedCalls.size() == 0) throw new AssertionFailedError("no methods defined on mock, received: " + DynamicUtil.methodToString(activeCall)); - if (callIndex == expectedCalls.size()) throw new AssertionFailedError("mock called too many times, received: " + DynamicUtil.methodToString(activeCall)); + public Object call(ActiveCall activeCall) throws Throwable { + if (expectedCalls.isEmpty()) + throw new AssertionFailedError("no methods defined on mock, received: " + DynamicUtil.methodToString(activeCall)); + if (callIndex == expectedCalls.size()) + throw new AssertionFailedError("mock called too many times, received: " + DynamicUtil.methodToString(activeCall)); - Callable callable = (Callable)expectedCalls.get(callIndex++); - if (callable.matches(activeCall)) + Callable callable = expectedCalls.get(callIndex++); + if (callable.matches(activeCall)) { + //TODO shouldn't callIndex be incremented here? return callable.call(activeCall); - - try { - return matchedCalls.call(activeCall); - } catch (AssertionFailedError ex) { - throw createUnexpectedCallError(activeCall); } + + return findMatchingCall(activeCall).call(activeCall); } public String getDescription() { if (expectedCalls.isEmpty()) { return "no methods"; } else { - StringBuffer buf = new StringBuffer(); - + final StringBuffer buf = new StringBuffer(); buf.append("in sequence:\n"); - int j=0; - for (Iterator i = expectedCalls.iterator(); i.hasNext();) { - buf.append(((Callable)i.next()).getDescription()); - if (j++==(callIndex-1)) buf.append(" <<< Next Expected Call"); - buf.append("\n"); - } - + expectedCalls.apply( + new CallableList.Handler() { + public Callable handle(int index, Callable callable) { + buf.append(callable.getDescription()); + if (index == (callIndex - 1)) + buf.append(" <<< Next Expected Call"); + buf.append("\n"); + return null; + } + }); return buf.toString(); } } - - public boolean matches(ActiveCall activeCall) { - throw new AssertionFailedError("matches() operation not supported in CallSequence"); - } - - public void addExpect(Callable call) { - expectedCalls.add(call); - } - - public void addMatch(Callable call) { - matchedCalls.addMatch(call); - } - - public void verify() { - for (Iterator iter = expectedCalls.iterator(); iter.hasNext();) { - Callable callable = (Callable) iter.next(); - callable.verify(); - } - } } |
From: Steve F. <sm...@us...> - 2003-07-05 16:35:23
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv1036/src/core/test/mockobjects/dynamic Modified Files: CallOnceExpectationTest.java CallMatchTest.java CallSequenceTest.java MockCallable.java Log Message: renamed setupMatchesReturn to setupAlwaysMatchesCall Index: CallOnceExpectationTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/CallOnceExpectationTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- CallOnceExpectationTest.java 5 Jul 2003 15:15:54 -0000 1.3 +++ CallOnceExpectationTest.java 5 Jul 2003 16:35:20 -0000 1.4 @@ -59,7 +59,7 @@ public void testMatchesDelegated() throws Throwable { mockCallable.setExpectedMatches( METHOD_NAME, ARGS ); - mockCallable.setupMatchesReturn(true); + mockCallable.setupAlwaysMatchActiveCall(true); assertTrue( "returns matches to be true", call.matches( CALL ) ); mockCallable.verifyExpectations(); } @@ -74,7 +74,7 @@ public void testDoesNotMatchAfterMethodCalled() throws Throwable { - mockCallable.setupMatchesReturn(true); + mockCallable.setupAlwaysMatchActiveCall(true); mockCallable.setupCallReturn(RESULT); assertTrue( "First time should match", call.matches( CALL )); Index: CallMatchTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/CallMatchTest.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- CallMatchTest.java 5 Jul 2003 15:15:54 -0000 1.5 +++ CallMatchTest.java 5 Jul 2003 16:35:20 -0000 1.6 @@ -72,7 +72,7 @@ public void testMatchesAfterCalls() throws Throwable { mockCallable.setupCallReturn("result"); - mockCallable.setupMatchesReturn(true); + mockCallable.setupAlwaysMatchActiveCall(true); mockConstraintMatcher.setupMatches(true); Index: CallSequenceTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/CallSequenceTest.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- CallSequenceTest.java 5 Jul 2003 15:15:54 -0000 1.10 +++ CallSequenceTest.java 5 Jul 2003 16:35:20 -0000 1.11 @@ -42,7 +42,7 @@ public void testCallableThrowableThrown() throws Throwable { final Throwable throwable = new DummyThrowable(); - mockCallable.setupMatchesReturn(true); + mockCallable.setupAlwaysMatchActiveCall(true); mockCallable.setupCallThrow(throwable); callSequence.addExpect(mockCallable); @@ -67,7 +67,7 @@ } public void testCallFailsWithTooManyCalls() throws Throwable { - mockCallable.setupMatchesReturn(true); + mockCallable.setupAlwaysMatchActiveCall(true); mockCallable.setupCallReturn(METHOD_A_RESULT); callSequence.addExpect(mockCallable); callSequence.call(new ActiveCall("willdefinitelyMatch", new Object[0])); @@ -85,7 +85,7 @@ public void testCallPassedToContainedElements() throws Throwable { methodA.setExpectedMatches(METHOD_A_NAME, METHOD_A_ARGS); - methodA.setupMatchesReturn(true); + methodA.setupAlwaysMatchActiveCall(true); methodA.activeCall.setExpected(METHOD_A_CALL); methodA.setupCallReturn(METHOD_A_RESULT); @@ -102,7 +102,7 @@ public void testCallPassedToContainedElementsOtherOrderShouldFail() throws Throwable { - methodA.setupMatchesReturn(false); + methodA.setupAlwaysMatchActiveCall(false); methodA.setupGetDescription("***methodA-description****"); methodB.setupGetDescription("***methodB-description****"); @@ -133,7 +133,7 @@ final String result = "result"; mockCallable.setupCallReturn(result); - mockCallable.setupMatchesReturn(true); + mockCallable.setupAlwaysMatchActiveCall(true); callSequence.addExpect(mockCallable); @@ -150,11 +150,11 @@ final ActiveCall methodCCall = new ActiveCall(methodCName, methodCArgs); methodA.setExpectedMatches(methodCName, methodCArgs); - methodA.setupMatchesReturn(false); + methodA.setupAlwaysMatchActiveCall(false); methodA.activeCall.setExpectNothing(); methodA.setupGetDescription("***methodA-description****"); methodB.activeCall.setExpected(methodCCall); - methodB.setupMatchesReturn(false); + methodB.setupAlwaysMatchActiveCall(false); methodB.activeCall.setExpectNothing(); methodB.setupGetDescription("***methodB-description****"); Index: MockCallable.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockCallable.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- MockCallable.java 5 Jul 2003 15:15:54 -0000 1.4 +++ MockCallable.java 5 Jul 2003 16:35:20 -0000 1.5 @@ -60,7 +60,7 @@ matchesCount.setExpected(count); } - public void setupMatchesReturn( boolean result ) { + public void setupAlwaysMatchActiveCall( boolean result ) { matchesResult.setValue(result); } |
From: Steve F. <sm...@us...> - 2003-07-05 16:34:19
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv885/src/core/test/mockobjects/dynamic Modified Files: CallBagTest.java Log Message: renamed callSet variable to callBag Index: CallBagTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/CallBagTest.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- CallBagTest.java 5 Jul 2003 15:15:54 -0000 1.6 +++ CallBagTest.java 5 Jul 2003 16:34:14 -0000 1.7 @@ -19,7 +19,7 @@ final String[] METHOD_B_ARGS = new String[] { "b1", "b2" }; final ActiveCall METHOD_B_CALL = new ActiveCall(METHOD_B_NAME, METHOD_B_ARGS); - private CallBag callSet = new CallBag(); + private CallBag callBag = new CallBag(); private MockCallable methodA = new MockCallable("method a"); private MockCallable methodB = new MockCallable("method b"); @@ -32,7 +32,7 @@ public void testCallFailsOnEmptySet() throws Throwable { try { - callSet.call(new ActiveCall("missingMethod", new Object[0])); + callBag.call(new ActiveCall("missingMethod", new Object[0])); } catch (AssertionFailedError ex) { AssertMo.assertIncludes("reports empty set in error message", "no methods", ex.getMessage()); @@ -44,16 +44,16 @@ public void testCallPassedToContainedElements() throws Throwable { methodA.setExpectedMatches(METHOD_A_NAME, METHOD_A_ARGS); - methodA.setupMatchesReturn(true); + methodA.setupAlwaysMatchActiveCall(true); methodA.activeCall.setExpected(METHOD_A_CALL); methodA.setupCallReturn(METHOD_A_RESULT); methodB.activeCall.setExpectNothing(); - callSet.addExpect(methodA); - callSet.addExpect(methodB); + callBag.addExpect(methodA); + callBag.addExpect(methodB); - assertSame("expected result from method A", METHOD_A_RESULT, callSet.call(METHOD_A_CALL)); + assertSame("expected result from method A", METHOD_A_RESULT, callBag.call(METHOD_A_CALL)); methodA.verifyExpectations(); methodB.verifyExpectations(); @@ -64,29 +64,29 @@ Callable methodASignature = new CallSignature(METHOD_A_NAME,METHOD_A_CONSTRAINTS, new ReturnStub("result1")); Callable anotherMethodASignature = new CallSignature(METHOD_A_NAME,METHOD_A_CONSTRAINTS, new ReturnStub("result2")); - callSet.addMatch(methodASignature); - callSet.addExpect(new CallOnceExpectation(anotherMethodASignature)); + callBag.addMatch(methodASignature); + callBag.addExpect(new CallOnceExpectation(anotherMethodASignature)); assertSame("expected result from method B, as expect has precendence over match", "result2", - callSet.call(METHOD_A_CALL)); + callBag.call(METHOD_A_CALL)); } public void testCallPassedToContainedElementsOtherOrder() throws Throwable { methodA.setExpectedMatches(METHOD_B_NAME, METHOD_B_ARGS); - methodA.setupMatchesReturn(false); + methodA.setupAlwaysMatchActiveCall(false); methodA.activeCall.setExpectNothing(); methodB.activeCall.setExpected(METHOD_B_CALL); methodB.setupCallReturn(METHOD_B_RESULT); methodB.setExpectedMatches(METHOD_B_NAME, METHOD_B_ARGS); - methodB.setupMatchesReturn(true); + methodB.setupAlwaysMatchActiveCall(true); - callSet.addExpect(methodA); - callSet.addExpect(methodB); + callBag.addExpect(methodA); + callBag.addExpect(methodB); assertSame("expected result from method B", METHOD_B_RESULT, - callSet.call(METHOD_B_CALL)); + callBag.call(METHOD_B_CALL)); methodA.verifyExpectations(); methodB.verifyExpectations(); @@ -96,31 +96,31 @@ final String result = "result"; mockCallable.setupCallReturn(result); - mockCallable.setupMatchesReturn(true); + mockCallable.setupAlwaysMatchActiveCall(true); - callSet.addExpect(mockCallable); + callBag.addExpect(mockCallable); - assertSame("result is returned by mock", result, callSet.call(new ActiveCall("method", new Object[0]))); + assertSame("result is returned by mock", result, callBag.call(new ActiveCall("method", new Object[0]))); } public void testCallableThrowableThrown() throws Throwable { final Throwable throwable = new DummyThrowable(); - mockCallable.setupMatchesReturn(true); + mockCallable.setupAlwaysMatchActiveCall(true); mockCallable.setupCallThrow(throwable); - callSet.addExpect(mockCallable); + callBag.addExpect(mockCallable); try { - callSet.call(new ActiveCall("hello", new String[0])); + callBag.call(new ActiveCall("anyMethod", new String[0])); } catch (Throwable ex) { - assertSame("exception is caught by mock", throwable, ex); + assertSame("exception was thrown by mock", throwable, ex); } } public void testEmptySetVerifies() throws Exception { - callSet.verify(); + callBag.verify(); } public void testFailureIfNoElementMatches() throws Throwable { @@ -129,19 +129,19 @@ final ActiveCall methodCCall = new ActiveCall(methodCName, methodCArgs); methodA.setExpectedMatches(methodCName, methodCArgs); - methodA.setupMatchesReturn(false); + methodA.setupAlwaysMatchActiveCall(false); methodA.activeCall.setExpectNothing(); methodA.setupGetDescription("***methodA-description****"); methodB.activeCall.setExpected(methodCCall); - methodB.setupMatchesReturn(false); + methodB.setupAlwaysMatchActiveCall(false); methodB.activeCall.setExpectNothing(); methodB.setupGetDescription("***methodB-description****"); - callSet.addExpect(methodA); - callSet.addExpect(methodB); + callBag.addExpect(methodA); + callBag.addExpect(methodB); try { - callSet.call(methodCCall); + callBag.call(methodCCall); } 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()); @@ -161,9 +161,9 @@ methodA.setExpectedVerifyCalls(1); methodB.setExpectedVerifyCalls(1); - callSet.addExpect(methodA); - callSet.addExpect(methodB); - callSet.verify(); + callBag.addExpect(methodA); + callBag.addExpect(methodB); + callBag.verify(); methodA.verifyExpectations(); methodB.verifyExpectations(); @@ -173,10 +173,10 @@ throws Exception { methodA.setExpectedVerifyCalls(1); methodA.setupVerifyThrow(new AssertionFailedError("verify failed")); - callSet.addExpect(methodA); + callBag.addExpect(methodA); try { - callSet.verify(); + callBag.verify(); } catch (AssertionFailedError ex) { methodA.verifyExpectations(); |
From: Steve F. <st...@m3...> - 2003-07-05 15:18:39
|
being at a loose end, I took an executive decision and added a first cut at ActiveCall to the head release. I tagged before doing this so we can always roll back. It really starts to make the code collapse and I can see how some of the tests could be simplified. Any objections? S. |
From: Steve F. <sm...@us...> - 2003-07-05 15:15:57
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv21732/src/core/test/mockobjects/dynamic Modified Files: CallOnceExpectationTest.java StubTest.java MockTest.java CallBagTest.java CallMatchTest.java MockCallableAddable.java CallSequenceTest.java MockCallable.java Log Message: Refactored methoName and arguments to ActiveCall object. Index: CallOnceExpectationTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/CallOnceExpectationTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- CallOnceExpectationTest.java 12 Jun 2003 22:45:16 -0000 1.2 +++ CallOnceExpectationTest.java 5 Jul 2003 15:15:54 -0000 1.3 @@ -10,11 +10,13 @@ final String RESULT = "result!"; final String METHOD_NAME = "methodName"; - final Object[] ARGS = { "arg1", "arg2" }; + final Object[] ARGS = { "arg1", "arg2" }; + final ActiveCall CALL = new ActiveCall(METHOD_NAME, ARGS) ; + final String DECORATED_DESCRIPTION = DynamicUtil.methodToString( METHOD_NAME, ARGS ); Mock ignoredMock = null; - MockCallable mockCallable = new MockCallable(); + MockCallable mockCallable = new MockCallable("mock callable"); CallOnceExpectation call = new CallOnceExpectation( mockCallable ); public CallOnceExpectationTest(String name) { @@ -49,7 +51,7 @@ mockCallable.setupCallReturn( RESULT ); mockCallable.setExpectedVerifyCalls(1); - call.call( METHOD_NAME, ARGS ); + call.call( CALL ); call.verify(); mockCallable.verifyExpectations(); @@ -58,15 +60,15 @@ public void testMatchesDelegated() throws Throwable { mockCallable.setExpectedMatches( METHOD_NAME, ARGS ); mockCallable.setupMatchesReturn(true); - assertTrue( "returns matches to be true", call.matches( METHOD_NAME, ARGS ) ); + assertTrue( "returns matches to be true", call.matches( CALL ) ); mockCallable.verifyExpectations(); } public void testCallArgumentsPassedThrough() throws Throwable { - mockCallable.setExpectedCall(ignoredMock, METHOD_NAME, ARGS); + mockCallable.activeCall.setExpected(CALL); mockCallable.setupCallReturn(RESULT); - call.call( METHOD_NAME, ARGS ); + call.call( CALL ); mockCallable.verifyExpectations(); } @@ -75,16 +77,16 @@ mockCallable.setupMatchesReturn(true); mockCallable.setupCallReturn(RESULT); - assertTrue( "First time should match", call.matches(METHOD_NAME, ARGS)); - call.call(METHOD_NAME, ARGS); - assertFalse( "Second time should not match", call.matches(METHOD_NAME, ARGS)); + assertTrue( "First time should match", call.matches( CALL )); + call.call( CALL ); + assertFalse( "Second time should not match", call.matches( CALL )); } public void testDecoratedResultPassedThrough() throws Throwable { mockCallable.setupCallReturn(RESULT); assertSame( "should return decorated's result", - RESULT, call.call( METHOD_NAME, ARGS ) ); + RESULT, call.call( CALL ) ); mockCallable.verifyExpectations(); } @@ -95,7 +97,7 @@ mockCallable.setupCallThrow(exception); try { - call.call( METHOD_NAME, ARGS ); + call.call( CALL ); fail("expected decorated's throwable to be thrown"); } catch( DummyThrowable ex ) { Index: StubTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/StubTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- StubTest.java 12 Jun 2003 22:45:16 -0000 1.3 +++ StubTest.java 5 Jul 2003 15:15:54 -0000 1.4 @@ -3,39 +3,31 @@ */ package test.mockobjects.dynamic; -import com.mockobjects.dynamic.*; +import junit.framework.TestCase; -import junit.framework.*; +import com.mockobjects.dynamic.ActiveCall; +import com.mockobjects.dynamic.ReturnStub; +import com.mockobjects.dynamic.ThrowStub; -/** - * @author dev - */ public class StubTest extends TestCase { public StubTest(String name) { super(name); } + ActiveCall stubCall = new ActiveCall("ignoredName", new Object[0]); + public void testReturnStub() throws Throwable { - final String result = "result"; - - ReturnStub stub = new ReturnStub(result); - String ignoredMethodName = "methodName"; - Object[] ignoredArgs = new Object[0]; + final String RESULT = "result"; - assertSame( "Should be the same result object", - result, stub.call( ignoredMethodName, ignoredArgs ) ); + assertSame( "Should be the same result object", RESULT, new ReturnStub(RESULT).call( stubCall) ); } public void testThrowStub() { final Throwable throwable = new DummyThrowable(); - ThrowStub stub = new ThrowStub(throwable); - String ignoredMethodName = "methodName"; - Object[] ignoredArgs = new Object[0]; - try { - stub.call( ignoredMethodName, ignoredArgs ); + new ThrowStub(throwable).call( stubCall ); } catch( Throwable t ) { assertSame( "Should be the same throwable", throwable, t ); Index: MockTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockTest.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- MockTest.java 2 Jul 2003 03:46:18 -0000 1.13 +++ MockTest.java 5 Jul 2003 15:15:54 -0000 1.14 @@ -29,11 +29,11 @@ private DummyInterface proxy; private Mock mock; private MockCallFactory mockCallFactory = new MockCallFactory(); - private MockCallable mockCallMatch = new MockCallable(); - private MockCallable mockExpectedCall = new MockCallable(); - private MockCallable mockReturnStub = new MockCallable(); - private MockCallable mockThrowStub = new MockCallable(); - private MockCallable mockVoidStub = new MockCallable(); + 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 MockCallableAddable mockCallableAddable = new MockCallableAddable(); public MockTest(String name) throws Exception { Index: CallBagTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/CallBagTest.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- CallBagTest.java 12 Jun 2003 22:45:16 -0000 1.5 +++ CallBagTest.java 5 Jul 2003 15:15:54 -0000 1.6 @@ -13,14 +13,17 @@ 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 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); + private CallBag callSet = new CallBag(); - private Mock unusedMock = null; - private MockCallable methodA = new MockCallable(); - private MockCallable methodB = new MockCallable(); - private MockCallable mockCallable = new MockCallable(); + private MockCallable methodA = new MockCallable("method a"); + private MockCallable methodB = new MockCallable("method b"); + private MockCallable mockCallable = new MockCallable("mock callable"); public CallBagTest(String name) { @@ -29,7 +32,7 @@ public void testCallFailsOnEmptySet() throws Throwable { try { - callSet.call("missingMethod", new Object[0]); + callSet.call(new ActiveCall("missingMethod", new Object[0])); } catch (AssertionFailedError ex) { AssertMo.assertIncludes("reports empty set in error message", "no methods", ex.getMessage()); @@ -42,16 +45,15 @@ public void testCallPassedToContainedElements() throws Throwable { methodA.setExpectedMatches(METHOD_A_NAME, METHOD_A_ARGS); methodA.setupMatchesReturn(true); - methodA.setExpectedCall(unusedMock, METHOD_A_NAME, METHOD_A_ARGS); + methodA.activeCall.setExpected(METHOD_A_CALL); methodA.setupCallReturn(METHOD_A_RESULT); - methodB.setExpectedCallCount(0); + methodB.activeCall.setExpectNothing(); callSet.addExpect(methodA); callSet.addExpect(methodB); - assertSame("expected result from method A", METHOD_A_RESULT, - callSet.call(METHOD_A_NAME, METHOD_A_ARGS)); + assertSame("expected result from method A", METHOD_A_RESULT, callSet.call(METHOD_A_CALL)); methodA.verifyExpectations(); methodB.verifyExpectations(); @@ -66,15 +68,15 @@ callSet.addExpect(new CallOnceExpectation(anotherMethodASignature)); assertSame("expected result from method B, as expect has precendence over match", "result2", - callSet.call(METHOD_A_NAME, METHOD_A_ARGS)); + callSet.call(METHOD_A_CALL)); } public void testCallPassedToContainedElementsOtherOrder() throws Throwable { methodA.setExpectedMatches(METHOD_B_NAME, METHOD_B_ARGS); methodA.setupMatchesReturn(false); - methodA.setExpectedCallCount(0); - methodB.setExpectedCall(unusedMock, METHOD_B_NAME, METHOD_B_ARGS); + methodA.activeCall.setExpectNothing(); + methodB.activeCall.setExpected(METHOD_B_CALL); methodB.setupCallReturn(METHOD_B_RESULT); methodB.setExpectedMatches(METHOD_B_NAME, METHOD_B_ARGS); @@ -84,7 +86,7 @@ callSet.addExpect(methodB); assertSame("expected result from method B", METHOD_B_RESULT, - callSet.call(METHOD_B_NAME, METHOD_B_ARGS)); + callSet.call(METHOD_B_CALL)); methodA.verifyExpectations(); methodB.verifyExpectations(); @@ -98,7 +100,7 @@ callSet.addExpect(mockCallable); - assertSame("result is returned by mock", result, callSet.call("method", new Object[0])); + assertSame("result is returned by mock", result, callSet.call(new ActiveCall("method", new Object[0]))); } public void testCallableThrowableThrown() @@ -111,7 +113,7 @@ callSet.addExpect(mockCallable); try { - callSet.call("hello", new String[0]); + callSet.call(new ActiveCall("hello", new String[0])); } catch (Throwable ex) { assertSame("exception is caught by mock", throwable, ex); } @@ -124,21 +126,22 @@ public void testFailureIfNoElementMatches() throws Throwable { final String methodCName = "methodC"; final String[] methodCArgs = { "c1", "c2" }; + final ActiveCall methodCCall = new ActiveCall(methodCName, methodCArgs); methodA.setExpectedMatches(methodCName, methodCArgs); methodA.setupMatchesReturn(false); - methodA.setExpectedCallCount(0); + methodA.activeCall.setExpectNothing(); methodA.setupGetDescription("***methodA-description****"); - methodB.setExpectedCall(unusedMock, methodCName, methodCArgs); + methodB.activeCall.setExpected(methodCCall); methodB.setupMatchesReturn(false); - methodB.setExpectedCallCount(0); + methodB.activeCall.setExpectNothing(); methodB.setupGetDescription("***methodB-description****"); callSet.addExpect(methodA); callSet.addExpect(methodB); try { - callSet.call(methodCName, methodCArgs); + callSet.call(methodCCall); } 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: CallMatchTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/CallMatchTest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- CallMatchTest.java 12 Jun 2003 22:45:15 -0000 1.4 +++ CallMatchTest.java 5 Jul 2003 15:15:54 -0000 1.5 @@ -9,10 +9,12 @@ public class CallMatchTest extends TestCase { - private static final Object[] IGNORED_ARGS = new Object[0]; 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(); + MockCallable mockCallable = new MockCallable("mock callable"); MockConstraintMatcher mockConstraintMatcher = new MockConstraintMatcher(); CallSignature callSignature = new CallSignature(METHOD_NAME, mockConstraintMatcher, mockCallable); @@ -22,13 +24,12 @@ public void testCallArgumentsArePropagatedToDecorated() throws Throwable { - final Object[] arguments = IGNORED_ARGS; final String result = "result"; - mockCallable.setExpectedCall(mock, METHOD_NAME, arguments); + mockCallable.activeCall.setExpected(CALL); mockCallable.setupCallReturn(result); - callSignature.call(METHOD_NAME, arguments); + callSignature.call(CALL); mockCallable.verifyExpectations(); } @@ -45,7 +46,7 @@ mockCallable.setExpectedVerifyCalls(1); mockCallable.setupCallReturn("result"); - callSignature.call("methodName", IGNORED_ARGS); + callSignature.call(CALL); callSignature.verify(); mockCallable.verifyExpectations(); @@ -54,8 +55,8 @@ public void testMultipleCallsSucceed() throws Throwable { mockCallable.setupCallReturn("result"); - callSignature.call(METHOD_NAME, IGNORED_ARGS); - callSignature.call(METHOD_NAME, IGNORED_ARGS); + callSignature.call(CALL); + callSignature.call(CALL); mockCallable.verifyExpectations(); } @@ -65,7 +66,7 @@ } public void testCallDoesNotMatchWhenWrongName() throws Throwable { - assertFalse("call does not match", callSignature.matches("anotherName", IGNORED_ARGS)); + assertFalse("call does not match", callSignature.matches(new ActiveCall("anotherName", IGNORED_ARGS))); mockCallable.verifyExpectations(); } @@ -75,10 +76,10 @@ mockConstraintMatcher.setupMatches(true); - callSignature.call(METHOD_NAME, IGNORED_ARGS); - assertTrue("matches after first call", callSignature.matches(METHOD_NAME, IGNORED_ARGS)); - callSignature.call(METHOD_NAME, IGNORED_ARGS); - assertTrue("matches after further calls", callSignature.matches(METHOD_NAME, IGNORED_ARGS)); + callSignature.call(CALL); + assertTrue("matches after first call", callSignature.matches( CALL )); + callSignature.call(CALL); + assertTrue("matches after further calls", callSignature.matches( CALL )); mockCallable.verifyExpectations(); } @@ -90,13 +91,13 @@ mockConstraintMatcher.addExpectedMatches(args); mockConstraintMatcher.setupMatches(true); - assertTrue("matches delegated to constraint matcher", callSignature.matches(METHOD_NAME, args)); + 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(METHOD_NAME, IGNORED_ARGS)); + assertFalse("Should not match if constraint matcher doesn't", callSignature.matches(CALL)); } } Index: MockCallableAddable.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockCallableAddable.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- MockCallableAddable.java 12 Jun 2003 22:45:15 -0000 1.3 +++ MockCallableAddable.java 5 Jul 2003 15:15:54 -0000 1.4 @@ -4,6 +4,7 @@ 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.CallableAddable; import com.mockobjects.util.NotImplementedException; @@ -65,10 +66,10 @@ myMatchesParameter1Values.addExpected(arg1); } - public boolean matches(String arg0, Object[] arg1) { + public boolean matches(ActiveCall call) { myMatchesCalls.inc(); - myMatchesParameter0Values.addActual(arg0); - myMatchesParameter1Values.addActual(arg1); + myMatchesParameter0Values.addActual(call.getMethodName()); + myMatchesParameter1Values.addActual(call.args); Object nextReturnValue = myActualMatchesReturnValues.getNext(); @@ -104,11 +105,11 @@ myCallArguments.addExpectedMany(args); } - public Object call(String methodName, Object[] args) + public Object call(ActiveCall call) throws Throwable { myCallCalls.inc(); - myCallMethodNames.addActual(methodName); - myCallArguments.addActualMany(args); + myCallMethodNames.addActual(call.getMethodName()); + myCallArguments.addActualMany(call.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.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- CallSequenceTest.java 12 Jun 2003 22:45:16 -0000 1.9 +++ CallSequenceTest.java 5 Jul 2003 15:15:54 -0000 1.10 @@ -9,7 +9,6 @@ import com.mockobjects.dynamic.CallSequence; import com.mockobjects.dynamic.Callable; import com.mockobjects.dynamic.CallOnceExpectation; -import com.mockobjects.dynamic.Mock; import com.mockobjects.dynamic.ReturnStub; import com.mockobjects.util.AssertMo; @@ -25,13 +24,16 @@ 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 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); + private CallSequence callSequence = new CallSequence(); - private Mock unusedMock = null; - private MockCallable methodA = new MockCallable(); - private MockCallable methodB = new MockCallable(); - private MockCallable mockCallable = new MockCallable(); + private MockCallable methodA = new MockCallable("method a"); + private MockCallable methodB = new MockCallable("method b"); + private MockCallable mockCallable = new MockCallable("mock callable"); public CallSequenceTest(String name) { super(name); @@ -46,7 +48,7 @@ callSequence.addExpect(mockCallable); try { - callSequence.call("hello", new String[0]); + callSequence.call(new ActiveCall("hello", new String[0])); } catch (Throwable ex) { assertSame("exception is caught by mock", throwable, ex); } @@ -54,7 +56,7 @@ public void testCallFailsOnEmptyList() throws Throwable { try { - callSequence.call("missingMethod", new Object[0]); + callSequence.call(new ActiveCall("missingMethod", new Object[0])); } catch (AssertionFailedError ex) { AssertMo.assertIncludes("reports empty set in error message", "no methods", ex.getMessage()); @@ -68,10 +70,10 @@ mockCallable.setupMatchesReturn(true); mockCallable.setupCallReturn(METHOD_A_RESULT); callSequence.addExpect(mockCallable); - callSequence.call("willdefinitelyMatch", new Object[0]); + callSequence.call(new ActiveCall("willdefinitelyMatch", new Object[0])); try { - callSequence.call("oneMethodTooMany", new Object[0]); + callSequence.call(new ActiveCall("oneMethodTooMany", new Object[0])); } catch (AssertionFailedError ex) { AssertMo.assertIncludes("reports one method call too many", "too many", ex.getMessage()); @@ -84,15 +86,15 @@ public void testCallPassedToContainedElements() throws Throwable { methodA.setExpectedMatches(METHOD_A_NAME, METHOD_A_ARGS); methodA.setupMatchesReturn(true); - methodA.setExpectedCall(unusedMock, METHOD_A_NAME, METHOD_A_ARGS); + methodA.activeCall.setExpected(METHOD_A_CALL); methodA.setupCallReturn(METHOD_A_RESULT); - methodB.setExpectedCallCount(0); + methodB.activeCall.setExpectNothing(); callSequence.addExpect(methodA); callSequence.addExpect(methodB); - assertSame("expected result from method A", METHOD_A_RESULT, callSequence.call(METHOD_A_NAME, METHOD_A_ARGS)); + assertSame("expected result from method A", METHOD_A_RESULT, callSequence.call(METHOD_A_CALL)); methodA.verifyExpectations(); methodB.verifyExpectations(); @@ -109,7 +111,7 @@ callSequence.addExpect(methodB); try { - assertSame("expected result from method B", METHOD_B_RESULT, callSequence.call(METHOD_B_NAME, METHOD_B_ARGS)); + assertSame("expected result from method B", METHOD_B_RESULT, callSequence.call(METHOD_B_CALL)); } catch (AssertionFailedError ex) { String message = ex.getMessage(); AssertMo.assertIncludes("Should have expected error message", "Unexpected call: methodB", message); @@ -135,7 +137,7 @@ callSequence.addExpect(mockCallable); - assertSame("result is returned by mock", result, callSequence.call("method", new Object[0])); + assertSame("result is returned by mock", result, callSequence.call(new ActiveCall("method", new Object[0]))); } public void testEmptySetVerifies() throws Exception { @@ -145,21 +147,22 @@ public void testFailureIfNoElementMatches() throws Throwable { final String methodCName = "methodC"; final String[] methodCArgs = { "c1", "c2" }; - + final ActiveCall methodCCall = new ActiveCall(methodCName, methodCArgs); + methodA.setExpectedMatches(methodCName, methodCArgs); methodA.setupMatchesReturn(false); - methodA.setExpectedCallCount(0); + methodA.activeCall.setExpectNothing(); methodA.setupGetDescription("***methodA-description****"); - methodB.setExpectedCall(unusedMock, methodCName, methodCArgs); + methodB.activeCall.setExpected(methodCCall); methodB.setupMatchesReturn(false); - methodB.setExpectedCallCount(0); + methodB.activeCall.setExpectNothing(); methodB.setupGetDescription("***methodB-description****"); callSequence.addExpect(methodA); callSequence.addExpect(methodB); try { - callSequence.call(methodCName, methodCArgs); + callSequence.call(methodCCall); } 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()); @@ -213,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_NAME, METHOD_A_ARGS)); + callSequence.call(METHOD_A_CALL)); } } Index: MockCallable.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockCallable.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- MockCallable.java 12 Jun 2003 22:45:16 -0000 1.3 +++ MockCallable.java 5 Jul 2003 15:15:54 -0000 1.4 @@ -1,17 +1,21 @@ package test.mockobjects.dynamic; -import junit.framework.*; +import junit.framework.AssertionFailedError; -import com.mockobjects.*; +import com.mockobjects.ExpectationCounter; +import com.mockobjects.ExpectationList; +import com.mockobjects.ExpectationValue; +import com.mockobjects.ReturnValue; +import com.mockobjects.dynamic.ActiveCall; import com.mockobjects.dynamic.Callable; -import com.mockobjects.dynamic.Mock; -import com.mockobjects.util.*; +import com.mockobjects.util.Verifier; public class MockCallable implements Callable { - private ExpectationCounter callCount = new ExpectationCounter("call.count"); - private ExpectationValue callMethodName = new ExpectationValue("call.methodName"); - private ExpectationList callArgs = new ExpectationList("call.args"); + final public String name; + + public ExpectationValue activeCall = new ExpectationValue("call") ; + private ReturnValue callResult = new ReturnValue("call.return"); private Throwable callThrow = null; @@ -25,14 +29,8 @@ private ReturnValue toStringResult = new ReturnValue("toString.return"); - - public void setExpectedCallCount( int count ) { - callCount.setExpected(count); - } - - public void setExpectedCall( Mock mock, String methodName, Object[] args ) { - callMethodName.setExpected(methodName); - callArgs.addExpectedMany(args); + public MockCallable(String name) { + this.name = name; } public void setupCallReturn( Object result ) { @@ -43,11 +41,9 @@ callThrow = thrown; } - public Object call(String methodName, Object[] args) throws Throwable { - callMethodName.setActual(methodName); - callArgs.addActualMany(args); - callCount.inc(); - + public Object call(ActiveCall anActiveCall) throws Throwable { + activeCall.setActual(anActiveCall); + if( callThrow != null ) { throw callThrow; } else { @@ -68,9 +64,9 @@ matchesResult.setValue(result); } - public boolean matches(String methodName, Object[] args) { - matchesMethodName.setActual(methodName); - matchesArgs.addActualMany(args); + public boolean matches(ActiveCall call) { + matchesMethodName.setActual(call.getMethodName()); + matchesArgs.addActualMany(call.args); matchesCount.inc(); return matchesResult.getBooleanValue(); } @@ -103,5 +99,9 @@ public String getDescription() { return (String)toStringResult.getValue(); + } + + public String toString() { + return "MockCallable " + name; } } |
From: Steve F. <sm...@us...> - 2003-07-05 15:15:57
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv21732/src/core/com/mockobjects/dynamic Modified Files: Callable.java DynamicUtil.java ReturnStub.java CallBag.java VoidStub.java CallCollection.java CallOnceExpectation.java Mock.java CallStub.java CallSequence.java ThrowStub.java CallSignature.java Added Files: ActiveCall.java Log Message: Refactored methoName and arguments to ActiveCall object. Index: Callable.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Callable.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- Callable.java 12 Jun 2003 22:45:13 -0000 1.3 +++ Callable.java 5 Jul 2003 15:15:54 -0000 1.4 @@ -4,6 +4,6 @@ public interface Callable extends Verifiable { String getDescription(); - Object call( String methodName, Object[] args ) throws Throwable; - boolean matches(String methodName, Object[] args); + Object call( ActiveCall call ) throws Throwable; + boolean matches(ActiveCall activeCall); } Index: DynamicUtil.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/DynamicUtil.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- DynamicUtil.java 18 May 2003 20:59:35 -0000 1.2 +++ DynamicUtil.java 5 Jul 2003 15:15:54 -0000 1.3 @@ -96,6 +96,10 @@ } } + 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: ReturnStub.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/ReturnStub.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ReturnStub.java 5 Jul 2003 10:11:01 -0000 1.4 +++ ReturnStub.java 5 Jul 2003 15:15:54 -0000 1.5 @@ -12,7 +12,7 @@ this.result = result; } - public Object call(String methodName, Object[] args) throws Throwable { + public Object call(ActiveCall args) throws Throwable { return result; } Index: CallBag.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallBag.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- CallBag.java 12 Jun 2003 22:45:14 -0000 1.4 +++ CallBag.java 5 Jul 2003 15:15:54 -0000 1.5 @@ -20,25 +20,25 @@ this.expectedMatches.clear(); } - public Object call(String methodName, Object[] args) + public Object call(ActiveCall call) throws Throwable { - Callable matchingCall = findMatchingCall(methodName, args, this.expectedCalls); + Callable matchingCall = findMatchingCall(call, this.expectedCalls); if(matchingCall == null) { - matchingCall = findMatchingCall(methodName, args, this.expectedMatches); + matchingCall = findMatchingCall(call, this.expectedMatches); } if(matchingCall == null) { - throw createUnexpectedCallError(methodName, args); + throw createUnexpectedCallError(call); } - return matchingCall.call(methodName, args); + return matchingCall.call(call); } - private Callable findMatchingCall(String methodName, Object[] args, List callList) { - for (Iterator call = callList.iterator(); call.hasNext();) { - Callable element = (Callable) call.next(); + private Callable findMatchingCall(ActiveCall call, List callList) { + for (Iterator nextCall = callList.iterator(); nextCall.hasNext();) { + Callable element = (Callable) nextCall.next(); - if (element.matches(methodName, args)) { + if (element.matches(call)) { return element; } } @@ -63,7 +63,7 @@ } } - public boolean matches(String methodName, Object[] args) { + public boolean matches(ActiveCall activeCall) { throw new Error("not implemented"); } Index: VoidStub.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/VoidStub.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- VoidStub.java 12 Jun 2003 22:45:11 -0000 1.3 +++ VoidStub.java 5 Jul 2003 15:15:54 -0000 1.4 @@ -10,7 +10,7 @@ return "returns <void>"; } - public Object call(String methodName, Object[] args) throws Throwable { + public Object call(ActiveCall args) throws Throwable { return null; } Index: CallCollection.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallCollection.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- CallCollection.java 8 Jun 2003 21:48:24 -0000 1.3 +++ CallCollection.java 5 Jul 2003 15:15:54 -0000 1.4 @@ -4,11 +4,11 @@ abstract public class CallCollection { - protected AssertionFailedError createUnexpectedCallError(String methodName, Object[] args) { + protected AssertionFailedError createUnexpectedCallError(ActiveCall call) { StringBuffer buf = new StringBuffer(); buf.append("Unexpected call: "); - buf.append(DynamicUtil.methodToString(methodName, args)); + buf.append(DynamicUtil.methodToString(call)); buf.append("\n"); buf.append("Expected "); buf.append(getDescription()); Index: CallOnceExpectation.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallOnceExpectation.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- CallOnceExpectation.java 12 Jun 2003 22:45:13 -0000 1.2 +++ CallOnceExpectation.java 5 Jul 2003 15:15:54 -0000 1.3 @@ -14,13 +14,13 @@ return delegate.getDescription() + " [" + (wasCalled ? "" : "not ") + "called]"; } - public Object call(String methodName, Object[] args) throws Throwable { + public Object call(ActiveCall args) throws Throwable { wasCalled = true; - return delegate.call( methodName, args ); + return delegate.call( args ); } - public boolean matches(String methodName, Object[] args) { - return (!wasCalled) && delegate.matches( methodName, args ); + public boolean matches(ActiveCall activeCall) { + return (!wasCalled) && delegate.matches( activeCall ); } public void verify() { Index: Mock.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Mock.java,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- Mock.java 2 Jul 2003 03:46:18 -0000 1.24 +++ Mock.java 5 Jul 2003 15:15:54 -0000 1.25 @@ -80,24 +80,27 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { try { - if (isCheckingEqualityOnProxy(method, args)) { + ActiveCall activeCall = new ActiveCall(method, args); + + if (isCheckingEqualityOnProxy(activeCall)) { return new Boolean(args[0] == this.proxy); - } else if (isMockNameGetter(method, args)) { + } else if (isMockNameGetter(activeCall)) { return this.getMockName(); } else { - return calls.call(method.getName(), (args == null ? new Object[0] : args)); + return calls.call(activeCall); } } catch (AssertionFailedError ex) { throw new AssertionFailedError(name + ": " + ex.getMessage()); } } - private boolean isCheckingEqualityOnProxy(Method method, Object[] args) { - return (method.getName().equals("equals")) && (args.length == 1) && (Proxy.isProxyClass(args[0].getClass())); + private boolean isCheckingEqualityOnProxy(ActiveCall call) { + return (call.getMethodName().equals("equals")) && (call.args.length == 1) + && (Proxy.isProxyClass(call.args[0].getClass())); } - private boolean isMockNameGetter(Method method, Object[] args) { - return (method.getName().equals("getMockName")) && (args.length == 0); + private boolean isMockNameGetter(ActiveCall call) { + return (call.getMethodName().equals("getMockName")) && (call.args.length == 0); } public void verify() { Index: CallStub.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallStub.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- CallStub.java 10 Jun 2003 17:07:45 -0000 1.3 +++ CallStub.java 5 Jul 2003 15:15:54 -0000 1.4 @@ -6,7 +6,7 @@ public abstract class CallStub implements Callable { - public boolean matches(String methodName, Object[] args) { + public boolean matches(ActiveCall activeCall) { return true; } Index: CallSequence.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallSequence.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- CallSequence.java 12 Jun 2003 22:45:12 -0000 1.6 +++ CallSequence.java 5 Jul 2003 15:15:54 -0000 1.7 @@ -17,18 +17,18 @@ this.matchedCalls.reset(); } - public Object call(String methodName, Object[] args) throws Throwable { - if (expectedCalls.size() == 0) throw new AssertionFailedError("no methods defined on mock, received: " + DynamicUtil.methodToString(methodName, args)); - if (callIndex == expectedCalls.size()) throw new AssertionFailedError("mock called too many times, received: " + DynamicUtil.methodToString(methodName, args)); + public Object call(ActiveCall activeCall) throws Throwable { + if (expectedCalls.size() == 0) throw new AssertionFailedError("no methods defined on mock, received: " + DynamicUtil.methodToString(activeCall)); + if (callIndex == expectedCalls.size()) throw new AssertionFailedError("mock called too many times, received: " + DynamicUtil.methodToString(activeCall)); - Callable nextCall = (Callable)expectedCalls.get(callIndex++); - if (nextCall.matches(methodName, args)) - return nextCall.call(methodName, args); + Callable callable = (Callable)expectedCalls.get(callIndex++); + if (callable.matches(activeCall)) + return callable.call(activeCall); try { - return matchedCalls.call(methodName, args); + return matchedCalls.call(activeCall); } catch (AssertionFailedError ex) { - throw createUnexpectedCallError(methodName, args); + throw createUnexpectedCallError(activeCall); } } @@ -51,7 +51,7 @@ } } - public boolean matches(String methodName, Object[] args) { + public boolean matches(ActiveCall activeCall) { throw new AssertionFailedError("matches() operation not supported in CallSequence"); } Index: ThrowStub.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/ThrowStub.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ThrowStub.java 5 Jul 2003 10:11:01 -0000 1.4 +++ ThrowStub.java 5 Jul 2003 15:15:54 -0000 1.5 @@ -12,7 +12,7 @@ this.throwable = throwable; } - public Object call(String methodName, Object[] args) throws Throwable { + public Object call(ActiveCall args) throws Throwable { throw throwable; } Index: CallSignature.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallSignature.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- CallSignature.java 12 Jun 2003 22:45:14 -0000 1.2 +++ CallSignature.java 5 Jul 2003 15:15:54 -0000 1.3 @@ -14,18 +14,18 @@ this.delegate = delegate; } - public Object call( String methodName, Object[] args ) + public Object call( ActiveCall args ) throws Throwable { - return delegate.call( methodName, args ); + return delegate.call( args ); } public void verify() { delegate.verify(); } - public boolean matches(String methodName, Object[] args) { - return this.methodName.equals(methodName) && constraints.matches(args); + public boolean matches(ActiveCall activeCall) { + return this.methodName.equals(activeCall.getMethodName()) && constraints.matches(activeCall.args); } public String getDescription() { |
From: Steve F. <sm...@us...> - 2003-07-05 10:11:04
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv20244/src/core/com/mockobjects/dynamic Modified Files: ReturnStub.java ThrowStub.java Log Message: removed unnecessary comment Index: ReturnStub.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/ReturnStub.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ReturnStub.java 12 Jun 2003 22:45:14 -0000 1.3 +++ ReturnStub.java 5 Jul 2003 10:11:01 -0000 1.4 @@ -3,9 +3,6 @@ */ package com.mockobjects.dynamic; -/** - * @author dev - */ public class ReturnStub extends CallStub { Index: ThrowStub.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/ThrowStub.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ThrowStub.java 12 Jun 2003 22:45:13 -0000 1.3 +++ ThrowStub.java 5 Jul 2003 10:11:01 -0000 1.4 @@ -3,9 +3,6 @@ */ package com.mockobjects.dynamic; -/** - * @author dev - */ public class ThrowStub extends CallStub { |
From: Steve F. <sm...@us...> - 2003-07-05 10:09:22
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv20030/src/core/com/mockobjects/dynamic Modified Files: Tag: Nat_reworks_dynamics_from_0_09 Mock.java Added Files: Tag: Nat_reworks_dynamics_from_0_09 MockInvocationError.java Log Message: Added a MockInvocationError to specialise error handling --- NEW FILE: MockInvocationError.java --- package com.mockobjects.dynamic; import junit.framework.AssertionFailedError; public class MockInvocationError extends AssertionFailedError { public final ActiveCall call; public MockInvocationError() { super(); call = null; } public MockInvocationError(String message) { this(message, null); } public MockInvocationError(String message, ActiveCall aCall) { super(message); call = aCall; } } Index: Mock.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Mock.java,v retrieving revision 1.23.2.1 retrieving revision 1.23.2.2 diff -u -r1.23.2.1 -r1.23.2.2 --- Mock.java 21 Jun 2003 14:01:07 -0000 1.23.2.1 +++ Mock.java 5 Jul 2003 10:09:19 -0000 1.23.2.2 @@ -82,7 +82,7 @@ return call( call ); } } catch (AssertionFailedError ex) { - throw new AssertionFailedError(name + ": " + ex.getMessage()); + throw new MockInvocationError(name + ": " + ex.getMessage(), call); } } |
From: Tim M. <tim...@po...> - 2003-07-03 23:33:51
|
That seems like a good way of handling the future direction. I want to do an alternate branch that would better match what I'm thinking of trying with dynamockdotnet. Tim > -----Original Message----- > From: moc...@li... > [mailto:moc...@li...]On Behalf Of > Nat Pryce > Sent: 03 July 2003 15:16 > To: Moc...@Li... > Subject: [MO-java-dev] Merging branches > > > To help any merge between my branch and the head branch, I've > put a page on > the Mock Objects wiki describing the changes I made in my branch and why, > along with voting boxes so that people can say whether they like > or dislike > each change. > > It's at: http://www.mockobjects.com/wiki/ChangesInNatsBranch > > Cheers, > Nat. > > _______________________ > Dr. Nathaniel Pryce > B13media Ltd. > http://www.b13media.com > +44 (0)7712 526 661 > > > > > ------------------------------------------------------- > This SF.Net email sponsored by: Free pre-built ASP.NET sites including > Data Reports, E-commerce, Portals, and Forums are available now. > Download today and enter to win an XBOX or Visual Studio .NET. > http://aspnet.click-url.com/go/psa00100006ave/direct;at.asp_061203_01/01 > _______________________________________________ > Mockobjects-java-dev mailing list > Moc...@li... > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev > > --- > Incoming mail is certified Virus Free. > Checked by AVG anti-virus system (http://www.grisoft.com). > Version: 6.0.495 / Virus Database: 294 - Release Date: 30/06/2003 > --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.495 / Virus Database: 294 - Release Date: 30/06/2003 |
From: Nat P. <nat...@b1...> - 2003-07-03 14:20:07
|
To help any merge between my branch and the head branch, I've put a page on the Mock Objects wiki describing the changes I made in my branch and why, along with voting boxes so that people can say whether they like or dislike each change. It's at: http://www.mockobjects.com/wiki/ChangesInNatsBranch Cheers, Nat. _______________________ Dr. Nathaniel Pryce B13media Ltd. http://www.b13media.com +44 (0)7712 526 661 |
From: Vincent M. <vm...@pi...> - 2003-07-03 12:15:25
|
Hi Nat, > -----Original Message----- > From: Nat Pryce [mailto:nat...@b1...] > Sent: 03 July 2003 12:17 > To: Vincent Massol > Subject: Re: [MO-java-dev] dynamic branch and merge > > I think it will be very hard to provide complete backwards compatability. > Changing the dynamock library to use the ActiveCall class will change the > Callable method, and thereby change every class that implements or calls > Callable. Just as long as it as the user public API is the same it is fine. BTW, do we have a strategy so that users know what is public from what is not? What I am doing on my new projects is to include the keyword "internal" for non-public packages. For example: org.apache.cactus <-- public org.apache.cactus.server <-- public org.apache.cactus.internal <-- non public org.apache.cactus.internal.server <-- non public [...] [Note: I have taken this from Eclipse] The strategy is then that we are not allowed to break public APIs between subsequent releases. However items can be marked as deprecated and new API introduced. We then keep deprecated classes/methods for at least 2 releases and we are then free to remove it. However for internal classes, we are free to change the implementation whenever we want (of course provided the functional/acceptance tests still pass). > > If you just use the Mock class and the sugar methods it will be possible. Cool. I think I'm only using "terminal" APIs from DynaMock. > In my branch I renamed some of the classes and sugar methods so that they > follow a regular system of names -- I found that less confusing. I'm sure > we can use deprecated and overloaded methods to provide backwards > compatability here. > excellent. > For example, instead of "expect" I used "expectVoid" to expect a void > method. I used "expect" to expect a user-defined stub. That's fine, provided we mark the expect method as deprecated and not remove it for a while. Thanks -Vincent > > Regards, > Nat. > _______________________ > Dr. Nathaniel Pryce > B13media Ltd. > http://www.b13media.com > +44 (0)7712 526 661 > > ----- Original Message ----- > From: "Vincent Massol" <vm...@pi...> > To: "'Moc...@Li...'" > <moc...@li...> > Sent: Thursday, July 03, 2003 9:36 AM > Subject: RE: [MO-java-dev] dynamic branch and merge > > > > Is this going to break the DynaMock API from released version 0.09? > > > > In any case I believe we should absolutely provide backward > > compatibility and mark changed methods as deprecated. All new public > > methods should also be tagged with the "@since" javadoc tag. > > > > Thank you > > -Vincent > > > > > -----Original Message----- > > > From: moc...@li... > > > [mailto:moc...@li...] On Behalf Of > > > Steve Freeman > > > Sent: 03 July 2003 01:25 > > > To: moc...@li... > > > Subject: [MO-java-dev] dynamic branch and merge > > > > > > folks, given that some people aren't totally happy with nat's branch, > > > how about we start implementing the few bits we agree on in the HEAD? > > > For example, adding the ActiveCall object. That way we can make /some/ > > > progress and the merge will be less painful. > > > > > > S. > > > > > > > > > > > > > > > ------------------------------------------------------- > > > This SF.Net email sponsored by: Free pre-built ASP.NET sites including > > > Data Reports, E-commerce, Portals, and Forums are available now. > > > Download today and enter to win an XBOX or Visual Studio .NET. > > > > > http://aspnet.click-url.com/go/psa00100006ave/direct;at.asp_061203_01/01 > > > _______________________________________________ > > > Mockobjects-java-dev mailing list > > > Moc...@li... > > > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev > > > > > > > > ------------------------------------------------------- > > This SF.Net email sponsored by: Free pre-built ASP.NET sites including > > Data Reports, E-commerce, Portals, and Forums are available now. > > Download today and enter to win an XBOX or Visual Studio .NET. > > http://aspnet.click-url.com/go/psa00100006ave/direct;at.asp_061203_01/01 > > _______________________________________________ > > Mockobjects-java-dev mailing list > > Moc...@li... > > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev |
From: Nat P. <nat...@b1...> - 2003-07-03 10:20:32
|
I think it will be very hard to provide complete backwards compatability. Changing the dynamock library to use the ActiveCall class will change the Callable method, and thereby change every class that implements or calls Callable. If you just use the Mock class and the sugar methods it will be possible. In my branch I renamed some of the classes and sugar methods so that they follow a regular system of names -- I found that less confusing. I'm sure we can use deprecated and overloaded methods to provide backwards compatability here. For example, instead of "expect" I used "expectVoid" to expect a void method. I used "expect" to expect a user-defined stub. Regards, Nat. _______________________ Dr. Nathaniel Pryce B13media Ltd. http://www.b13media.com +44 (0)7712 526 661 ----- Original Message ----- From: "Vincent Massol" <vm...@pi...> To: "'Moc...@Li...'" <moc...@li...> Sent: Thursday, July 03, 2003 9:36 AM Subject: RE: [MO-java-dev] dynamic branch and merge > Is this going to break the DynaMock API from released version 0.09? > > In any case I believe we should absolutely provide backward > compatibility and mark changed methods as deprecated. All new public > methods should also be tagged with the "@since" javadoc tag. > > Thank you > -Vincent > > > -----Original Message----- > > From: moc...@li... > > [mailto:moc...@li...] On Behalf Of > > Steve Freeman > > Sent: 03 July 2003 01:25 > > To: moc...@li... > > Subject: [MO-java-dev] dynamic branch and merge > > > > folks, given that some people aren't totally happy with nat's branch, > > how about we start implementing the few bits we agree on in the HEAD? > > For example, adding the ActiveCall object. That way we can make /some/ > > progress and the merge will be less painful. > > > > S. > > > > > > > > > > ------------------------------------------------------- > > This SF.Net email sponsored by: Free pre-built ASP.NET sites including > > Data Reports, E-commerce, Portals, and Forums are available now. > > Download today and enter to win an XBOX or Visual Studio .NET. > > > http://aspnet.click-url.com/go/psa00100006ave/direct;at.asp_061203_01/01 > > _______________________________________________ > > Mockobjects-java-dev mailing list > > Moc...@li... > > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev > > > > ------------------------------------------------------- > This SF.Net email sponsored by: Free pre-built ASP.NET sites including > Data Reports, E-commerce, Portals, and Forums are available now. > Download today and enter to win an XBOX or Visual Studio .NET. > http://aspnet.click-url.com/go/psa00100006ave/direct;at.asp_061203_01/01 > _______________________________________________ > Mockobjects-java-dev mailing list > Moc...@li... > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev |
From: Nat P. <nat...@b1...> - 2003-07-03 10:16:04
|
> > From: "Steve Freeman" <st...@m3...> > >>I'm not so keen on the newSequence() > >>because it doesn't make clear what happens to expectations applied to > >>the originating Mock. At least the OrderedMock has only one visible > >>behaviour. > > Could this be fixed by a better name? > > not sure. it's more about 2 interfaces to the same behaviour. Not if we get rid of the OrderedMock class as I am suggesting. I think this will just make things a lot simpler. All Mocks are unordered. If you want to set up an expectation on the order of certain calls, create a CallSequence and add it to the mock, or use the newSequence sugar method. That would also disallow confusing code such as: private Mock mock; // This looks like it is declaring an unordered mock ... pubic void setUp() { mock = new OrderedMock( Interface.class ); // No it is actually an ordered mock. } Cheers, Nat. |
From: Vincent M. <vm...@pi...> - 2003-07-03 08:38:03
|
Is this going to break the DynaMock API from released version 0.09? In any case I believe we should absolutely provide backward compatibility and mark changed methods as deprecated. All new public methods should also be tagged with the "@since" javadoc tag. Thank you -Vincent > -----Original Message----- > From: moc...@li... > [mailto:moc...@li...] On Behalf Of > Steve Freeman > Sent: 03 July 2003 01:25 > To: moc...@li... > Subject: [MO-java-dev] dynamic branch and merge > > folks, given that some people aren't totally happy with nat's branch, > how about we start implementing the few bits we agree on in the HEAD? > For example, adding the ActiveCall object. That way we can make /some/ > progress and the merge will be less painful. > > S. > > > > > ------------------------------------------------------- > This SF.Net email sponsored by: Free pre-built ASP.NET sites including > Data Reports, E-commerce, Portals, and Forums are available now. > Download today and enter to win an XBOX or Visual Studio .NET. > http://aspnet.click-url.com/go/psa00100006ave/direct;at.asp_061203_01/01 > _______________________________________________ > Mockobjects-java-dev mailing list > Moc...@li... > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev |
From: Steve F. <st...@m3...> - 2003-07-03 07:47:29
|
Nat Pryce wrote: > From: "Steve Freeman" <st...@m3...> >>We argued this one out and thought that in most case people either care >>about the order or they don't. > It seems that there are always some methods that can occur out of order > (toString, etc.). if they matter, then put them in the expectations (this is another motivation for restructuring the special cases). >>I'm not so keen on the newSequence() >>because it doesn't make clear what happens to expectations applied to >>the originating Mock. At least the OrderedMock has only one visible >>behaviour. > Could this be fixed by a better name? not sure. it's more about 2 interfaces to the same behaviour. >>We also considered adding something like: >> listener.expectVoid( "first", C.before("second") ); > This gets tricky because you need to unambiguously identify the first and > second methods, and that gets difficult with the flexible way that methods > are matched using decorators. I find that putting callable objects into > sequences makes this explicit and is not very verbose. I suspect that simple name matching would work in practice. We also talked about adding a before() method to the callable objects, which would be unambiguous, but I couldn't be bothered to type in the example... 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. <st...@m3...> - 2003-07-02 23:25:02
|
folks, given that some people aren't totally happy with nat's branch, how about we start implementing the few bits we agree on in the HEAD? For example, adding the ActiveCall object. That way we can make /some/ progress and the merge will be less painful. S. |
From: Nat P. <nat...@b1...> - 2003-07-02 22:56:59
|
From: "Steve Freeman" <st...@m3...> > We argued this one out and thought that in most case people either care > about the order or they don't. It seems that there are always some methods that can occur out of order (toString, etc.). > I'm not so keen on the newSequence() > because it doesn't make clear what happens to expectations applied to > the originating Mock. At least the OrderedMock has only one visible > behaviour. Could this be fixed by a better name? > We also considered adding something like: > listener.expectVoid( "first", C.before("second") ); This gets tricky because you need to unambiguously identify the first and second methods, and that gets difficult with the flexible way that methods are matched using decorators. I find that putting callable objects into sequences makes this explicit and is not very verbose. Cheers, Nat. _______________________ Dr. Nathaniel Pryce B13media Ltd. http://www.b13media.com +44 (0)7712 526 661 |
From: Steve F. <st...@m3...> - 2003-07-02 22:14:00
|
We argued this one out and thought that in most case people either care about the order or they don't. I'm not so keen on the newSequence() because it doesn't make clear what happens to expectations applied to the originating Mock. At least the OrderedMock has only one visible behaviour. We also considered adding something like: listener.expectVoid( "first", C.before("second") ); S. Nat Pryce wrote: > Thinking about this, perhaps the whole idea of an OrderedMock is wrong. It > seems that there are no cases where *all* method calls will happen in one > order. Testing explicitly ordered calls is pretty rare, rare enough that > having to write an extra line of code to create a CallSequence to specify > the expected sequence of calls is not really a big problem. > > E.g. instead of: > > OrderedMock listener = new OrderedMock(EventListener.class); > listener.expectVoid( "firstEvent", C.eq(firstEvent) ); > listener.expectVoid( "secondEvent", C.eq(secondEvent) ); > listener.expectVoid( "thirdEvent", C.eq(thirdEvent) ); > > A test would look like: > > Mock listener = new Mock(EventListener.class); > CallCollectionBuilder eventSequence = listener.newSequence(); > eventSequence.expectVoid( "firstEvent", C.eq(firstEvent) ); > eventSequence.expectVoid( "secondEvent", C.eq(secondEvent) ); > eventSequence.expectVoid( "thirdEvent", C.eq(thirdEvent) ); > > I can live with that. I even think that it makes the test more readable. > > Regards, > Nat. > _______________________ > Dr. Nathaniel Pryce > B13media Ltd. > http://www.b13media.com > +44 (0)7712 526 661 > |
From: Nat P. <nat...@b1...> - 2003-07-02 15:13:04
|
From: "Nat Pryce" <nat...@b1...> > I think the proposed solution is very neat, and could probably also be used > to move the checks for and processing of "magic" calls from the Mock class > into Callable objects. > > However, how would it work with the OrderedMock class? Thinking about this, perhaps the whole idea of an OrderedMock is wrong. It seems that there are no cases where *all* method calls will happen in one order. Testing explicitly ordered calls is pretty rare, rare enough that having to write an extra line of code to create a CallSequence to specify the expected sequence of calls is not really a big problem. E.g. instead of: OrderedMock listener = new OrderedMock(EventListener.class); listener.expectVoid( "firstEvent", C.eq(firstEvent) ); listener.expectVoid( "secondEvent", C.eq(secondEvent) ); listener.expectVoid( "thirdEvent", C.eq(thirdEvent) ); A test would look like: Mock listener = new Mock(EventListener.class); CallCollectionBuilder eventSequence = listener.newSequence(); eventSequence.expectVoid( "firstEvent", C.eq(firstEvent) ); eventSequence.expectVoid( "secondEvent", C.eq(secondEvent) ); eventSequence.expectVoid( "thirdEvent", C.eq(thirdEvent) ); I can live with that. I even think that it makes the test more readable. Regards, Nat. _______________________ Dr. Nathaniel Pryce B13media Ltd. http://www.b13media.com +44 (0)7712 526 661 |
From: <st...@m3...> - 2003-07-02 09:35:49
|
> How about NOT using the call factory to create the decorator chains for > toString in the constructor. Instead, create them explicitly with the new > operator. >=20 > The CallFactory was created so that we could test how the Mock constructed > objects in response to other calls. If we have Tim's unit tests for > toString then we don't need to use the CallFactory to test the mocking of > toString in the constructor. >=20 > Does that make sense? But then we would have two mechanisms for creating calls. One with the fact= ory and one without. That doesn't sound right to me. |