From: Barry K. <bk...@in...> - 2003-05-14 15:09:12
|
I had a need for a CallBag, except I do not want to limit the number of calls. Mainly to support getters. Below is what I did. Is there another way? If not, could this be incorporated into the dynamic package? Notice that I had to override the field 'numcalls'. This is smelly. But I could not see any other way. And I'm not too happy about the class name. Also, I noticed that the comments in CallBag that the class was temporary, and would be pushed-up into CallSequence. If that is the case, I would like to see the ability to support unspecified number of calls. (Isn't there other support for unspecified number of calls in the Mock class?) ---- package mockobjects; import com.mockobjects.dynamic.CallCollection; import com.mockobjects.dynamic.MockCall; public class CallSet extends CallCollection { private int numCalls = 0; public Object call(Object[] args) throws Throwable { numCalls++; int callIndex = findCallIndexAndCheckArguments(args, numCalls); MockCall call = (MockCall)_expected_calls.get(callIndex); _hasBeenCalled.add(callIndex, Boolean.TRUE); return call.call(args); } protected int findCallIndexAndCheckArguments( Object[] args, int callNumber) { for (int i = 0; i < _expected_constraints.size(); i++) { if (checkArguments(i, args)) { return i; } } fail(errorMessage(args)); return -1; } public void verify() { assertTrue(errorMessage( null), _expected_calls.size() <= numCalls); } } ---- |
From: Tim M. <tim...@po...> - 2003-05-14 23:10:02
|
Barry - Is this a question about the current head version vs. the branch version? The new branch doesn't support this but its easy to add. ExpectedCall should be copied (or subclassed not sure which) to CallAtLeastOnce and the method matches reimplmented (e.g. return delegate.matches( methodName, args ); (When we get into the head version, ExpectedCall should be renamed to CallOnlyOnce). Subclass DefaultCallFactory and override createExpectedCall to return your CallAtLeastOnce. Create a Mock with the new factory (or subclass and have RelaxedMock the specifies the factory). tim > -----Original Message----- > From: moc...@li... > [mailto:moc...@li...]On Behalf Of > Barry Kaplan > Sent: 14 May 2003 16:09 > To: mockobjects > Subject: [MO-java-dev] dynamic.CallBag which allows any number of calls > > > I had a need for a CallBag, except I do not want to limit the number of > calls. Mainly to support getters. Below is what I did. Is there another > way? If not, could this be incorporated into the dynamic package? > > Notice that I had to override the field 'numcalls'. This is smelly. But > I could not see any other way. And I'm not too happy about the class name. > > Also, I noticed that the comments in CallBag that the class was > temporary, and would be pushed-up into CallSequence. If that is the > case, I would like to see the ability to support unspecified number of > calls. > > (Isn't there other support for unspecified number of calls in the Mock > class?) > > > ---- > package mockobjects; > > import com.mockobjects.dynamic.CallCollection; > import com.mockobjects.dynamic.MockCall; > > public class CallSet extends CallCollection { > > private int numCalls = 0; > > public Object call(Object[] args) throws Throwable { > numCalls++; > int callIndex = findCallIndexAndCheckArguments(args, numCalls); > MockCall call = (MockCall)_expected_calls.get(callIndex); > _hasBeenCalled.add(callIndex, Boolean.TRUE); > return call.call(args); > } > > protected int findCallIndexAndCheckArguments( > Object[] args, int callNumber) { > for (int i = 0; i < _expected_constraints.size(); i++) { > if (checkArguments(i, args)) { > return i; > } > } > fail(errorMessage(args)); > return -1; > } > > public void verify() { > assertTrue(errorMessage( > null), _expected_calls.size() <= numCalls); > } > } > ---- > > > > > ------------------------------------------------------- > Enterprise Linux Forum Conference & Expo, June 4-6, 2003, Santa Clara > The only event dedicated to issues related to Linux enterprise solutions > www.enterpriselinuxforum.com > > _______________________________________________ > 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.476 / Virus Database: 273 - Release Date: 24/04/2003 > --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.476 / Virus Database: 273 - Release Date: 24/04/2003 |
From: Barry K. <bk...@in...> - 2003-05-15 16:27:25
|
Tim Mackinnon wrote: > Barry - > > Is this a question about the current head version vs. the branch version? Head from 30 April. > The new branch doesn't support this but its easy to add. ExpectedCall should > be copied (or subclassed not sure which) to CallAtLeastOnce and the method > matches reimplmented (e.g. return delegate.matches( methodName, args ); > (When we get into the head version, ExpectedCall should be renamed to > CallOnlyOnce). Subclass DefaultCallFactory and override createExpectedCall > to return your CallAtLeastOnce. Create a Mock with the new factory (or > subclass and have RelaxedMock the specifies the factory). Hmm. I'll have to look at the branch. What is its state? Usable? Stable? -bk |