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: Immanuel, Gidado-Y. <av...@cd...> - 2002-11-08 08:25:48
|
(Appologies if this should go to the user list, but that list has been dormant for a little while, so I'm headed straight to the source) This has taken me about an 1 1/2 to figure out (thank goodness for the code). In my test case I have: 1. handler.log(val); 2. mock.setExpectedLogMessage(val); 3. mock.verify(); where the handler knows about the mock. What happens is that line 1 eventually calls mock.log() which then calls mock.logMessage.setActual(). setActual looks to see if it should verify...finds no expectations...so skips it. Line 2 sets the expected value which eventually calls ExpectationValue.setExpected() which calls AbstractExpectation.setHasExpectations() which does the not so obvious: AbstractExpectation.clearActual() So Line 2 ends up clearing whatever is set in Line 1. The only usage pattern that works is to setExpected() before setActual(): 1. mock.setExpectedLogMessage(val); 2. handler.log(val); 3. mock.verify(); This was not clear anywhere in the articles or javadoc. Perhaps you could add this to the FAQ page. I assume there is a very good reason why clearActual() is necessary in setHasExpectations()...I'm very new to all this, so if you don't mind educating me a little, I would love to know. Thanks, Gidado |
From: Immanuel, Gidado-Y. <av...@cd...> - 2002-11-08 06:46:22
|
I take it that 0.07 (the James Bond release :) is the successor to 0.6, despite the fact that 0.6 > 0.007 ? Regards, Gidado |
From: Nat P. <np...@us...> - 2002-11-07 17:45:37
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory usw-pr-cvs1:/tmp/cvs-serv7280/src/core/test/mockobjects/dynamic Modified Files: MockTest.java CallCounterTest.java CallSequenceTest.java Log Message: Added more checks to catch wrong method names earlier and give meaningful failure messages Refactoring: renamed expect... methods in Mock class to match Joe's better naming convention Fixed and extended Javadoc comments. Index: MockTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockTest.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- MockTest.java 7 Nov 2002 13:04:20 -0000 1.6 +++ MockTest.java 7 Nov 2002 17:45:03 -0000 1.7 @@ -62,7 +62,7 @@ public void testMockCallToNoArgMethod() { Object result = new Object(); - _mock.expectReturn( "noArgs", Mock.NO_ARGS, result ); + _mock.expectAndReturn( "noArgs", Mock.NO_ARGS, result ); assertSame( result, _interface.noArgs() ); @@ -78,7 +78,7 @@ } public void testObjectTypes() { - _mock.expectReturn( "objectTypes", + _mock.expectAndReturn( "objectTypes", new Predicate[] { new IsEqual( new Integer(1) ) }, "1" ); @@ -87,7 +87,7 @@ } public void testPrimitiveTypes() { - _mock.expectReturn( "primitiveTypes", + _mock.expectAndReturn( "primitiveTypes", new Predicate[] { new IsEqual( new Integer(2) ), new IsEqual( new Integer(3) ) }, new Integer(6) ); @@ -100,8 +100,8 @@ Object result1 = new Object(); Object result2 = new Object(); - _mock.expectReturn( "noArgs", Mock.NO_ARGS, result1 ); - _mock.expectReturn( "noArgs", Mock.NO_ARGS, result2 ); + _mock.expectAndReturn( "noArgs", Mock.NO_ARGS, result1 ); + _mock.expectAndReturn( "noArgs", Mock.NO_ARGS, result2 ); assertSame( result2, _interface.noArgs() ); assertSame( result2, _interface.noArgs() ); @@ -109,7 +109,7 @@ } public void testThrow() { - _mock.expectThrow( "primitiveTypes", + _mock.expectAndThrow( "primitiveTypes", new Predicate[] { new IsEqual( new Integer(2) ), new IsEqual( new Integer(3) ) }, new ArithmeticException("message") ); @@ -233,7 +233,7 @@ Predicate p = new IsEqual( new Integer(2) ); Predicate q = new IsAnything(); - _mock.expectReturn( "objectTypes", new Predicate[]{p,q}, "2" ); + _mock.expectAndReturn( "objectTypes", new Predicate[]{p,q}, "2" ); assertFails( "mock did not fail when wrong number of arguments passed", new Runnable() { @@ -259,7 +259,7 @@ public void testPredicateFailure() { Predicate p = new IsEqual( new Integer(2) ); - _mock.expectReturn( "objectTypes", new Predicate[]{p}, "2" ); + _mock.expectAndReturn( "objectTypes", new Predicate[]{p}, "2" ); assertTrue( !p.eval( new Integer(1) ) ); try { @@ -387,7 +387,7 @@ } public void testErrorWhenMockedVoidMethodReturnsAValue() { - _mock.expectReturn( "voidMethod", Mock.NO_ARGS, Boolean.TRUE ); + _mock.expectAndReturn( "voidMethod", Mock.NO_ARGS, Boolean.TRUE ); try { _interface.voidMethod(); @@ -483,6 +483,32 @@ } ); } + public void testFailureWhenExpectNotCalledMethodNotOnMockedInterfaces() { + final Mock mock = new Mock( Interface1.class, Interface2.class ); + + assertFails( "should fail with bad method name", new Runnable() { + public void run() { + mock.expectNotCalled( "CeciNestPasUneMethode" ); + } + } ); + } + + public void testFailureWhenOrderMethodNotOnMockedInterfaces() { + final Mock mock = new Mock( Interface1.class, Interface2.class ); + + assertFails( "should fail with bad first method name", new Runnable() { + public void run() { + mock.order( "CeciNestPasUneMethode", "method2" ); + } + } ); + assertFails( "should fail with bad second method name", new Runnable() { + public void run() { + mock.order( "method1", "CeciNestPasUneMethode" ); + } + } ); + } + + public static class DerivedMock extends Mock @@ -524,7 +550,7 @@ new Class[]{ ExampleInterface.class }, mock ); - mock.expectReturn( "objectTypes", + mock.expectAndReturn( "objectTypes", new Predicate[] { new IsAnything() }, "result" ); Index: CallCounterTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/CallCounterTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- CallCounterTest.java 6 Nov 2002 15:54:35 -0000 1.2 +++ CallCounterTest.java 7 Nov 2002 17:45:04 -0000 1.3 @@ -28,7 +28,7 @@ final Object[] ARGS = { new Object() }; final Object RESULT = new Object(); - mock_call.expectReturn( "call", ARGS, RESULT ); + mock_call.expectAndReturn( "call", ARGS, RESULT ); assertSame( RESULT, counter.call(ARGS) ); @@ -44,7 +44,7 @@ 1, (MockCall)mock_call.proxy() ); final Object RESULT = new Object(); - mock_call.expectThrow( "call", P.ANY_ARGS, new ExampleException() ); + mock_call.expectAndThrow( "call", P.ANY_ARGS, new ExampleException() ); try { counter.call( new Object[0] ); Index: CallSequenceTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/CallSequenceTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- CallSequenceTest.java 6 Nov 2002 15:54:35 -0000 1.2 +++ CallSequenceTest.java 7 Nov 2002 17:45:04 -0000 1.3 @@ -50,10 +50,10 @@ final Object[] ARGS_2 = { new Object() }; final Object RESULT_2 = new Object(); - mock_call_1.expectReturn( "call", ARGS_1, RESULT_1 ); + mock_call_1.expectAndReturn( "call", ARGS_1, RESULT_1 ); call_list.expect( (MockCall)mock_call_1.proxy() ); - mock_call_2.expectReturn( "call", ARGS_2, RESULT_2 ); + mock_call_2.expectAndReturn( "call", ARGS_2, RESULT_2 ); call_list.expect( (MockCall)mock_call_2.proxy() ); assertSame( RESULT_1, call_list.call( ARGS_1 ) ); @@ -75,11 +75,11 @@ final ExampleException EXCEPTION_1 = new ExampleException(); final ExampleException EXCEPTION_2 = new ExampleException(); - mock_call_1.expectThrow( "call", P.args(P.same(ARGS_1)), EXCEPTION_1 ); + mock_call_1.expectAndThrow( "call", P.args(P.same(ARGS_1)), EXCEPTION_1 ); call_list.expect( (MockCall)mock_call_1.proxy() ); - mock_call_2.expectThrow( "call", P.args(P.eq(ARGS_2)), EXCEPTION_2 ); + mock_call_2.expectAndThrow( "call", P.args(P.eq(ARGS_2)), EXCEPTION_2 ); call_list.expect( (MockCall)mock_call_2.proxy() ); try { |
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory usw-pr-cvs1:/tmp/cvs-serv7280/src/core/com/mockobjects/dynamic Modified Files: MockReturnCall.java Mock.java AbstractMockCall.java MockVoidCall.java MockThrowCall.java Log Message: Added more checks to catch wrong method names earlier and give meaningful failure messages Refactoring: renamed expect... methods in Mock class to match Joe's better naming convention Fixed and extended Javadoc comments. Index: MockReturnCall.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/MockReturnCall.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- MockReturnCall.java 6 Nov 2002 18:57:21 -0000 1.2 +++ MockReturnCall.java 7 Nov 2002 17:45:04 -0000 1.3 @@ -14,12 +14,23 @@ { private Object _result; + /** Constructs a <code>MockReturnCall</code> that accepts any arguments. + * + * @param result + * The value returned when the method is called. + */ public MockReturnCall( Object result ) { this( ANY_ARGS, result ); } - public MockReturnCall( Predicate[] expected_args, Object result ) - { + /** Constructs a <code>MockReturnCall</code> that checks its arguments. + * + * @param expected_args + * Predicates that define the valid arguments of the method. + * @param result + * The value returned when the method is called. + */ + public MockReturnCall( Predicate[] expected_args, Object result ) { super( expected_args ); _result = result; } Index: Mock.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Mock.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- Mock.java 7 Nov 2002 13:04:21 -0000 1.12 +++ Mock.java 7 Nov 2002 17:45:05 -0000 1.13 @@ -6,6 +6,7 @@ import com.mockobjects.Verifiable; import junit.framework.Assert; +import junit.framework.AssertionFailedError; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; @@ -111,6 +112,9 @@ * * @param call * The call to be mocked. + * @throws junit.framework.AssertionFailedError + * The method name is not the name of a method mocked by this + * Mock object. */ public void setup( String method_name, MockCall call ) { checkMethodName( method_name ); @@ -127,6 +131,9 @@ * The result that will be returned from this call. Primitive types * must be wrapped in the equivalent Java object, and will be unwrapped * before being returned to the caller of the method. + * @throws junit.framework.AssertionFailedError + * The method name is not the name of a method mocked by this + * Mock object. */ public void setupResult( String method_name, Object result ) { setup( method_name, new MockReturnCall( result ) ); @@ -140,6 +147,9 @@ * The name of the method that will be called. * @param exception * The exception or error that will be thrown as a result of this call. + * @throws junit.framework.AssertionFailedError + * The method name is not the name of a method mocked by this + * Mock object. */ public void setupThrow( String method_name, Throwable exception ) { setup( method_name, new MockThrowCall( exception ) ); @@ -164,6 +174,9 @@ * * @param call * An object describing the expected call and mocking its behaviour. + * @throws junit.framework.AssertionFailedError + * The method name is not the name of a method mocked by this + * Mock object. */ public void expect( String method_name, MockCall call ) { checkMethodName( method_name ); @@ -182,8 +195,11 @@ * The result that will be returned from this call. Primitive types * must be wrapped in the equivalent Java object, and will be unwrapped * before being returned to the caller of the method. + * @throws junit.framework.AssertionFailedError + * The method name is not the name of a method mocked by this + * Mock object. */ - public void expectReturn( String method, Predicate[] args, Object result ) { + public void expectAndReturn( String method, Predicate[] args, Object result ) { expect( method, new MockReturnCall( args, result ) ); } @@ -197,9 +213,12 @@ * The result that will be returned from this call. Primitive types * must be wrapped in the equivalent Java object, and will be unwrapped * before being returned to the caller of the method. + * @throws junit.framework.AssertionFailedError + * The method name is not the name of a method mocked by this + * Mock object. */ - public void expectReturn( String method, Object arg, Object result ) { - expectReturn( method, P.args(P.eq(arg) ), result); + public void expectAndReturn( String method, Object arg, Object result ) { + expectAndReturn( method, P.args(P.eq(arg) ), result); } /** Expect a method call with no parameters and return a result when it is called. @@ -210,9 +229,12 @@ * The result that will be returned from this call. Primitive types * must be wrapped in the equivalent Java object, and will be unwrapped * before being returned to the caller of the method. + * @throws junit.framework.AssertionFailedError + * The method name is not the name of a method mocked by this + * Mock object. */ - public void expectReturn( String method, Object result ) { - expectReturn( method, NO_ARGS, result ); + public void expectAndReturn( String method, Object result ) { + expectAndReturn( method, NO_ARGS, result ); } /** @@ -224,6 +246,9 @@ * An array of {@link com.mockobjects.dynamic.Predicate}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 ) { expect( method, new MockVoidCall( args ) ); @@ -236,6 +261,9 @@ * The name of the method that will be called. * @param arg * An single object that will be compared with predicate eq() + * @throws junit.framework.AssertionFailedError + * The method name is not the name of a method mocked by this + * Mock object. */ public void expectVoid(String method, Object arg) { expectVoid( method, P.args(P.eq(arg)) ); @@ -246,6 +274,9 @@ * * @param method * The name of the method that will be called. + * @throws junit.framework.AssertionFailedError + * The method name is not the name of a method mocked by this + * Mock object. */ public void expectVoid(String method) { expectVoid( method, NO_ARGS ); @@ -261,8 +292,11 @@ * the expected arity of the method call. * @param exception * The exception or error that will be thrown as a result of this call. + * @throws junit.framework.AssertionFailedError + * The method name is not the name of a method mocked by this + * Mock object. */ - public void expectThrow( String method, Predicate[] args, Throwable exception ) { + public void expectAndThrow( String method, Predicate[] args, Throwable exception ) { expect( method, new MockThrowCall( args, exception ) ); } @@ -274,9 +308,12 @@ * An single object that will be compared with predicate eq() * @param exception * The exception or error that will be thrown as a result of this call. + * @throws junit.framework.AssertionFailedError + * The method name is not the name of a method mocked by this + * Mock object. */ - public void expectThrow( String method, Object arg, Throwable exception ) { - expectThrow( method, P.args(P.eq(arg)), exception ); + public void expectAndThrow( String method, Object arg, Throwable exception ) { + expectAndThrow( method, P.args(P.eq(arg)), exception ); } /** Expect a method call with no parameters and throw an exception or error when it is called. @@ -285,30 +322,42 @@ * The name of the method that will be called. * @param exception * The exception or error that will be thrown as a result of this call. + * @throws junit.framework.AssertionFailedError + * The method name is not the name of a method mocked by this + * Mock object. */ - public void expectThrow( String method, Throwable exception ) { - expectThrow( method, NO_ARGS, exception ); + public void expectAndThrow( String method, Throwable exception ) { + expectAndThrow( method, NO_ARGS, exception ); } - /** - * Expect a method not to be called. + /** Expect a method not to be called. * An {@link junit.framework.AssertionFailedError} will be thrown if * the method is called. * * @param methodName * The name of the method that will not be called. + * @throws junit.framework.AssertionFailedError + * The method name is not the name of a method mocked by this + * Mock object. */ - public void expectNotCalled( String methodName ) { - methods.expectNotCalled(methodName); + public void expectNotCalled( String method_name ) { + checkMethodName( method_name ); + methods.expectNotCalled(method_name); } - - /** - * Define an order between two calls. The method named + + /** Define an order between two calls. The method named * <var>subsequent_method</var> <em>must</em> be called after * the method namd <var>preceding_method</var>, otherwise an - * {@link junit.framework.AssertionFailedError} will be thrown. + * {@link junit.framework.AssertionFailedError} will be thrown + * when <var>subsequent_method</var> is called. + * + * @throws junit.framework.AssertionFailedError + * Either method name is not the name of a method mocked by this + * Mock object. */ public void order( String preceding_method, String subsequent_method ) { + checkMethodName( preceding_method ); + checkMethodName( subsequent_method ); methods.order( preceding_method, subsequent_method ); } @@ -357,7 +406,7 @@ if( expectation.canBeCalled() ) { return expectation.callAndCheckResult( method, args ); } else { - assertTrue( "Unexpected call to " + method.getName(), + assertTrue( "unexpected call to " + method.getName(), !_strict ); return defaultResult( method.getReturnType() ); } Index: AbstractMockCall.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/AbstractMockCall.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- AbstractMockCall.java 6 Nov 2002 18:57:21 -0000 1.1 +++ AbstractMockCall.java 7 Nov 2002 17:45:05 -0000 1.2 @@ -5,13 +5,15 @@ package com.mockobjects.dynamic; -/** An mocked call to a method of that has a void result. +/** An abstract mocked method call that checks its arguments against + * expectations, but leaves the result of the call (returned value, + * thrown exception or side effect) to derived classes. */ public abstract class AbstractMockCall extends junit.framework.Assert implements MockCall { - /** A constant that indicates that the <code>MockVoidCall</code> accepts + /** A constant that indicates that the mocked call accepts * any arguments, that is, that the call does not check the arguments * passed to it. */ @@ -21,14 +23,13 @@ private Predicate[] _expected_args; - /** Constructs an <code>MockVoidCall</code> that accepts any arguments. - * The name of the expected method. + /** Constructs an <code>AbstractMockCall</code> that accepts any arguments. */ public AbstractMockCall() { this( ANY_ARGS ); } - /** Constructs a <code>MockVoidCall</code> that checks its arguments. + /** Constructs a <code>AbstractMockCall</code> that checks its arguments. * * @param expected_args * Predicates that define the valid arguments of the method. @@ -53,7 +54,8 @@ private void checkArguments( Object[] args ) { int arg_count = (args == null) ? 0 : args.length; - assertEquals( "wrong number of arguments", getArgumentCount(), arg_count ); + assertEquals( "wrong number of arguments", + getArgumentCount(), arg_count ); for( int i = 0; i < arg_count; i++ ) { checkArgument( i, _expected_args[i], args[i]); @@ -65,13 +67,13 @@ } private void checkArgument( int i, Predicate expectedArg, Object arg ) { - assertTrue("argument " + (i+1) + "\n" + - "expected " + expectedArg + "\n" + - " was " + arg + "", + assertTrue( "argument " + (i+1) + "\n" + + "expected " + expectedArg + "\n" + + " was " + arg + "", expectedArg.eval(arg) ); } - public String describeArgument( int n ) { + private String describeArgument( int n ) { if( _expected_args == null ) { return "anything"; } else { Index: MockVoidCall.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/MockVoidCall.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- MockVoidCall.java 6 Nov 2002 18:57:21 -0000 1.3 +++ MockVoidCall.java 7 Nov 2002 17:45:06 -0000 1.4 @@ -5,15 +5,22 @@ package com.mockobjects.dynamic; -/** An mocked call to a method of that has a void result. +/** A mocked call to a method of that has a void result. */ public class MockVoidCall extends AbstractMockCall { + /** Constructs a <code>MockVoidCall</code> that accepts any arguments. + */ public MockVoidCall() { this( ANY_ARGS ); } + /** Constructs a <code>MockVoidCall</code> that checks its arguments. + * + * @param expected_args + * Predicates that define the valid arguments of the method. + */ public MockVoidCall( Predicate[] 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.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- MockThrowCall.java 6 Nov 2002 18:57:21 -0000 1.2 +++ MockThrowCall.java 7 Nov 2002 17:45:06 -0000 1.3 @@ -6,7 +6,7 @@ import com.mockobjects.dynamic.MockVoidCall; -/** A mocked call to a method results in a thrown exception. +/** A mocked call to a method that results in a thrown exception. */ class MockThrowCall extends AbstractMockCall @@ -14,10 +14,24 @@ private Throwable _exception; + /** Constructs a <code>MockThrowCall</code> that accepts any arguments. + * + * @param exception + * The exception or error that will be thrown when this method + * is called. + */ public MockThrowCall( Throwable exception ) { this( ANY_ARGS, exception ); } + /** Constructs a <code>MockThrowCall</code> that checks its arguments. + * + * @param expected_args + * Predicates that define the valid arguments of the method. + * @param exception + * The exception or error that will be thrown when this method + * is called. + */ public MockThrowCall( Predicate[] expected_args, Throwable exception ) { |
From: Nat P. <np...@us...> - 2002-11-07 15:51:30
|
Update of /cvsroot/mockobjects/no-stone-unturned/doc/xdocs In directory usw-pr-cvs1:/tmp/cvs-serv13619 Modified Files: random.xml Log Message: Fixed grammatical error. Index: random.xml =================================================================== RCS file: /cvsroot/mockobjects/no-stone-unturned/doc/xdocs/random.xml,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- random.xml 7 Nov 2002 13:25:48 -0000 1.7 +++ random.xml 7 Nov 2002 15:51:25 -0000 1.8 @@ -11,7 +11,7 @@ <para> Many applications exhibit random or pseudo-random behaviour. -For example, in video games use pseudo-randomness to portray +For example, video games use pseudo-randomness to portray natural behaviours that are too complex to simulate accurately, or to add variety to behaviours that are too predictable when calculated algorithmically. Cryptographic algorithms |
From: Nat P. <np...@us...> - 2002-11-07 13:25:51
|
Update of /cvsroot/mockobjects/no-stone-unturned/doc/xdocs In directory usw-pr-cvs1:/tmp/cvs-serv26779 Modified Files: random.xml Log Message: Extended introductory paragraph. Index: random.xml =================================================================== RCS file: /cvsroot/mockobjects/no-stone-unturned/doc/xdocs/random.xml,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- random.xml 14 Aug 2002 13:54:58 -0000 1.6 +++ random.xml 7 Nov 2002 13:25:48 -0000 1.7 @@ -10,20 +10,25 @@ <title>Introduction</title> <para> -Pseudo-random behaviour is used in many applications. -For example, in video games pseudo-randomness is used to portray +Many applications exhibit random or pseudo-random behaviour. +For example, in video games use pseudo-randomness to portray natural behaviours that are too complex to simulate accurately, or to add variety to behaviours that are too predictable when -simulated algorithmically. +calculated algorithmically. Cryptographic algorithms +use random number generators extensively, as do optimisation +algorithms such as genetic programming and simulated annealing. +But how can one test behaviour that is, by its very nature, +unpredictable? </para> <para> -Testing random behaviour is not complex. You will not need to use -statistical analysis, unless you are actually writing a new random -number generator. Instead, as in many test driven designs, you -will end up separating the objects that direct activity from -those that effect activity so that you can mock one to test -the other. In the case of random behaviour, the object directing +In this chapter, I hope to show that testing random behaviour is not +complex. You will not need to use statistical analysis, unless +you are actually writing a new random number generator. +Instead, as in many test driven designs, you will end up +separating the objects that direct activity from those that effect +activity so that you can mock one to test the other. +In the case of random behaviour, the object directing the activity is a random number generator. You can use a mock generator to feed deterministic values into the objects under test. So far, soo good, but it turns out that testing random behaviour |
From: Nat P. <np...@us...> - 2002-11-07 13:04:25
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory usw-pr-cvs1:/tmp/cvs-serv15265/src/core/test/mockobjects/dynamic Modified Files: MockTest.java Log Message: Mock raises test failure if try to expect/setup an invalid method Index: MockTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockTest.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- MockTest.java 6 Nov 2002 15:54:34 -0000 1.5 +++ MockTest.java 7 Nov 2002 13:04:20 -0000 1.6 @@ -403,7 +403,6 @@ assertEquals("Same interface should be equal", _interface, _interface); } - public static interface Interface1 { void method1(); } @@ -463,6 +462,27 @@ assertTrue( o + " should be an instance of " + klass, klass.isInstance(o) ); } + + public void testFailureWhenExpectMethodNotOnMockedInterfaces() { + final Mock mock = new Mock( Interface1.class, Interface2.class ); + + assertFails( "should fail with bad method name", new Runnable() { + public void run() { + mock.expectVoid( "CeciNestPasUneMethode", Mock.NO_ARGS ); + } + } ); + } + + public void testFailureWhenSetupMethodNotOnMockedInterfaces() { + final Mock mock = new Mock( Interface1.class, Interface2.class ); + + assertFails( "should fail with bad method name", new Runnable() { + public void run() { + mock.setupResult( "CeciNestPasUneMethode", new Object() ); + } + } ); + } + public static class DerivedMock extends Mock |
From: Nat P. <np...@us...> - 2002-11-07 13:04:24
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory usw-pr-cvs1:/tmp/cvs-serv15265/src/core/com/mockobjects/dynamic Modified Files: Mock.java Log Message: Mock raises test failure if try to expect/setup an invalid method Index: Mock.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Mock.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- Mock.java 6 Nov 2002 15:54:35 -0000 1.11 +++ Mock.java 7 Nov 2002 13:04:21 -0000 1.12 @@ -28,6 +28,7 @@ public static final Predicate[] NO_ARGS = new Predicate[0]; + private Class[] _proxy_classes; private Object _proxy; private MethodMap methods = new MethodMap(); private boolean _strict = false; @@ -69,6 +70,7 @@ * any number of interfaces. */ public Mock( Class[] interfaces_to_mock ) { + _proxy_classes = (Class[])interfaces_to_mock.clone(); _proxy = createInterface( interfaces_to_mock ); setupDefaultResult( byte.class, new Byte((byte)0) ); @@ -111,7 +113,8 @@ * The call to be mocked. */ public void setup( String method_name, MockCall call ) { - methods.setupCall(method_name, call); + checkMethodName( method_name ); + methods.setupCall( method_name, call ); } /** Set up calls to <var>method</var> to return <var>result</var>, @@ -163,7 +166,8 @@ * An object describing the expected call and mocking its behaviour. */ public void expect( String method_name, MockCall call ) { - methods.expectCall(method_name, call); + checkMethodName( method_name ); + methods.expectCall( method_name, call ); } /** Expect a method call and return a result when it is called. @@ -383,5 +387,26 @@ return Proxy.newProxyInstance( getClass().getClassLoader(), interface_classes, this ); + } + + private void checkMethodName( String method_name ) { + for( int i = 0; i < _proxy_classes.length; i++ ) { + if( hasMethod( _proxy_classes[i], method_name ) ) { + return; + } + } + + fail("method " + method_name + + " is not defined by any of the mocked interfaces" ); + } + + private boolean hasMethod( Class c, String method_name ) { + Method[] methods = c.getMethods(); + for( int i = 0; i < methods.length; i++ ) { + if( methods[i].getName().equals(method_name) ) { + return true; + } + } + return false; } } |
From: Nat P. <np...@us...> - 2002-11-06 18:57:26
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory usw-pr-cvs1:/tmp/cvs-serv28820/src/core/com/mockobjects/dynamic Modified Files: MockReturnCall.java MockVoidCall.java MockThrowCall.java Added Files: AbstractMockCall.java Log Message: Refactored MockCall class hierarchy: Extracted AbstractMockCall class from MockVoidCall class Made concrete MockCall classes derive from AbstractMockCall --- NEW FILE: AbstractMockCall.java --- /* Copyright (c) 2002 Nat Pryce. All rights reserved. * * Created on February 10, 2002, 11:09 PM */ package com.mockobjects.dynamic; /** An mocked call to a method of that has a void result. */ public abstract class AbstractMockCall extends junit.framework.Assert implements MockCall { /** A constant that indicates that the <code>MockVoidCall</code> accepts * any arguments, that is, that the call does not check the arguments * passed to it. */ static final Predicate[] ANY_ARGS = null; private Predicate[] _expected_args; /** Constructs an <code>MockVoidCall</code> that accepts any arguments. * The name of the expected method. */ public AbstractMockCall() { this( ANY_ARGS ); } /** Constructs a <code>MockVoidCall</code> that checks its arguments. * * @param expected_args * Predicates that define the valid arguments of the method. */ public AbstractMockCall( Predicate[] expected_args ) { _expected_args = expected_args; } public Object call( Object[] args ) throws Throwable { if( isTestingArguments() ) { checkArguments( args ); } return null; } private boolean isTestingArguments() { return _expected_args != null; } private void checkArguments( Object[] args ) { int arg_count = (args == null) ? 0 : args.length; assertEquals( "wrong number of arguments", getArgumentCount(), arg_count ); for( int i = 0; i < arg_count; i++ ) { checkArgument( i, _expected_args[i], args[i]); } } private int getArgumentCount() { return _expected_args.length; } private void checkArgument( int i, Predicate expectedArg, Object arg ) { assertTrue("argument " + (i+1) + "\n" + "expected " + expectedArg + "\n" + " was " + arg + "", expectedArg.eval(arg) ); } public String describeArgument( int n ) { if( _expected_args == null ) { return "anything"; } else { return _expected_args[n].toString(); } } } Index: MockReturnCall.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/MockReturnCall.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- MockReturnCall.java 31 Oct 2002 17:03:45 -0000 1.1 +++ MockReturnCall.java 6 Nov 2002 18:57:21 -0000 1.2 @@ -9,7 +9,8 @@ /** An mocked call to a method that returns a result. */ -class MockReturnCall extends MockVoidCall +class MockReturnCall + extends AbstractMockCall { private Object _result; Index: MockVoidCall.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/MockVoidCall.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- MockVoidCall.java 5 Nov 2002 16:03:40 -0000 1.2 +++ MockVoidCall.java 6 Nov 2002 18:57:21 -0000 1.3 @@ -8,74 +8,20 @@ /** An mocked call to a method of that has a void result. */ public class MockVoidCall - extends junit.framework.Assert - implements MockCall + extends AbstractMockCall { - /** A constant that indicates that the <code>MockVoidCall</code> accepts - * any arguments, that is, that the call does not check the arguments - * passed to it. - */ - static final Predicate[] ANY_ARGS = null; - - - private Predicate[] _expected_args; - - - /** Constructs an <code>MockVoidCall</code> that accepts any arguments. - * The name of the expected method. - */ public MockVoidCall() { this( ANY_ARGS ); } - /** Constructs a <code>MockVoidCall</code> that checks its arguments. - * - * @param expected_args - * Predicates that define the valid arguments of the method. - */ public MockVoidCall( Predicate[] expected_args ) { - _expected_args = expected_args; + super( expected_args ); } - public Object call( Object[] args ) - throws Throwable + public Object call( Object[] args ) + throws Throwable { - if( isTestingArguments() ) { - checkArguments( args ); - } + super.call(args); return Mock.VOID; - } - - private boolean isTestingArguments() { - return _expected_args != null; - } - - private void checkArguments( Object[] args ) - { - int arg_count = (args == null) ? 0 : args.length; - assertEquals( "wrong number of arguments", getArgumentCount(), arg_count ); - - for( int i = 0; i < arg_count; i++ ) { - checkArgument( i, _expected_args[i], args[i]); - } - } - - private int getArgumentCount() { - return _expected_args.length; - } - - private void checkArgument( int i, Predicate expectedArg, Object arg ) { - assertTrue("argument " + (i+1) + "\n" + - "expected " + expectedArg + "\n" + - " was " + arg + "", - expectedArg.eval(arg) ); - } - - public String describeArgument( int n ) { - if( _expected_args == null ) { - return "anything"; - } else { - return _expected_args[n].toString(); - } } } Index: MockThrowCall.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/MockThrowCall.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- MockThrowCall.java 31 Oct 2002 17:03:45 -0000 1.1 +++ MockThrowCall.java 6 Nov 2002 18:57:21 -0000 1.2 @@ -9,7 +9,7 @@ /** A mocked call to a method results in a thrown exception. */ class MockThrowCall - extends MockVoidCall + extends AbstractMockCall { private Throwable _exception; |
From: Vincent M. <vm...@oc...> - 2002-11-06 16:31:06
|
> -----Original Message----- > From: moc...@li... > [mailto:moc...@li...] On Behalf Of > Steve Freeman > Sent: 06 November 2002 08:53 > To: moc...@li... > Subject: [MO-java-dev] CVS: mockobjects-java .cvsignore,1.2,NONE > > Update of /cvsroot/mockobjects/mockobjects-java > In directory usw-pr-cvs1:/tmp/cvs-serv1180 > > Removed Files: > .cvsignore > Log Message: > Removed .cvsignore because it clashes with some local installations This file is a CVS file which is used by all projects I've come across. What's wrong? -Vincent |
From: Nat P. <np...@us...> - 2002-11-06 15:54:39
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory usw-pr-cvs1:/tmp/cvs-serv31865/src/core/test/mockobjects/dynamic Modified Files: MockTest.java CallCounterTest.java CallSequenceTest.java Log Message: Fixed tests broken by MethodExpectation class Replaced createInterface methods with interface references passed to constructor, and the proxy() method to "cast" the mock to its proxy. Index: MockTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockTest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- MockTest.java 5 Nov 2002 16:26:59 -0000 1.4 +++ MockTest.java 6 Nov 2002 15:54:34 -0000 1.5 @@ -36,23 +36,7 @@ void first(); void second(); } - - public static class DerivedMock - extends Mock - { - public boolean was_called = false; - - public void voidMethod() { - this.was_called = true; - } - public String objectTypes( Integer n ) throws Throwable { - Method method = getClass().getMethod("objectTypes", new Class[] { Integer.class } ); - return (String)mockCall(method , new Object[]{n} ); - } - }; - - private Mock _mock; private ExampleInterface _interface; @@ -62,9 +46,8 @@ } public void setUp() { - _mock = new Mock(); - _interface = - (ExampleInterface)_mock.createInterface( ExampleInterface.class ); + _mock = new Mock( ExampleInterface.class ); + _interface = (ExampleInterface)_mock.proxy(); } public void tearDown() { @@ -415,6 +398,91 @@ fail("should have thrown AssertionFailedError when return from void method"); } + public void testEquals() { + assertEquals("Same interface should have same hashcode", _interface.hashCode(), _interface.hashCode()); + assertEquals("Same interface should be equal", _interface, _interface); + } + + + public static interface Interface1 { + void method1(); + } + + public static interface Interface2 { + void method2(); + } + + public static interface Interface3 { + void method3(); + } + + public static interface Interface4 { + void method4(); + } + + public static interface Interface5 { + void method5(); + } + + public void testMockTwoInterfaces() { + Mock mock = new Mock( Interface1.class, Interface2.class ); + assertInstanceOf( Interface1.class, mock.proxy() ); + assertInstanceOf( Interface2.class, mock.proxy() ); + } + + public void testMockThreeInterfaces() { + Mock mock = new Mock( Interface1.class, Interface2.class, + Interface3.class ); + assertInstanceOf( Interface1.class, mock.proxy() ); + assertInstanceOf( Interface2.class, mock.proxy() ); + assertInstanceOf( Interface3.class, mock.proxy() ); + } + + public void testMockFourInterfaces() { + Mock mock = new Mock( Interface1.class, Interface2.class, + Interface3.class, Interface4.class ); + assertInstanceOf( Interface1.class, mock.proxy() ); + assertInstanceOf( Interface2.class, mock.proxy() ); + assertInstanceOf( Interface3.class, mock.proxy() ); + assertInstanceOf( Interface4.class, mock.proxy() ); + } + + public void testMockFiveInterfaces() { + Mock mock = new Mock( new Class[] { + Interface1.class, Interface2.class, Interface3.class, + Interface4.class, Interface5.class } ); + + assertInstanceOf( Interface1.class, mock.proxy() ); + assertInstanceOf( Interface2.class, mock.proxy() ); + assertInstanceOf( Interface3.class, mock.proxy() ); + assertInstanceOf( Interface4.class, mock.proxy() ); + assertInstanceOf( Interface5.class, mock.proxy() ); + } + + private static void assertInstanceOf( Class klass, Object o ) { + assertTrue( o + " should be an instance of " + klass, + klass.isInstance(o) ); + } + + public static class DerivedMock + extends Mock + { + public boolean was_called = false; + + public DerivedMock() { + super( ExampleInterface.class ); + } + + public void voidMethod() { + this.was_called = true; + } + + public String objectTypes( Integer n ) throws Throwable { + Method method = getClass().getMethod("objectTypes", new Class[] { Integer.class } ); + return (String)mockCall(method , new Object[]{n} ); + } + }; + public void testDerivedMockClass() { DerivedMock mock = new DerivedMock(); ExampleInterface i = (ExampleInterface)Proxy.newProxyInstance( @@ -443,10 +511,5 @@ assertEquals( "result", i.objectTypes( new Integer(1) ) ); mock.verify(); - } - - public void testEquals() { - assertEquals("Same interface should have same hashcode", _interface.hashCode(), _interface.hashCode()); - assertEquals("Same interface should be equal", _interface, _interface); } } Index: CallCounterTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/CallCounterTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- CallCounterTest.java 31 Oct 2002 17:03:47 -0000 1.1 +++ CallCounterTest.java 6 Nov 2002 15:54:35 -0000 1.2 @@ -19,33 +19,18 @@ super(test); } - public void testCallCounterPassesArguments() - throws Throwable - { - Mock mock_call = new Mock(); - CallCounter counter = new CallCounter( - 1, (MockCall)mock_call.createInterface(MockCall.class) ); - - final Object[] ARGS = { new Object() }; - mock_call.expectVoid( "call", P.args( P.same(ARGS) ) ); - - counter.call( ARGS ); - - mock_call.verify(); - counter.verify(); - } - - public void testCallCounterReturnsValue() + public void testCallCounterPassesArgumentsAndReturnsValue() throws Throwable { - Mock mock_call = new Mock(); + Mock mock_call = new Mock(MockCall.class); CallCounter counter = new CallCounter( - 1, (MockCall)mock_call.createInterface(MockCall.class) ); + 1, (MockCall)mock_call.proxy() ); + final Object[] ARGS = { new Object() }; final Object RESULT = new Object(); - mock_call.expectReturn( "call", P.ANY_ARGS, RESULT ); + mock_call.expectReturn( "call", ARGS, RESULT ); - assertSame( RESULT, counter.call( new Object[0] ) ); + assertSame( RESULT, counter.call(ARGS) ); mock_call.verify(); counter.verify(); @@ -54,9 +39,9 @@ public void testCallCounterThrowsException() throws Throwable { - Mock mock_call = new Mock(); + Mock mock_call = new Mock(MockCall.class); CallCounter counter = new CallCounter( - 1, (MockCall)mock_call.createInterface(MockCall.class) ); + 1, (MockCall)mock_call.proxy() ); final Object RESULT = new Object(); mock_call.expectThrow( "call", P.ANY_ARGS, new ExampleException() ); @@ -75,9 +60,9 @@ public void testTooManyCalls() throws Throwable { - Mock mock_call = new Mock(); + Mock mock_call = new Mock(MockCall.class); final CallCounter counter = new CallCounter( - 2, (MockCall)mock_call.createInterface(MockCall.class) ); + 2, (MockCall)mock_call.proxy() ); counter.call( new Object[0] ); counter.call( new Object[0] ); @@ -95,9 +80,9 @@ public void testTooFewCalls() throws Throwable { - Mock mock_call = new Mock(); + Mock mock_call = new Mock(MockCall.class); final CallCounter counter = new CallCounter( - 2, (MockCall)mock_call.createInterface(MockCall.class) ); + 2, (MockCall)mock_call.proxy() ); counter.call( new Object[0] ); Index: CallSequenceTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/CallSequenceTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- CallSequenceTest.java 1 Nov 2002 15:35:20 -0000 1.1 +++ CallSequenceTest.java 6 Nov 2002 15:54:35 -0000 1.2 @@ -39,50 +39,22 @@ fail( "call to empty call list should fail" ); } - public void testCallListPassesArguments() + public void testCallListPassesArgumentsAndReturnsValue() throws Throwable { - Mock mock_call_1 = new Mock(); - Mock mock_call_2 = new Mock(); + Mock mock_call_1 = new Mock(MockCall.class); + Mock mock_call_2 = new Mock(MockCall.class); CallSequence call_list = new CallSequence(); final Object[] ARGS_1 = { new Object() }; - final Object[] ARGS_2 = { new Object() }; - - mock_call_1.expectVoid( "call", P.args( P.same(ARGS_1) ) ); - call_list.expect( - (MockCall)mock_call_1.createInterface(MockCall.class) ); - - mock_call_2.expectVoid( "call", P.args( P.same(ARGS_2) ) ); - call_list.expect( - (MockCall)mock_call_2.createInterface(MockCall.class) ); - - - call_list.call( ARGS_1 ); - call_list.call( ARGS_2 ); - mock_call_1.verify(); - mock_call_2.verify(); - call_list.verify(); - } - - public void testCallListReturnsValue() - throws Throwable - { - Mock mock_call_1 = new Mock(); - Mock mock_call_2 = new Mock(); - CallSequence call_list = new CallSequence(); - final Object[] ARGS_1 = { new Object() }; - final Object[] ARGS_2 = { new Object() }; final Object RESULT_1 = new Object(); + final Object[] ARGS_2 = { new Object() }; final Object RESULT_2 = new Object(); - mock_call_1.expectReturn( "call", P.args(P.same(ARGS_1)), RESULT_1 ); - call_list.expect( - (MockCall)mock_call_1.createInterface(MockCall.class) ); + mock_call_1.expectReturn( "call", ARGS_1, RESULT_1 ); + call_list.expect( (MockCall)mock_call_1.proxy() ); - mock_call_2.expectReturn( "call", P.args(P.eq(ARGS_2)), RESULT_2 ); - call_list.expect( - (MockCall)mock_call_2.createInterface(MockCall.class) ); - + mock_call_2.expectReturn( "call", ARGS_2, RESULT_2 ); + call_list.expect( (MockCall)mock_call_2.proxy() ); assertSame( RESULT_1, call_list.call( ARGS_1 ) ); assertSame( RESULT_2, call_list.call( ARGS_2 ) ); @@ -91,12 +63,12 @@ mock_call_2.verify(); call_list.verify(); } - + public void testCallListThrowsExceptionValue() throws Throwable { - Mock mock_call_1 = new Mock(); - Mock mock_call_2 = new Mock(); + Mock mock_call_1 = new Mock(MockCall.class); + Mock mock_call_2 = new Mock(MockCall.class); CallSequence call_list = new CallSequence(); final Object[] ARGS_1 = { new Object() }; final Object[] ARGS_2 = { new Object() }; @@ -105,11 +77,10 @@ mock_call_1.expectThrow( "call", P.args(P.same(ARGS_1)), EXCEPTION_1 ); call_list.expect( - (MockCall)mock_call_1.createInterface(MockCall.class) ); + (MockCall)mock_call_1.proxy() ); mock_call_2.expectThrow( "call", P.args(P.eq(ARGS_2)), EXCEPTION_2 ); - call_list.expect( - (MockCall)mock_call_2.createInterface(MockCall.class) ); + call_list.expect( (MockCall)mock_call_2.proxy() ); try { call_list.call( ARGS_1 ); |
From: Nat P. <np...@us...> - 2002-11-06 15:54:38
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory usw-pr-cvs1:/tmp/cvs-serv31865/src/core/com/mockobjects/dynamic Modified Files: Mock.java MethodMap.java MethodExpectation.java Log Message: Fixed tests broken by MethodExpectation class Replaced createInterface methods with interface references passed to constructor, and the proxy() method to "cast" the mock to its proxy. Index: Mock.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Mock.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- Mock.java 5 Nov 2002 16:37:54 -0000 1.10 +++ Mock.java 6 Nov 2002 15:54:35 -0000 1.11 @@ -26,16 +26,51 @@ * have no methods. */ public static final Predicate[] NO_ARGS = new Predicate[0]; - - protected MethodMap methods = new MethodMap(); + + + private Object _proxy; + private MethodMap methods = new MethodMap(); private boolean _strict = false; - + private Map _default_results = new HashMap(); - /** Creates a new Mock object. + /** Creates a new Mock object that mocks the behaviour of + * a single interface. + */ + public Mock( Class interface_to_mock ) { + this( new Class[]{interface_to_mock} ); + } + + /** Creates a new Mock object that mocks the behaviour of + * two interfaces. + */ + public Mock( Class interface1, Class interface2 ) { + this( new Class[]{ interface1, interface2 } ); + } + + /** Creates a new Mock object that mocks the behaviour of + * three interfaces. + */ + public Mock( Class interface1, Class interface2, Class interface3 ) { + this( new Class[] { interface1, interface2, interface3 } ); + } + + /** Creates a new Mock object that mocks the behaviour of + * four interfaces. + */ + public Mock( Class interface1, Class interface2, + Class interface3, Class interface4 ) + { + this( new Class[] { interface1, interface2, interface3, interface4 } ); + } + + /** Creates a new Mock object that mocks the behaviour of + * any number of interfaces. */ - public Mock() { + public Mock( Class[] interfaces_to_mock ) { + _proxy = createInterface( interfaces_to_mock ); + setupDefaultResult( byte.class, new Byte((byte)0) ); setupDefaultResult( short.class, new Short((short)0) ); setupDefaultResult( int.class, new Integer(0) ); @@ -46,7 +81,15 @@ setupDefaultResult( char.class, new Character('\0') ); setupDefaultResult( String.class, "" ); } - + + /** Returns an object that can be cast to any of the interfaces passed + * to this Mock's constructor. This Mock will mock the behaviour of + * calls to the proxy. + */ + public Object proxy() { + return _proxy; + } + /** Is the mock in strict mode? In strict mode the mock will throw * {@link junit.framework.AssertionFailedError} exceptions when * unexpected method calls are made. Otherwise, the mock ignore @@ -262,7 +305,7 @@ * {@link junit.framework.AssertionFailedError} will be thrown. */ public void order( String preceding_method, String subsequent_method ) { - methods.order(preceding_method, subsequent_method); + methods.order( preceding_method, subsequent_method ); } @@ -280,8 +323,7 @@ return super.equals(obj); } } - - + /** Called by the {@link java.lang.reflect.Proxy} to mock the behaviour of an * invoked method and check expectations. */ @@ -293,26 +335,28 @@ return getMatchingMethod(method).invoke( this, args ); } catch( NoSuchMethodException ex ) { - return mockCall(expectation, method, args ); + return mockCall( expectation, method, args ); } } - - protected Object mockCall(Method method, Object[] args ) + + protected Object mockCall( Method method, Object[] args ) throws Throwable { return mockCall(methods.startCall(method.getName()), method, args); } - - protected Object mockCall(MethodExpectation expectation, Method method, Object[] args ) + + protected Object mockCall( MethodExpectation expectation, + Method method, + Object[] args ) throws Throwable { if( expectation.canBeCalled() ) { return expectation.callAndCheckResult( method, args ); + } else { + assertTrue( "Unexpected call to " + method.getName(), + !_strict ); + return defaultResult( method.getReturnType() ); } - - assertTrue("Unexpected call to " + method.getName(), ! _strict); - - return defaultResult( method.getReturnType() ); } @@ -335,13 +379,9 @@ methods.verify(); } - public Object createInterface( Class interface_class ) { - return createInterface(interface_class, this); - } - - private Object createInterface(Class interface_class, InvocationHandler handler) { - return Proxy.newProxyInstance( interface_class.getClassLoader(), - new Class[]{ interface_class }, - handler ); + private Object createInterface( Class[] interface_classes ) { + return Proxy.newProxyInstance( getClass().getClassLoader(), + interface_classes, + this ); } } Index: MethodMap.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/MethodMap.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- MethodMap.java 5 Nov 2002 16:04:33 -0000 1.2 +++ MethodMap.java 6 Nov 2002 15:54:35 -0000 1.3 @@ -9,7 +9,9 @@ import java.util.HashMap; import java.util.Iterator; -public class MethodMap implements Verifiable { +public class MethodMap + implements Verifiable +{ private HashMap map = new HashMap(); public void setupCall(String methodName, MockCall call) { Index: MethodExpectation.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/MethodExpectation.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- MethodExpectation.java 5 Nov 2002 16:37:54 -0000 1.3 +++ MethodExpectation.java 6 Nov 2002 15:54:35 -0000 1.4 @@ -8,7 +8,9 @@ import com.mockobjects.ExpectationValue; import com.mockobjects.Verifiable; -public class MethodExpectation implements Verifiable { +public class MethodExpectation +implements Verifiable +{ final public String name; private ExpectationValue wasCalled; @@ -62,7 +64,14 @@ } private void checkResultType(Method method, Object result) { - Assert.assertTrue("trying to return " + result + " from void method " + method.getName(), - (result == Mock.VOID) == (method.getReturnType() == void.class)); + if( method.getReturnType() == void.class ) { + Assert.assertTrue( "trying to return " + result + + " from void method " + method.getName(), + result == Mock.VOID ); + } else { + Assert.assertTrue( "returning nothing from non-void method " + + method.getName(), + result != Mock.VOID ); + } } } |
From: Steve F. <sm...@us...> - 2002-11-06 08:52:48
|
Update of /cvsroot/mockobjects/mockobjects-java In directory usw-pr-cvs1:/tmp/cvs-serv1180 Removed Files: .cvsignore Log Message: Removed .cvsignore because it clashes with some local installations --- .cvsignore DELETED --- |
From: Steve F. <sm...@us...> - 2002-11-05 16:37:58
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory usw-pr-cvs1:/tmp/cvs-serv9550/src/core/com/mockobjects/dynamic Modified Files: Mock.java MethodExpectation.java Log Message: Cosmetic tweaks Index: Mock.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Mock.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- Mock.java 5 Nov 2002 16:27:29 -0000 1.9 +++ Mock.java 5 Nov 2002 16:37:54 -0000 1.10 @@ -271,12 +271,14 @@ * This version will unpack the inovaction handler if the * other object is a proxy. */ - public boolean equals(Object obj) { + public boolean equals(Object obj) + { try { return equals(Proxy.getInvocationHandler(obj)); - } catch (IllegalArgumentException ignored) { + } + catch (IllegalArgumentException notAProxy) { + return super.equals(obj); } - return super.equals(obj); } Index: MethodExpectation.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/MethodExpectation.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- MethodExpectation.java 5 Nov 2002 16:04:33 -0000 1.2 +++ MethodExpectation.java 5 Nov 2002 16:37:54 -0000 1.3 @@ -12,7 +12,7 @@ final public String name; private ExpectationValue wasCalled; - private MockCall call; + private MockCall mockCall; private MethodMap prerequisites = new MethodMap(); public MethodExpectation(String aName) { @@ -21,12 +21,12 @@ } public void expectCall(MockCall aCall) { - call = aCall; + mockCall = aCall; wasCalled.setExpected(true); } public void setupCall(MockCall aCall) { - call = aCall; + mockCall = aCall; initializeWasCalled(); } @@ -39,11 +39,11 @@ } public boolean canBeCalled() { - return call != null; + return mockCall != null; } public Object callAndCheckResult(Method method, Object[] args) throws Throwable { - Object result = call.call(args); + Object result = mockCall.call(args); checkResultType(method, result); return result; } |
From: Steve F. <sm...@us...> - 2002-11-05 16:27:32
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory usw-pr-cvs1:/tmp/cvs-serv4441/src/core/com/mockobjects/dynamic Modified Files: Mock.java Log Message: Added equals method that handles the other object being a proxy Index: Mock.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Mock.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- Mock.java 5 Nov 2002 16:04:32 -0000 1.8 +++ Mock.java 5 Nov 2002 16:27:29 -0000 1.9 @@ -265,6 +265,21 @@ methods.order(preceding_method, subsequent_method); } + + /** + * @see java.lang.Object#equals(java.lang.Object) + * This version will unpack the inovaction handler if the + * other object is a proxy. + */ + public boolean equals(Object obj) { + try { + return equals(Proxy.getInvocationHandler(obj)); + } catch (IllegalArgumentException ignored) { + } + return super.equals(obj); + } + + /** Called by the {@link java.lang.reflect.Proxy} to mock the behaviour of an * invoked method and check expectations. */ @@ -298,6 +313,7 @@ return defaultResult( method.getReturnType() ); } + private Method getMatchingMethod(Method method) throws NoSuchMethodException { @@ -326,5 +342,4 @@ new Class[]{ interface_class }, handler ); } - } |
From: Steve F. <sm...@us...> - 2002-11-05 16:27:04
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory usw-pr-cvs1:/tmp/cvs-serv4145a/src/core/test/mockobjects/dynamic Modified Files: MockTest.java Log Message: Added test for comparing an interface to itself Index: MockTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- MockTest.java 5 Nov 2002 16:02:04 -0000 1.3 +++ MockTest.java 5 Nov 2002 16:26:59 -0000 1.4 @@ -444,4 +444,9 @@ mock.verify(); } + + public void testEquals() { + assertEquals("Same interface should have same hashcode", _interface.hashCode(), _interface.hashCode()); + assertEquals("Same interface should be equal", _interface, _interface); + } } |
From: Steve F. <sm...@us...> - 2002-11-05 16:04:38
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory usw-pr-cvs1:/tmp/cvs-serv23805/src/core/com/mockobjects/dynamic Modified Files: Mock.java Added Files: MethodMap.java MethodExpectation.java Log Message: Refactored MethodExpectation and MethodMap out of Mock Index: Mock.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Mock.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- Mock.java 1 Nov 2002 15:35:40 -0000 1.7 +++ Mock.java 5 Nov 2002 16:04:32 -0000 1.8 @@ -6,7 +6,6 @@ import com.mockobjects.Verifiable; import junit.framework.Assert; -import junit.framework.AssertionFailedError; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; @@ -27,12 +26,8 @@ * have no methods. */ public static final Predicate[] NO_ARGS = new Predicate[0]; - - - private Map _expectations = new HashMap(); - private Set _not_called_expectations = new HashSet(); - private Map _order_constraints = new HashMap(); - private Set _called_methods = new HashSet(); + + protected MethodMap methods = new MethodMap(); private boolean _strict = false; private Map _default_results = new HashMap(); @@ -73,9 +68,7 @@ * The call to be mocked. */ public void setup( String method_name, MockCall call ) { - _expectations.put( method_name, call ); - _not_called_expectations.remove( method_name ); - _called_methods.add( method_name ); + methods.setupCall(method_name, call); } /** Set up calls to <var>method</var> to return <var>result</var>, @@ -127,9 +120,7 @@ * An object describing the expected call and mocking its behaviour. */ public void expect( String method_name, MockCall call ) { - _expectations.put( method_name, call ); - _not_called_expectations.remove( method_name ); - _called_methods.remove( method_name ); + methods.expectCall(method_name, call); } /** Expect a method call and return a result when it is called. @@ -257,11 +248,11 @@ * An {@link junit.framework.AssertionFailedError} will be thrown if * the method is called. * - * @param method + * @param methodName * The name of the method that will not be called. */ - public void expectNotCalled( String method ) { - _not_called_expectations.add(method); + public void expectNotCalled( String methodName ) { + methods.expectNotCalled(methodName); } /** @@ -271,13 +262,7 @@ * {@link junit.framework.AssertionFailedError} will be thrown. */ public void order( String preceding_method, String subsequent_method ) { - Set preceding_calls = orderConstraintsFor(subsequent_method); - if( null == preceding_calls) { - preceding_calls = new HashSet(); - _order_constraints.put( subsequent_method, preceding_calls ); - } - - preceding_calls.add( preceding_method ); + methods.order(preceding_method, subsequent_method); } /** Called by the {@link java.lang.reflect.Proxy} to mock the behaviour of an @@ -286,54 +271,37 @@ public Object invoke( Object obj, Method method, Object[] args ) throws Throwable { - _called_methods.add( method.getName() ); - + MethodExpectation expectation = methods.startCall(method.getName()); try { - return getClass().getMethod( - method.getName(), method.getParameterTypes() ).invoke( this, args ); + return getMatchingMethod(method).invoke( this, args ); } catch( NoSuchMethodException ex ) { - return mockCall( method, args ); + return mockCall(expectation, method, args ); } } - - protected Object mockCall( Method method, Object[] args ) + + protected Object mockCall(Method method, Object[] args ) throws Throwable { - String method_name = method.getName(); - - assertCanBeCalled( method_name ); - - if( _expectations.containsKey( method_name ) ) { - MockCall expected = (MockCall)_expectations.get(method_name); - - checkCallOrder( method_name ); - return checkResult(method, expected.call( args )); - - } else if( _strict ) { - throw new AssertionFailedError( - "unexpected call to " + method_name ); - } else { - return defaultResult( method.getReturnType() ); - } + return mockCall(methods.startCall(method.getName()), method, args); } - - private Object checkResult(Method method, Object result) { - if( method.getReturnType() == void.class && result != VOID ) { - fail("trying to return " + result + " from void method"); + + protected Object mockCall(MethodExpectation expectation, Method method, Object[] args ) + throws Throwable + { + if( expectation.canBeCalled() ) { + return expectation.callAndCheckResult( method, args ); } - return result; + assertTrue("Unexpected call to " + method.getName(), ! _strict); + + return defaultResult( method.getReturnType() ); } - private void checkCallOrder( String method_name ) { - if( _order_constraints.containsKey(method_name) ) { - assertMethodsHaveBeenCalled(orderConstraintsFor(method_name) ); - } - } - - private Set orderConstraintsFor(String method_name) { - return (Set)_order_constraints.get(method_name); + private Method getMatchingMethod(Method method) + throws NoSuchMethodException + { + return getClass().getMethod( method.getName(), method.getParameterTypes() ); } private Object defaultResult(Class return_type) { @@ -346,33 +314,9 @@ * Not all expected calls were made to this mock object. */ public void verify() { - assertAllExpectedMethodsCalled(); - } - - private void assertAllExpectedMethodsCalled() { - - assertMethodsHaveBeenCalled( _expectations.keySet() ); - } - - private void assertMethodsHaveBeenCalled( Set method_names ) { - Iterator i = method_names.iterator(); - while( i.hasNext() ) { - assertHasBeenCalled( (String)i.next() ); - } - } - - private void assertHasBeenCalled( String method_name ) { - if( !_called_methods.contains(method_name) ) { - fail( "method " + method_name + " was not called" ); - } + methods.verify(); } - private void assertCanBeCalled( String method_name ) { - if( _not_called_expectations.contains(method_name) ) { - fail( "unexpected call to method " + method_name ); - } - } - public Object createInterface( Class interface_class ) { return createInterface(interface_class, this); } |
From: Steve F. <sm...@us...> - 2002-11-05 16:03:43
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory usw-pr-cvs1:/tmp/cvs-serv23367/src/core/com/mockobjects/dynamic Modified Files: MockVoidCall.java Log Message: Layout and internal refactoring Fixed javadoc argument Index: MockVoidCall.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/MockVoidCall.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- MockVoidCall.java 31 Oct 2002 17:03:45 -0000 1.1 +++ MockVoidCall.java 5 Nov 2002 16:03:40 -0000 1.2 @@ -22,8 +22,6 @@ /** Constructs an <code>MockVoidCall</code> that accepts any arguments. - * - * @param name * The name of the expected method. */ public MockVoidCall() { @@ -32,8 +30,6 @@ /** Constructs a <code>MockVoidCall</code> that checks its arguments. * - * @param name - * The name of the expected method. * @param expected_args * Predicates that define the valid arguments of the method. */ @@ -57,12 +53,10 @@ private void checkArguments( Object[] args ) { int arg_count = (args == null) ? 0 : args.length; - assertEquals( "wrong number of arguments", - getArgumentCount(), arg_count ); + assertEquals( "wrong number of arguments", getArgumentCount(), arg_count ); for( int i = 0; i < arg_count; i++ ) { - Object arg = args[i]; - checkArgument(i, arg); + checkArgument( i, _expected_args[i], args[i]); } } @@ -70,12 +64,11 @@ return _expected_args.length; } - private void checkArgument( int i, Object arg ) { - if( !_expected_args[i].eval(arg) ) { - fail( "unexpected argument " + (i+1) + ": " + - ", expected " + describeArgument(i) + - ", was <" + arg + ">" ); - } + private void checkArgument( int i, Predicate expectedArg, Object arg ) { + assertTrue("argument " + (i+1) + "\n" + + "expected " + expectedArg + "\n" + + " was " + arg + "", + expectedArg.eval(arg) ); } public String describeArgument( int n ) { |
From: Steve F. <sm...@us...> - 2002-11-05 16:02:42
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects In directory usw-pr-cvs1:/tmp/cvs-serv22824/src/core/com/mockobjects Modified Files: AbstractExpectationCollection.java Log Message: Refactored out some common behaviour Index: AbstractExpectationCollection.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/AbstractExpectationCollection.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- AbstractExpectationCollection.java 30 Aug 2002 14:49:57 -0000 1.4 +++ AbstractExpectationCollection.java 5 Nov 2002 16:02:36 -0000 1.5 @@ -18,12 +18,7 @@ } public void addActual(int actualItem) { - Integer actualItemWrapper = new Integer(actualItem); - - getActualCollection().add(actualItemWrapper); - if (shouldCheckImmediately()) { - checkImmediateValues(actualItemWrapper); - } + addActual(new Integer(actualItem)); } public void addActualMany(Object[] items) { @@ -45,9 +40,7 @@ } public void addExpected(int expectedItem) { - Integer expectedItemWrapper = new Integer(expectedItem); - getExpectedCollection().add(expectedItemWrapper); - setHasExpectations(); + addExpected(new Integer(expectedItem)); } public void addExpected(Object expectedItem) { |
From: Steve F. <sm...@us...> - 2002-11-05 16:02:13
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory usw-pr-cvs1:/tmp/cvs-serv22570/src/core/test/mockobjects/dynamic Modified Files: MockTest.java Log Message: Fixed broken tests to use voidMethod(), rather than noArgs() Some layout Index: MockTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- MockTest.java 31 Oct 2002 17:03:46 -0000 1.2 +++ MockTest.java 5 Nov 2002 16:02:04 -0000 1.3 @@ -47,10 +47,8 @@ } public String objectTypes( Integer n ) throws Throwable { - Method method = getClass().getMethod("objectTypes", - new Class[] { Integer.class } ); - - return (String)mockCall( method , new Object[]{n} ); + Method method = getClass().getMethod("objectTypes", new Class[] { Integer.class } ); + return (String)mockCall(method , new Object[]{n} ); } }; @@ -186,9 +184,9 @@ } public void testCalledExpectationClearedBySubsequentExpecation() { - _mock.expectVoid( "noArgs", Mock.NO_ARGS ); - _interface.noArgs(); - _mock.expectVoid( "noArgs", Mock.NO_ARGS ); + _mock.expectVoid( "voidMethod", Mock.NO_ARGS ); + _interface.voidMethod(); + _mock.expectVoid( "voidMethod", Mock.NO_ARGS ); assertFails("verify did not fail when not all of the expected methods were called", new Runnable() { @@ -320,10 +318,10 @@ } public void testExpectNotCalledClearedBySubsequentExpectation() { - _mock.expectNotCalled("noArgs"); - _mock.expectVoid( "noArgs", Mock.NO_ARGS ); + _mock.expectNotCalled("voidMethod"); + _mock.expectVoid( "voidMethod", Mock.NO_ARGS ); - _interface.noArgs(); + _interface.voidMethod(); _mock.verify(); } |
From: Piran M. <pmo...@La...> - 2002-11-05 15:11:49
|
I'm trying to test some code that make sure something is done on a non-auto-committing connection. I.e., the code does this: if ( myConnection.getAutoCommit() == true ) { try { myConnection.setAutoCommit(false); doCode(); } finally { myConnection.setAutoCommit(true); } } else { doCode(); } But you've not implemented getAutoCommit. Below is a diff -u for the addition. BCNU, Piran Montford. --- CommonMockConnection.java Tue Nov 5 14:57:09 2002 +++ CommonMockConnection.java_old Tue Nov 5 15:00:58 2002 @@ -97,7 +97,7 @@ // -------------------------------------------------------------------- fields - private ExpectationValue myAutoCommitExpectation = + private ExpectationValue myAutoCommit = new ExpectationValue("CommonMockConnection.setAutoCommit"); private ExpectationCounter myCloseCalls = @@ -111,8 +111,6 @@ private boolean myIsClosed; - private boolean myAutoCommit = true; - private SQLException myCloseException; private SQLException myIsClosedException; @@ -154,7 +152,7 @@ * Register the anticipated value for autoCommit during testing. */ public void setExpectedAutoCommit(boolean autoCommit) { - myAutoCommitExpectation.setExpected(autoCommit); + myAutoCommit.setExpected(autoCommit); } @@ -341,20 +339,10 @@ /** * Stores the value passed for comparison with the value passed * to setupAutoCommit. - * The validate method will report any discrepency to the value - * set with {@link setExpectedAutoCommit} + * The validate method will report any discrepency. */ public void setAutoCommit(boolean autoCommit) throws SQLException { - myAutoCommitExpectation.setActual(autoCommit); - myAutoCommit = autoCommit; - } - - /** - * Gets the value last value set with {@link setAutoCommit}. - * Defaults to true. - */ - public boolean getAutoCommit() throws SQLException { - return myAutoCommit; + myAutoCommit.setActual(autoCommit); } // ------------------------------------------------------------ notImplemented @@ -378,6 +366,14 @@ } /** + * Calls notImplemented. Returns false. + */ + public boolean getAutoCommit() throws SQLException { + notImplemented(); + return false; + } + + /** * Calls notImplemented. Returns null. */ public String getCatalog() throws SQLException { ------------------------------ This e-mail is intended for the named addressee only. It may contain confidential and/or privileged information. If you have received this message in error, please let us know and then delete this message from your system. You should not copy the message, use it for any purpose or disclose its contents to anyone. ________________________________________________________________________ This e-mail has been scanned for all viruses by Star Internet. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________ |
From: Nat P. <nat...@b1...> - 2002-11-05 15:08:34
|
On Mon, 2002-11-04 at 20:43, Vincent Massol wrote: > > There are already default results for lots of types. I think the default > values should the ones defined by the JVM specification (which is null > for Objects). The idea behind the default return types is to avoid brittle or overspecified tests. If you want to test one particular interaction between two objects, you don't want to setup or expect irrelevant method calls so that the test doesn't break as you change other parts of the tested class. But conversely, you don't want your test to fail with an error because the class receives an invalid value from a called method. So the default return types are used to return safe but "empty" values from methods that have not been given explicit result values. Cheers, Nat. -- Dr. Nathaniel Pryce, Technical Director, B13media Ltd. Studio 3a, 22-24 Highbury Grove, London N5 2EA, UK http://www.b13media.com |
From: Jeff M. <je...@mk...> - 2002-11-05 09:57:08
|
I've plonked the patch in. Did make one change which was to change the verify method to use Verifier.verify(this); rather than having to verify each expectation. On Mon, 2002-11-04 at 23:21, Francois Beausoleil wrote: > Hi ! > > Simple patch to expect calls to flush(). > > I also reordered the methods so that all expectations are first, then the > overriden methods, and finally, the verify() method. > > Have a nice day ! > Francois Beausoleil > > Index: MockPrintWriter.java > =================================================================== > RCS file: > /cvsroot/mockobjects/mockobjects-java/src/jdk/common/com/mockobjects/io/MockPrintWriter.java,v > retrieving revision 1.2 > diff -u -r1.2 MockPrintWriter.java > --- MockPrintWriter.java 22 Aug 2002 09:33:44 -0000 1.2 > +++ MockPrintWriter.java 4 Nov 2002 23:19:00 -0000 > @@ -1,21 +1,22 @@ > package com.mockobjects.io; > > -import java.io.PrintWriter; > -import java.io.StringWriter; > -import java.io.Writer; > - > import com.mockobjects.ExpectationCounter; > import com.mockobjects.ExpectationSegment; > import com.mockobjects.Verifiable; > > +import java.io.PrintWriter; > +import java.io.StringWriter; > +import java.io.Writer; > + > > /** > * @author st...@m3... > + * @author Francois Beausoleil (fb...@us...) > */ > - > public class MockPrintWriter extends PrintWriter implements Verifiable { > private ExpectationSegment mySegment = new > ExpectationSegment("String segment"); > private ExpectationCounter myCloseCalls = new > ExpectationCounter("close calls"); > + private ExpectationCounter myFlushCalls = new > ExpectationCounter("flush calls"); > > public MockPrintWriter() { > this(new StringWriter()); > @@ -25,26 +26,35 @@ > super(writer); > } > > - public void close() { > - super.close(); > - myCloseCalls.inc(); > - } > - > public void setExpectedCloseCalls(int calls) { > myCloseCalls.setExpected(calls); > } > > + public void setExpectedFlushCalls(int calls) { > + myFlushCalls.setExpected(calls); > + } > + > public void setExpectedSegment(String aString) { > mySegment.setExpected(aString); > } > > - public void verify() { > - mySegment.verify(); > - myCloseCalls.verify(); > + public void flush() { > + super.flush(); > + myFlushCalls.inc(); > + } > + > + public void close() { > + super.close(); > + myCloseCalls.inc(); > } > > public void write(String s) { > super.write(s); > mySegment.setActual(s); > + } > + > + public void verify() { > + mySegment.verify(); > + myCloseCalls.verify(); > } > } > > -- > http://fastmail.fm - The holy hand grenade of email services > > > ------------------------------------------------------- > This SF.net email is sponsored by: ApacheCon, November 18-21 in > Las Vegas (supported by COMDEX), the only Apache event to be > fully supported by the ASF. http://www.apachecon.com > _______________________________________________ > Mockobjects-java-dev mailing list > Moc...@li... > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev -- jeff martin information technologist mkodo limited mobile: 44 (0) 78 5547 8331 phone: 44 (0) 20 2226 4545 email: je...@mk... www.mkodo.com |
From: Jeff M. <cus...@us...> - 2002-11-05 09:55:38
|
Update of /cvsroot/mockobjects/mockobjects-java/src/jdk/common/com/mockobjects/io In directory usw-pr-cvs1:/tmp/cvs-serv6353/mockobjects/io Modified Files: MockPrintWriter.java Log Message: Added support for counting flushes patch provided by Francois Beausoleil Index: MockPrintWriter.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/jdk/common/com/mockobjects/io/MockPrintWriter.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- MockPrintWriter.java 22 Aug 2002 09:33:44 -0000 1.2 +++ MockPrintWriter.java 5 Nov 2002 09:55:35 -0000 1.3 @@ -7,15 +7,18 @@ import com.mockobjects.ExpectationCounter; import com.mockobjects.ExpectationSegment; import com.mockobjects.Verifiable; +import com.mockobjects.util.Verifier; /** * @author st...@m3... + * @author Francois Beausoleil (fb...@us...) */ public class MockPrintWriter extends PrintWriter implements Verifiable { private ExpectationSegment mySegment = new ExpectationSegment("String segment"); private ExpectationCounter myCloseCalls = new ExpectationCounter("close calls"); + private ExpectationCounter myFlushCalls = new ExpectationCounter("flush calls"); public MockPrintWriter() { this(new StringWriter()); @@ -25,11 +28,6 @@ super(writer); } - public void close() { - super.close(); - myCloseCalls.inc(); - } - public void setExpectedCloseCalls(int calls) { myCloseCalls.setExpected(calls); } @@ -38,13 +36,26 @@ mySegment.setExpected(aString); } - public void verify() { - mySegment.verify(); - myCloseCalls.verify(); - } - public void write(String s) { super.write(s); mySegment.setActual(s); + } + + public void setExpectedFlushCalls(int calls) { + myFlushCalls.setExpected(calls); + } + + public void flush() { + super.flush(); + myFlushCalls.inc(); + } + + public void close() { + super.close(); + myCloseCalls.inc(); + } + + public void verify() { + Verifier.verifyObject(this); } } |
From: Jeff M. <je...@mk...> - 2002-11-05 09:39:42
|
Works okay for me ;) On Mon, 2002-11-04 at 20:59, Steve Freeman wrote: > From: "Vincent Massol" <vm...@oc...> > > > From: moc...@li... > > > [mailto:moc...@li...] On Behalf Of > > > Steve Freeman > > > Sent: 03 November 2002 11:39 > > > To: 'MockObjects' > > > Subject: Re: [MO-java-dev] Building the core library problem + version > > > number issue > > > > > > I can't reproduce that. The src archive might be out of date, so I'll > put another one up. > > > > I'm actually talking about building from CVS. Try it: make a clean > > checkout somewhere and run "ant", you should get the same error. > > I just did and it ran fine, both 1.3.1 and 1.4.1. Can you check the class > AbstractExpectationCollection and see if it's got the relevant method? It > should have. > > > > Well, I thought it would make the numbers line up better. I've just > changed > > > the formatting, not the value. > > > > I can tell you it looks very strange when on SF you look at the > > downloadable versions and see 0.2, 0.3, 0.4, 0.5, 0.6 and 0.07, because > > mathematically 0.07 < 0.6 (I do understand the point about 0.07 not > > being a number but nevertheless it will cause confusion - it already > > has! :-)). > > I'm half inclined just to set the date yyyymmdd, but that would get a bit > long. I'm not sure we have clean enough releases to justify major/minor > versions. > > S. > > > > > > > ------------------------------------------------------- > This SF.net email is sponsored by: ApacheCon, November 18-21 in > Las Vegas (supported by COMDEX), the only Apache event to be > fully supported by the ASF. http://www.apachecon.com > _______________________________________________ > Mockobjects-java-dev mailing list > Moc...@li... > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev -- jeff martin information technologist mkodo limited mobile: 44 (0) 78 5547 8331 phone: 44 (0) 20 2226 4545 email: je...@mk... www.mkodo.com |