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: Barry K. <bk...@in...> - 2002-11-17 23:10:35
|
When should expectCall vs setupCall be used? Seems the only differnce is that setupCall creates a new ExpectationValue (overriding the existing instance), were expectCall sets the value of the existing instace. -bk ---- private ExpectationValue wasCalled; public MethodExpectation(String aName) { name = aName; initializeWasCalled(); } public void expectCall(MockCall aCall) { mockCall = aCall; wasCalled.setExpected(true); } public void setupCall(MockCall aCall) { mockCall = aCall; initializeWasCalled(); } private void initializeWasCalled() { wasCalled = new ExpectationValue(name + " was called"); } |
From: Steve F. <st...@m3...> - 2002-11-17 10:51:12
|
Thanks for your proposal in another message. You might also consider combining the dynamic mock with a hand-rolled mock using the ExpectationSet, e.g. public void MockFoo extends Mock { ExpectationSet values = new ExpectationSet("values); public void addValue(Value aValue) { // override values.addActual(aValue); } public void verify() { super.verify(); values.verify(); } } The hand-coded addValue() method will be picked up before the dynamic implementation. S. Barry Kaplan wrote: > I'm trying to test methods that create sums by invoking other methods. I > can setup the other methods correctly, but the setup of the mock method > calls is always sensitive to the order in which they are called. For the > method under test, this is not a requirement. Is there any mechanism for > setting up a CallSequence to not care about the order, but still ensure > that the total number of calls were made and the parameters were > correct. (I suppose it might have to give each method a shot, and only > fail if all fail to verify?) |
From: Steve F. <st...@m3...> - 2002-11-17 10:18:12
|
The problem is with new Object[]{foo, bar}, which is being interpreted as a single object and checked for equality. If you want to match two parameters, you need new Predicate{} { IsEqual(foo), IsEqual(bar) }. Or, alternatively, P.args(P.eq(foo), P.eq(bar)). S. Barry Kaplan wrote: > AbstractMockCall.checkArguments() always seem to say the number of > arguments is wrong. Consider the following code snippets: > > ---- > public interface PositionMemento { > int getQuantity(Object foo, Object bar); > } > > private Mock mock = new Mock(PositionMemento.class); > private PositionMemento mockProxy = (PositionMemento) mock.proxy(); > mock.expectAndReturn("getQuantity", new Object[]{foo, bar}, new > Integer(1)); > int q = mockProxy.getQuantity(foo, bar); > ---- > > The AbstractMockCall.getArgumentsCounts() checks the length of > '_expected_args'. But this object always seems to be a Constraint (an > and constraint containing the two method parameter objects), with a > length of 1. But the 'args' parameter is an array of the actual args > (ie, foo and bar) with a length of 2. Thus checkArguments() always fails. > > Any clues? Is this a known problem. > thanks! > > (BTW, I tried running the junit task from my CVS checkout to see if > maybe mockobjects was broke, but that seemed to do nothing. I also tried > to search the mailing list, but alas there are not archives.) > > > > > > > > ------------------------------------------------------- > This sf.net email is sponsored by: To learn the basics of securing your > web site with SSL, click here to get a FREE TRIAL of a Thawte Server > Certificate: http://www.gothawte.com/rd524.html > _______________________________________________ > Mockobjects-java-dev mailing list > Moc...@li... > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev |
From: Barry K. <bk...@in...> - 2002-11-17 02:42:49
|
I hacked together a class that did just the minimal amount I needed. Most of the code below is because of the inability to extend the CallSequence and the package scope of MockReturnCall. If this behavior were to be integrated in to CallSequence it only take a setting to indicate that order is unimportant, and an alternate implementation of the call() method (like the one below). If I made these patches to CallSequence, would someone commit them? Or should I create a completly seperate class (eg, CallSet)? If the latter, a base for the two would be called for as they code will 95% the same. ----------- private static class CallSet extends AssertMo implements MockCall, Verifiable { //extends CallSequence { private List expectedCalls = new ArrayList(); private int nextIndex = 0; // This is was copied from the mockobjects because it was package scope. static class MockReturnCall_x extends AbstractMockCall { private Object result; public MockReturnCall_x(Constraint[] expectedArgs, Object result) { super(expectedArgs); this.result = result; } public Object call(Object[] args) throws Throwable { super.call(args); return result; } } public void expectReturn(Constraint[] args, Object result) { MockReturnCall_x mockCall = new MockReturnCall_x(args, result); expectedCalls.add(mockCall); } public Object call(Object[] args) throws Throwable { Throwable resultThrowable = null; Object result = null; for (Iterator iterator = expectedCalls.iterator(); iterator.hasNext();) { MockReturnCall_x mockCall = (MockReturnCall_x) iterator.next(); try { result = mockCall.call(args); nextIndex++; resultThrowable = null; break; } catch (Throwable t) { resultThrowable = t; } } if (resultThrowable != null) { throw resultThrowable; } if (nextIndex > expectedCalls.size()) { fail("too many calls: expected=" + expectedCalls.size() + ", actual=" + nextIndex); } return result; } public void verify() { if (nextIndex < expectedCalls.size()) { fail("too few calls: expected=" + expectedCalls.size() + ", actual=" + nextIndex); } } } |
From: Barry K. <bk...@in...> - 2002-11-17 01:46:57
|
Hmm, I started writing an UnorderedCallSequence class, but hit a roadblock when I found that the MockCall concrete classes are package scope. Is that necessary? |
From: Barry K. <bk...@in...> - 2002-11-17 01:39:33
|
I'm trying to test methods that create sums by invoking other methods. I can setup the other methods correctly, but the setup of the mock method calls is always sensitive to the order in which they are called. For the method under test, this is not a requirement. Is there any mechanism for setting up a CallSequence to not care about the order, but still ensure that the total number of calls were made and the parameters were correct. (I suppose it might have to give each method a shot, and only fail if all fail to verify?) thanks! |
From: Barry K. <bk...@in...> - 2002-11-17 01:35:40
|
Ok, figured out what I was doing wrong. I needed pass in an array of Constraints, not an array of the parameters directly. |
From: Barry K. <bk...@in...> - 2002-11-17 01:11:43
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"> <title></title> </head> <body> <div class="moz-text-flowed" style="font-family: -moz-fixed; font-size: 13px;" lang="x-western">AbstractMockCall.checkArguments() always seem to say the number of arguments is wrong. Consider the following code snippets:<br> <br> ----<br> public interface PositionMemento {<br> int getQuantity(Object foo, Object bar);<br> }<br> <br> private Mock mock = new Mock(PositionMemento.class);<br> private PositionMemento mockProxy = (PositionMemento) mock.proxy();<br> mock.expectAndReturn("getQuantity", new Object[]{foo, bar}, new Integer(1)); <br> int q = mockProxy.getQuantity(foo, bar);<br> ----<br> <br> The AbstractMockCall.getArgumentsCounts() checks the length of '_expected_args'. But this object always seems to be a Constraint (an and constraint containing the two method parameter objects), with a length of 1. But the 'args' parameter is an array of the actual args (ie, foo and bar) with a length of 2. Thus checkArguments() always fails.<br> <br> Any clues? Is this a known problem.<br> thanks!<br> <br> (BTW, I tried running the junit task from my CVS checkout to see if maybe mockobjects was broke, but that seemed to do nothing. I also tried to search the mailing list, but alas there are not archives.)<br> <br> </div> </body> </html> |
From: Barry K. <bk...@in...> - 2002-11-17 01:11:08
|
Wrong reply. I'll repost at the top level. Sorry. |
From: Barry K. <bk...@in...> - 2002-11-17 00:51:31
|
AbstractMockCall.checkArguments() always seem to say the number of arguments is wrong. Consider the following code snippets: ---- public interface PositionMemento { int getQuantity(Object foo, Object bar); } private Mock mock = new Mock(PositionMemento.class); private PositionMemento mockProxy = (PositionMemento) mock.proxy(); mock.expectAndReturn("getQuantity", new Object[]{foo, bar}, new Integer(1)); int q = mockProxy.getQuantity(foo, bar); ---- The AbstractMockCall.getArgumentsCounts() checks the length of '_expected_args'. But this object always seems to be a Constraint (an and constraint containing the two method parameter objects), with a length of 1. But the 'args' parameter is an array of the actual args (ie, foo and bar) with a length of 2. Thus checkArguments() always fails. Any clues? Is this a known problem. thanks! (BTW, I tried running the junit task from my CVS checkout to see if maybe mockobjects was broke, but that seemed to do nothing. I also tried to search the mailing list, but alas there are not archives.) |
From: Jeff M. <je...@mk...> - 2002-11-15 13:45:27
|
So far it's between me and Steve, but all you have to do is go into doc/html and change the relevant bits and then run the deploy-site target in site.xml On Fri, 2002-11-15 at 12:06, Nat Pryce wrote: > Hi. Who maintains the mockobjects.com website? I've written an article > I'd like to add to the Papers and Articles page. Also the javadoc > linked from the main page is out of date. > > Cheers, > Nat. -- Jeff Martin <je...@mk...> mkodo |
From: Nat P. <nat...@b1...> - 2002-11-15 12:33:19
|
Hi. Who maintains the mockobjects.com website? I've written an article I'd like to add to the Papers and Articles page. Also the javadoc linked from the main page is out of date. Cheers, Nat. -- Nat Pryce <np...@so...> |
From: Nat P. <np...@us...> - 2002-11-12 17:43:12
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory usw-pr-cvs1:/tmp/cvs-serv11918/src/core/test/mockobjects/dynamic Modified Files: MockTest.java Removed Files: PredicatesTest.java Log Message: Renamed Predicate to Constraint Moved Constraint interface and classes to com.mockobjects.constraint Rewrote some Javadoc comments to reflect new terminology Index: MockTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockTest.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- MockTest.java 7 Nov 2002 17:45:03 -0000 1.7 +++ MockTest.java 12 Nov 2002 17:42:38 -0000 1.8 @@ -7,7 +7,9 @@ import java.lang.reflect.Method; import java.lang.reflect.Proxy; import junit.framework.AssertionFailedError; + import com.mockobjects.dynamic.*; +import com.mockobjects.constraint.*; import com.mockobjects.util.TestCaseMo; @@ -79,7 +81,7 @@ public void testObjectTypes() { _mock.expectAndReturn( "objectTypes", - new Predicate[] { new IsEqual( new Integer(1) ) }, + new Constraint[] { new IsEqual( new Integer(1) ) }, "1" ); assertEquals( "1", _interface.objectTypes( new Integer(1) ) ); @@ -88,7 +90,7 @@ public void testPrimitiveTypes() { _mock.expectAndReturn( "primitiveTypes", - new Predicate[] { new IsEqual( new Integer(2) ), + new Constraint[] { new IsEqual( new Integer(2) ), new IsEqual( new Integer(3) ) }, new Integer(6) ); @@ -110,7 +112,7 @@ public void testThrow() { _mock.expectAndThrow( "primitiveTypes", - new Predicate[] { new IsEqual( new Integer(2) ), + new Constraint[] { new IsEqual( new Integer(2) ), new IsEqual( new Integer(3) ) }, new ArithmeticException("message") ); @@ -230,10 +232,10 @@ } public void testWrongNumberOfArguments() { - Predicate p = new IsEqual( new Integer(2) ); - Predicate q = new IsAnything(); + Constraint p = new IsEqual( new Integer(2) ); + Constraint q = new IsAnything(); - _mock.expectAndReturn( "objectTypes", new Predicate[]{p,q}, "2" ); + _mock.expectAndReturn( "objectTypes", new Constraint[]{p,q}, "2" ); assertFails( "mock did not fail when wrong number of arguments passed", new Runnable() { @@ -242,9 +244,9 @@ } public void testArgumentsPassedToNoArgMethod() { - Predicate p = new IsAnything(); + Constraint p = new IsAnything(); - _mock.expectVoid( "voidMethod", new Predicate[]{p} ); + _mock.expectVoid( "voidMethod", new Constraint[]{p} ); try { _interface.voidMethod(); @@ -257,9 +259,9 @@ } public void testPredicateFailure() { - Predicate p = new IsEqual( new Integer(2) ); + Constraint p = new IsEqual( new Integer(2) ); - _mock.expectAndReturn( "objectTypes", new Predicate[]{p}, "2" ); + _mock.expectAndReturn( "objectTypes", new Constraint[]{p}, "2" ); assertTrue( !p.eval( new Integer(1) ) ); try { @@ -551,7 +553,7 @@ mock ); mock.expectAndReturn( "objectTypes", - new Predicate[] { new IsAnything() }, + new Constraint[] { new IsAnything() }, "result" ); assertEquals( "result", i.objectTypes( new Integer(1) ) ); --- PredicatesTest.java DELETED --- |
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory usw-pr-cvs1:/tmp/cvs-serv11918/src/core/com/mockobjects/dynamic Modified Files: P.java MockVoidCall.java MockThrowCall.java Mock.java AbstractMockCall.java MockReturnCall.java CallSequence.java Removed Files: IsLessThan.java IsCloseTo.java IsNot.java IsSame.java IsEqual.java IsNull.java And.java Or.java IsAnything.java IsInstanceOf.java IsGreaterThan.java Predicate.java IsEventFrom.java Log Message: Renamed Predicate to Constraint Moved Constraint interface and classes to com.mockobjects.constraint Rewrote some Javadoc comments to reflect new terminology Index: P.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/P.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- P.java 31 Oct 2002 17:03:45 -0000 1.4 +++ P.java 12 Nov 2002 17:42:36 -0000 1.5 @@ -4,7 +4,8 @@ */ package com.mockobjects.dynamic; -import com.mockobjects.dynamic.*; +import com.mockobjects.constraint.*; + /** Convenient factory functions and constants for building predicates. */ @@ -12,99 +13,99 @@ { public static final IsAnything IS_ANYTHING = new IsAnything(); public static final IsNull IS_NULL = new IsNull(); - public static final Predicate IS_NOT_NULL = not(IS_NULL); - public static final Predicate IS_TRUE = new IsEqual(new Boolean(true)); - public static final Predicate IS_FALSE = eq(new Boolean(false)); - public static final Predicate IS_ZERO = eq(new Integer(0)); - public static final Predicate IS_NOT_ZERO = not(IS_ZERO); + public static final Constraint IS_NOT_NULL = not(IS_NULL); + public static final Constraint IS_TRUE = eq(new Boolean(true)); + public static final Constraint IS_FALSE = eq(new Boolean(false)); + public static final Constraint IS_ZERO = eq(new Integer(0)); + public static final Constraint IS_NOT_ZERO = not(IS_ZERO); - public static final Predicate[] ANY_ARGS = MockVoidCall.ANY_ARGS; + public static final Constraint[] ANY_ARGS = MockVoidCall.ANY_ARGS; - public static Predicate same( Object o ) { + public static Constraint same( Object o ) { return new IsSame(o); } - public static Predicate eq( Object o ) { + public static Constraint eq( Object o ) { return new IsEqual(o); } - public static Predicate eq( int n ) { + public static Constraint eq( int n ) { return new IsEqual( new Integer(n) ); } - public static Predicate eq( long l ) { + public static Constraint eq( long l ) { return new IsEqual( new Long(l) ); } - public static Predicate eq( double d ) { + public static Constraint eq( double d ) { return new IsEqual( new Double(d) ); } - public static Predicate gt( int n ) { + public static Constraint gt( int n ) { return new IsGreaterThan( new Integer(n) ); } - public static Predicate gt( long l ) { + public static Constraint gt( long l ) { return new IsGreaterThan( new Long(l) ); } - public static Predicate gt( double d ) { + public static Constraint gt( double d ) { return new IsGreaterThan( new Double(d) ); } - public static Predicate gt( char c ) { + public static Constraint gt( char c ) { return new IsGreaterThan( new Character(c) ); } - public static Predicate lt( int n ) { + public static Constraint lt( int n ) { return new IsLessThan( new Integer(n) ); } - public static Predicate lt( long l ) { + public static Constraint lt( long l ) { return new IsLessThan( new Long(l) ); } - public static Predicate lt( double d ) { + public static Constraint lt( double d ) { return new IsLessThan( new Double(d) ); } - public static Predicate lt( char c ) { + public static Constraint lt( char c ) { return new IsLessThan( new Character(c) ); } - public static Predicate not( Predicate p ) { + public static Constraint not( Constraint p ) { return new IsNot(p); } - public static Predicate and( Predicate p1, Predicate p2 ) { + public static Constraint and( Constraint p1, Constraint p2 ) { return new And(p1,p2); } - public static Predicate or( Predicate p1, Predicate p2 ) { + public static Constraint or( Constraint p1, Constraint p2 ) { return new Or(p1,p2); } - public static Predicate isA( Class c ) { + public static Constraint isA( Class c ) { return new IsInstanceOf(c); } - /* Helper methods for succinctly constructing Predicate arrays + /* Helper methods for succinctly constructing Constraint arrays */ - public static Predicate[] args() { + public static Constraint[] args() { return Mock.NO_ARGS; } - public static Predicate[] args(Predicate p) { - return new Predicate[] {p}; + public static Constraint[] args(Constraint p) { + return new Constraint[] {p}; } - public static Predicate[] args(Predicate p1, Predicate p2) { - return new Predicate[] {p1, p2}; + public static Constraint[] args(Constraint p1, Constraint p2) { + return new Constraint[] {p1, p2}; } - public static Predicate[] args(Predicate p1, Predicate p2, Predicate p3) { - return new Predicate[] {p1, p2, p3}; + public static Constraint[] args(Constraint p1, Constraint p2, Constraint p3) { + return new Constraint[] {p1, p2, p3}; } } Index: MockVoidCall.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/MockVoidCall.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- MockVoidCall.java 7 Nov 2002 17:45:06 -0000 1.4 +++ MockVoidCall.java 12 Nov 2002 17:42:36 -0000 1.5 @@ -4,6 +4,8 @@ */ package com.mockobjects.dynamic; +import com.mockobjects.constraint.*; + /** A mocked call to a method of that has a void result. */ @@ -21,7 +23,7 @@ * @param expected_args * Predicates that define the valid arguments of the method. */ - public MockVoidCall( Predicate[] expected_args ) { + public MockVoidCall( Constraint[] expected_args ) { super( expected_args ); } Index: MockThrowCall.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/MockThrowCall.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- MockThrowCall.java 7 Nov 2002 17:45:06 -0000 1.3 +++ MockThrowCall.java 12 Nov 2002 17:42:37 -0000 1.4 @@ -4,7 +4,7 @@ */ package com.mockobjects.dynamic; -import com.mockobjects.dynamic.MockVoidCall; +import com.mockobjects.constraint.*; /** A mocked call to a method that results in a thrown exception. */ @@ -32,7 +32,7 @@ * The exception or error that will be thrown when this method * is called. */ - public MockThrowCall( Predicate[] expected_args, + public MockThrowCall( Constraint[] expected_args, Throwable exception ) { super( expected_args ); Index: Mock.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Mock.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- Mock.java 11 Nov 2002 16:20:34 -0000 1.14 +++ Mock.java 12 Nov 2002 17:42:37 -0000 1.15 @@ -5,6 +5,8 @@ package com.mockobjects.dynamic; import com.mockobjects.Verifiable; +import com.mockobjects.constraint.*; + import junit.framework.Assert; import junit.framework.AssertionFailedError; @@ -26,7 +28,7 @@ /** A convenient constant for defining expectations for methods that * have no methods. */ - public static final Predicate[] NO_ARGS = new Predicate[0]; + public static final Constraint[] NO_ARGS = new Constraint[0]; private Class[] _proxy_classes; @@ -188,7 +190,7 @@ * @param method * The name of the method that will be called. * @param args - * An array of {@link com.mockobjects.dynamic.Predicate}s that specify the + * An array of {@link com.mockobjects.dynamic.Constraint}s that specify the * epxected arguments of the method call. The length of the array defines * the expected arity of the method call. * @param result @@ -199,7 +201,7 @@ * The method name is not the name of a method mocked by this * Mock object. */ - public void expectAndReturn( String method, Predicate[] args, Object result ) { + public void expectAndReturn( String method, Constraint[] args, Object result ) { expect( method, new MockReturnCall( args, result ) ); } @@ -243,14 +245,14 @@ * @param method * The name of the method that will be called. * @param args - * An array of {@link com.mockobjects.dynamic.Predicate}s that specify the + * An array of {@link com.mockobjects.dynamic.Constraint}s that specify the * epxected arguments of the method call. The length of the array defines * the expected arity of the method call. * @throws junit.framework.AssertionFailedError * The method name is not the name of a method mocked by this * Mock object. */ - public void expectVoid( String method, Predicate[] args ) { + public void expectVoid( String method, Constraint[] args ) { expect( method, new MockVoidCall( args ) ); } @@ -287,7 +289,7 @@ * @param method * The name of the method that will be called. * @param args - * An array of {@link com.mockobjects.dynamic.Predicate}s that specify the + * An array of {@link com.mockobjects.dynamic.Constraint}s that specify the * epxected arguments of the method call. The length of the array defines * the expected arity of the method call. * @param exception @@ -296,7 +298,7 @@ * The method name is not the name of a method mocked by this * Mock object. */ - public void expectAndThrow( String method, Predicate[] args, Throwable exception ) { + public void expectAndThrow( String method, Constraint[] args, Throwable exception ) { expect( method, new MockThrowCall( args, exception ) ); } Index: AbstractMockCall.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/AbstractMockCall.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- AbstractMockCall.java 10 Nov 2002 10:55:08 -0000 1.3 +++ AbstractMockCall.java 12 Nov 2002 17:42:37 -0000 1.4 @@ -4,6 +4,8 @@ */ package com.mockobjects.dynamic; +import com.mockobjects.constraint.*; + /** An abstract mocked method call that checks its arguments against * expectations, but leaves the result of the call (returned value, @@ -17,10 +19,10 @@ * any arguments, that is, that the call does not check the arguments * passed to it. */ - static final Predicate[] ANY_ARGS = null; + static final Constraint[] ANY_ARGS = null; - private Predicate[] _expected_args; + private Constraint[] _expected_args; /** Constructs an <code>AbstractMockCall</code> that accepts any arguments. @@ -34,7 +36,7 @@ * @param expected_args * Predicates that define the valid arguments of the method. */ - public AbstractMockCall( Predicate[] expected_args ) { + public AbstractMockCall( Constraint[] expected_args ) { _expected_args = expected_args; } @@ -66,7 +68,7 @@ return _expected_args.length; } - private void checkArgument( int i, Predicate expectedArg, Object arg ) { + private void checkArgument( int i, Constraint expectedArg, Object arg ) { assertTrue( "argument " + (i+1) + "\n" + "expected " + expectedArg + "\n" + " was " + arg + "", Index: MockReturnCall.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/MockReturnCall.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- MockReturnCall.java 7 Nov 2002 17:45:04 -0000 1.3 +++ MockReturnCall.java 12 Nov 2002 17:42:37 -0000 1.4 @@ -4,7 +4,7 @@ */ package com.mockobjects.dynamic; -import com.mockobjects.dynamic.MockVoidCall; +import com.mockobjects.constraint.*; /** An mocked call to a method that returns a result. @@ -30,7 +30,7 @@ * @param result * The value returned when the method is called. */ - public MockReturnCall( Predicate[] expected_args, Object result ) { + public MockReturnCall( Constraint[] expected_args, Object result ) { super( expected_args ); _result = result; } Index: CallSequence.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallSequence.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- CallSequence.java 1 Nov 2002 15:35:20 -0000 1.1 +++ CallSequence.java 12 Nov 2002 17:42:37 -0000 1.2 @@ -7,6 +7,7 @@ import java.util.List; import com.mockobjects.Verifiable; +import com.mockobjects.constraint.*; import com.mockobjects.util.AssertMo; @@ -36,7 +37,7 @@ /** Expect a method call and return a result when it is called. * * @param args - * An array of {@link com.mockobjects.dynamic.Predicate}s that specify the + * An array of {@link com.mockobjects.dynamic.Constraint}s that specify the * epxected arguments of the method call. The length of the array defines * the expected arity of the method call. * @param result @@ -44,7 +45,7 @@ * must be wrapped in the equivalent Java object, and will be unwrapped * before being returned to the caller of the method. */ - public void expectReturn( Predicate[] args, Object result ) { + public void expectReturn( Constraint[] args, Object result ) { expect( new MockReturnCall( args, result ) ); } @@ -75,11 +76,11 @@ /** Expect a call to a method with a void return type. * * @param args - * An array of {@link com.mockobjects.dynamic.Predicate}s that specify the + * An array of {@link com.mockobjects.dynamic.Constraint}s that specify the * epxected arguments of the method call. The length of the array defines * the expected arity of the method call. */ - public void expectVoid( Predicate[] args ) { + public void expectVoid( Constraint[] args ) { expect( new MockVoidCall( args ) ); } @@ -103,13 +104,13 @@ /** Expect a method call and throw an exception or error when it is called. * * @param args - * An array of {@link com.mockobjects.dynamic.Predicate}s that specify the + * An array of {@link com.mockobjects.dynamic.Constraint}s that specify the * epxected arguments of the method call. The length of the array defines * the expected arity of the method call. * @param exception * The exception or error that will be thrown as a result of this call. */ - public void expectThrow( Predicate[] args, Throwable exception ) { + public void expectThrow( Constraint[] args, Throwable exception ) { expect( new MockThrowCall( args, exception ) ); } --- IsLessThan.java DELETED --- --- IsCloseTo.java DELETED --- --- IsNot.java DELETED --- --- IsSame.java DELETED --- --- IsEqual.java DELETED --- --- IsNull.java DELETED --- --- And.java DELETED --- --- Or.java DELETED --- --- IsAnything.java DELETED --- --- IsInstanceOf.java DELETED --- --- IsGreaterThan.java DELETED --- --- Predicate.java DELETED --- --- IsEventFrom.java DELETED --- |
From: Nat P. <np...@us...> - 2002-11-12 17:42:46
|
Update of /cvsroot/mockobjects/mockobjects-java/src/jdk/1.4/test/mockobjects/constraint In directory usw-pr-cvs1:/tmp/cvs-serv11918/src/jdk/1.4/test/mockobjects/constraint Added Files: MatchesTest.java Log Message: Renamed Predicate to Constraint Moved Constraint interface and classes to com.mockobjects.constraint Rewrote some Javadoc comments to reflect new terminology --- NEW FILE: MatchesTest.java --- /* * Date: 21-Oct-2002 */ package test.mockobjects.constraint; import com.mockobjects.constraint.Constraint; import com.mockobjects.constraint.Matches; import junit.framework.TestCase; public class MatchesTest extends TestCase { public MatchesTest(String name) { super(name); } public void testMatches() { Constraint p = new Matches("^hello, (.*)\\.$"); assertTrue(p.eval("hello, world.")); assertTrue(p.eval("hello, mum.")); assertTrue(!p.eval("hello world.")); assertTrue(!p.eval("hello, world")); assertTrue(!p.eval("goodbye, world.")); } } |
From: Nat P. <np...@us...> - 2002-11-12 17:42:46
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/constraint In directory usw-pr-cvs1:/tmp/cvs-serv11918/src/core/test/mockobjects/constraint Added Files: ConstraintsTest.java Log Message: Renamed Predicate to Constraint Moved Constraint interface and classes to com.mockobjects.constraint Rewrote some Javadoc comments to reflect new terminology --- NEW FILE: ConstraintsTest.java --- /* Copyright (c) 2002 Nat Pryce. All rights reserved. * * Created on February 10, 2002, 11:24 PM */ package test.mockobjects.constraint; import com.mockobjects.constraint.*; import com.mockobjects.constraint.*; import java.util.EventObject; public class ConstraintsTest extends junit.framework.TestCase { class True implements Constraint { public boolean eval( Object o ) { return true; } } class False implements Constraint { public boolean eval( Object o ) { return false; } } /** Creates a new instance of Test_Predicates */ public ConstraintsTest( String test ) { super(test); } public void testIsNull() { Constraint p = new IsNull(); assertTrue( p.eval(null) ); assertTrue( !p.eval(new Object()) ); } public void testIsSame() { Object o1 = new Object(); Object o2 = new Object(); Constraint p = new IsSame(o1); assertTrue( p.eval(o1) ); assertTrue( !p.eval(o2) ); } public void testIsEqual() { Integer i1 = new Integer(1); Integer i2 = new Integer(2); Constraint p = new IsEqual(i1); assertTrue( p.eval(i1) ); assertTrue( p.eval( new Integer(1) ) ); assertTrue( !p.eval(i2) ); } public void testIsGreaterThan() { Constraint p = new IsGreaterThan( new Integer(1) ); assertTrue( !p.eval( new Integer(0) ) ); assertTrue( !p.eval( new Integer(1) ) ); assertTrue( p.eval( new Integer(2) ) ); } public void testIsLessThan() { Constraint p = new IsLessThan( new Integer(1) ); assertTrue( p.eval( new Integer(0) ) ); assertTrue( !p.eval( new Integer(1) ) ); assertTrue( !p.eval( new Integer(2) ) ); } public void testIsAnything() { Constraint p = new IsAnything(); assertTrue( p.eval(null) ); assertTrue( p.eval( new Object() ) ); } public void testIsInstanceOf() { Constraint p = new IsInstanceOf( Number.class ); assertTrue( p.eval( new Integer(1) ) ); assertTrue( p.eval( new Double(1.0) ) ); assertTrue( !p.eval("a string") ); assertTrue( !p.eval(null) ); } public void testIsNot() { Constraint p = new IsNot( new True() ); assertTrue( !p.eval(null) ); assertTrue( !p.eval( new Object() ) ); } public void testAnd() { Object o = new Object(); assertTrue( new And( new True(), new True() ).eval(o) ); assertTrue( !new And( new False(), new True() ).eval(o) ); assertTrue( !new And( new True(), new False() ).eval(o) ); assertTrue( !new And( new False(), new False() ).eval(o) ); } public void testOr() { Object o = new Object(); assertTrue( new Or( new True(), new True() ).eval(o) ); assertTrue( new Or( new False(), new True() ).eval(o) ); assertTrue( new Or( new True(), new False() ).eval(o) ); assertTrue( !new Or( new False(), new False() ).eval(o) ); } public void testIsEventFrom() { Object o = new Object(); EventObject ev = new EventObject(o); EventObject ev2 = new EventObject( new Object() ); Constraint p = new IsEventFrom(o); assertTrue( p.eval(ev) ); assertTrue( "p should eval to false for an event not from o", !p.eval(ev2) ); assertTrue( "p should eval to false for objects that are not events", !p.eval(o) ); } private static class DerivedEvent extends EventObject { public DerivedEvent( Object source ) { super(source); } } public void testIsEventSubtypeFrom() { Object o = new Object(); DerivedEvent good_ev = new DerivedEvent(o); DerivedEvent wrong_source = new DerivedEvent(new Object()); EventObject wrong_type = new EventObject(o); EventObject wrong_source_and_type = new EventObject(new Object()); Constraint p = new IsEventFrom( DerivedEvent.class, o ); assertTrue( p.eval(good_ev) ); assertTrue( "p should eval to false for an event not from o", !p.eval(wrong_source) ); assertTrue( "p should eval to false for an event of the wrong type", !p.eval(wrong_type) ); assertTrue( "p should eval to false for an event of the wrong type "+ "and from the wrong source", !p.eval(wrong_source_and_type) ); } public void testIsCloseTo() { Constraint p = new IsCloseTo( 1.0, 0.5 ); assertTrue( p.eval( new Double(1.0) ) ); assertTrue( p.eval( new Double(0.5) ) ); assertTrue( p.eval( new Double(1.5) ) ); assertTrue( p.eval( new Float(1.0) ) ); assertTrue( p.eval( new Integer(1) ) ); assertTrue( "number too large", !p.eval( new Double(2.0) ) ); assertTrue( "number too small", !p.eval( new Double(0.0) ) ); try { p.eval("wrong type"); fail("ClassCastException expected for wrong type of argument"); } catch( ClassCastException ex ) { // expected } } } |
From: Nat P. <np...@us...> - 2002-11-12 17:42:46
|
Update of /cvsroot/mockobjects/mockobjects-java/src/jdk/1.4/com/mockobjects/dynamic In directory usw-pr-cvs1:/tmp/cvs-serv11918/src/jdk/1.4/com/mockobjects/dynamic Removed Files: Matches.java Log Message: Renamed Predicate to Constraint Moved Constraint interface and classes to com.mockobjects.constraint Rewrote some Javadoc comments to reflect new terminology --- Matches.java DELETED --- |
From: Nat P. <np...@us...> - 2002-11-12 17:42:46
|
Update of /cvsroot/mockobjects/mockobjects-java/src/jdk/1.4/com/mockobjects/constraint In directory usw-pr-cvs1:/tmp/cvs-serv11918/src/jdk/1.4/com/mockobjects/constraint Added Files: Matches.java Log Message: Renamed Predicate to Constraint Moved Constraint interface and classes to com.mockobjects.constraint Rewrote some Javadoc comments to reflect new terminology --- NEW FILE: Matches.java --- /* Copyright (c) 2002 Nat Pryce. All rights reserved. * * Created on February 10, 2002, 11:35 PM */ package com.mockobjects.constraint; import java.util.regex.Matcher; import java.util.regex.Pattern; /** Is the value a string that matches a regular expression? */ public class Matches implements Constraint { private Pattern _pattern; private Matcher _matcher; /** Creates a new Matches predicate. * * @param regex * A regular expression string used to create a * {@link java.util.regex.Pattern}. The {@link #eval} method * returns true when applied to Strings that match this pattern. * Matching is tested by calling the * {@link java.util.regex.Matcher#matches} method of a * {@link java.util.regex.Matcher} object. */ public Matches( String regex ) { _pattern = Pattern.compile(regex); } public boolean eval( Object arg ) { if( arg instanceof String ) { Matcher matcher = _pattern.matcher((String)arg); return matcher.matches(); } else { return false; } } public String toString() { return "a string that matches <" + _pattern.toString() + ">"; } } |
From: Nat P. <np...@us...> - 2002-11-12 17:42:45
|
Update of /cvsroot/mockobjects/mockobjects-java/src/jdk/1.4/test/mockobjects In directory usw-pr-cvs1:/tmp/cvs-serv11918/src/jdk/1.4/test/mockobjects Removed Files: MatchesTest.java Log Message: Renamed Predicate to Constraint Moved Constraint interface and classes to com.mockobjects.constraint Rewrote some Javadoc comments to reflect new terminology --- MatchesTest.java DELETED --- |
From: Nat P. <np...@us...> - 2002-11-12 17:42:44
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/constraint In directory usw-pr-cvs1:/tmp/cvs-serv11918/src/core/com/mockobjects/constraint Added Files: IsNot.java IsCloseTo.java IsEqual.java IsLessThan.java And.java IsSame.java IsNull.java Constraint.java Or.java IsGreaterThan.java IsAnything.java IsEventFrom.java IsInstanceOf.java Log Message: Renamed Predicate to Constraint Moved Constraint interface and classes to com.mockobjects.constraint Rewrote some Javadoc comments to reflect new terminology --- NEW FILE: IsNot.java --- /* Copyright (c) 2002 Nat Pryce. All rights reserved. * * Created on February 10, 2002, 11:35 PM */ package com.mockobjects.constraint; /** Calculates the logical negation of a constraint. */ public class IsNot implements Constraint { private Constraint _predicate; public IsNot( Constraint p ) { _predicate = p; } public boolean eval( Object arg ) { return !_predicate.eval(arg); } public String toString() { return "not " + _predicate.toString(); } } --- NEW FILE: IsCloseTo.java --- /* Copyright (c) 2002 Nat Pryce. All rights reserved. * * Created on February 10, 2002, 11:35 PM */ package com.mockobjects.constraint; /** Is the value a number equal to a value within some range of * acceptable error? */ public class IsCloseTo implements Constraint { private double _error; private double _value; public IsCloseTo( double value, double error ) { _error = error; _value = value; } public boolean eval( Object arg ) { double arg_value = ((Number)arg).doubleValue(); return Math.abs( (arg_value - _value) ) <= _error; } public String toString() { return "a numeric value within " + _error + " of " + _value; } } --- NEW FILE: IsEqual.java --- /* Copyright (c) 2002 Nat Pryce. All rights reserved. * * Created on February 10, 2002, 11:35 PM */ package com.mockobjects.constraint; /** Is the value equal to another value, as tested by the * {@link java.lang.Object#equals} method? */ public class IsEqual implements Constraint { private Object _object; /** Creates a new instance of IsEqual */ public IsEqual( Object o ) { _object = o; } public boolean eval( Object arg ) { return arg.equals(_object); } public String toString() { return "a value equal to <" + _object.toString() + ">"; } } --- NEW FILE: IsLessThan.java --- /* Copyright (c) 2002 Nat Pryce. All rights reserved. * * Created on February 10, 2002, 11:35 PM */ package com.mockobjects.constraint; /** Is the value less than another {@link java.lang.Comparable} value? */ public class IsLessThan implements Constraint { private Comparable _object; /** Creates a new instance of IsLessThan */ public IsLessThan(Comparable o) { _object = o; } public boolean eval( Object arg ) { return _object.compareTo(arg) > 0; } public String toString() { return "a value less than <" + _object.toString() + ">"; } } --- NEW FILE: And.java --- /* Copyright (c) 2002 B13media Ltd. All rights reserved. * * Created on February 10, 2002, 11:49 PM */ package com.mockobjects.constraint; /** Calculates the logical conjunction of two constraints. * Evaluation is shortcut, so that the second constraint is not * called if the first constraint returns <code>false</code>. */ public class And implements Constraint { Constraint _p1, _p2; public And(Constraint p1, Constraint p2) { _p1 = p1; _p2 = p2; } public boolean eval( Object o ) { return _p1.eval(o) && _p2.eval(o); } public String toString() { return "(" + _p1.toString() + " and " + _p2.toString() + ")"; } } --- NEW FILE: IsSame.java --- /* Copyright (c) 2002 Nat Pryce. All rights reserved. * * Created on February 10, 2002, 11:35 PM */ package com.mockobjects.constraint; /** Is the value the same object as another value? */ public class IsSame implements Constraint { private Object _object; /** Creates a new instance of IsSame * * @param o * The predicate evaluates to true only when the argument is * this object. */ public IsSame(Object o) { _object = o; } public boolean eval( Object arg ) { return arg == _object; } public String toString() { return "the same object as <" + _object.toString() + ">"; } } --- NEW FILE: IsNull.java --- /* Copyright (c) 2002 Nat Pryce. All rights reserved. * * Created on February 10, 2002, 11:33 PM */ package com.mockobjects.constraint; /** Is the value null? */ public class IsNull implements Constraint { public IsNull() { } public boolean eval(Object o) { return o == null; } public String toString() { return "null"; } } --- NEW FILE: Constraint.java --- /* Copyright (c) 2002 Nat Pryce. All rights reserved. * * Created on February 10, 2002, 11:21 PM */ package com.mockobjects.constraint; /** A constraint over acceptable values. */ public interface Constraint { /** Evaluates the constraint for argument <var>o</var>. * * @return * <code>true</code> if <var>o</var> meets the constraint, * <code>false</code> if it does not. */ boolean eval( Object o ); } --- NEW FILE: Or.java --- /* Copyright (c) 2002 B13media Ltd. All rights reserved. * * Created on February 10, 2002, 11:49 PM */ package com.mockobjects.constraint; /** Calculates the logical disjunction of two constraints. * Evaluation is shortcut, so that the second constraint is not * called if the first constraint returns <code>true</code>. */ public class Or implements Constraint { Constraint _p1, _p2; public Or( Constraint p1, Constraint p2 ) { _p1 = p1; _p2 = p2; } public boolean eval( Object o ) { return _p1.eval(o) || _p2.eval(o); } public String toString() { return "(" + _p1.toString() + " or " + _p2.toString() + ")"; } } --- NEW FILE: IsGreaterThan.java --- /* Copyright (c) 2002 Nat Pryce. All rights reserved. * * Created on February 10, 2002, 11:35 PM */ package com.mockobjects.constraint; /** Is the value greater than another {@link java.lang.Comparable} value? */ public class IsGreaterThan implements Constraint { private Comparable _object; /** Creates a new instance of IsGreaterThan */ public IsGreaterThan( Comparable o ) { _object = o; } public boolean eval( Object arg ) { return _object.compareTo(arg) < 0; } public String toString() { return "a value greater than <" + _object.toString() + ">"; } } --- NEW FILE: IsAnything.java --- /* Copyright (c) 2002 Nat Pryce. All rights reserved. * * Created on February 10, 2002, 11:33 PM */ package com.mockobjects.constraint; /** A constraint that always returns <code>true</code>. */ public class IsAnything implements Constraint { public IsAnything() { } public boolean eval(Object o) { return true; } public String toString() { return "any value"; } } --- NEW FILE: IsEventFrom.java --- /** Created on Jun 28, 2002 by npryce * Copyright (c) B13media Ltd. */ package com.mockobjects.constraint; import java.util.EventObject; /** Tests if the value is an event announced by a specific object. */ public class IsEventFrom implements Constraint { private Class _event_class; private Object _source; /** Constructs an IsEventFrom predicate that returns true for any object * derived from {@link java.util.EventObject} announced by * <var>source</var>. */ public IsEventFrom( Object source ) { this( EventObject.class, source ); } /** Constructs an IsEventFrom predicate that returns true for any object * derived from <var>event_class</var> announced by * <var>source</var>. */ public IsEventFrom( Class event_class, Object source ) { _event_class = event_class; _source = source; } public boolean eval( Object o ) { if( o instanceof EventObject ) { EventObject ev = (EventObject)o; return _event_class.isInstance(o) && ev.getSource() == _source; } else { return false; } } public String toString() { return "an event of type " + _event_class.getName() + " from " + _source.toString(); } } --- NEW FILE: IsInstanceOf.java --- /* Copyright (c) 2002 Nat Pryce. All rights reserved. * * Created on February 10, 2002, 11:35 PM */ package com.mockobjects.constraint; /** Tests whether the value is an instance of a class. */ public class IsInstanceOf implements Constraint { private Class _class; /** Creates a new instance of IsInstanceOf * * @param theclass * The predicate evaluates to true for instances of this class * or one of its subclasses. */ public IsInstanceOf( Class theclass ) { _class = theclass; } public boolean eval( Object arg ) { return _class.isInstance( arg ); } public String toString() { return "an instance of <" + _class.getName() + ">"; } } |
From: Nat P. <np...@us...> - 2002-11-12 17:41:36
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/constraint In directory usw-pr-cvs1:/tmp/cvs-serv11113/src/core/com/mockobjects/constraint Log Message: Directory /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/constraint added to the repository |
From: Nat P. <np...@us...> - 2002-11-12 17:41:19
|
Update of /cvsroot/mockobjects/mockobjects-java/src/jdk/1.4/test/mockobjects/constraint In directory usw-pr-cvs1:/tmp/cvs-serv10977/src/jdk/1.4/test/mockobjects/constraint Log Message: Directory /cvsroot/mockobjects/mockobjects-java/src/jdk/1.4/test/mockobjects/constraint added to the repository |
From: Nat P. <np...@us...> - 2002-11-12 17:41:10
|
Update of /cvsroot/mockobjects/mockobjects-java/src/jdk/1.4/com/mockobjects/constraint In directory usw-pr-cvs1:/tmp/cvs-serv10866/src/jdk/1.4/com/mockobjects/constraint Log Message: Directory /cvsroot/mockobjects/mockobjects-java/src/jdk/1.4/com/mockobjects/constraint added to the repository |
From: Nat P. <np...@us...> - 2002-11-12 17:40:56
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/constraint In directory usw-pr-cvs1:/tmp/cvs-serv10721/src/core/test/mockobjects/constraint Log Message: Directory /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/constraint added to the repository |
From: Vincent M. <vm...@oc...> - 2002-11-12 08:07:37
|
Hi Nat, > -----Original Message----- > From: moc...@li... > [mailto:moc...@li...] On Behalf Of Nat > Pryce > Sent: 11 November 2002 16:21 > To: moc...@li... > Subject: [MO-java-dev] CVS: mockobjects- > java/src/core/com/mockobjects/dynamic Mock.java,1.13,1.14 [snip] > Neatened up some formatting, no change in functionality [snip] > - assertTrue( "unexpected call to " + method.getName(), > - !_strict ); > + assertTrue( "unexpected call to "+method.getName(), !_strict > ); You really find this neater? ;-) [snip] -Vincent |