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: Tim M. <tim...@po...> - 2003-04-06 22:25:35
|
Guys - in the background I am still trying to work out how to simplify the usage of the mock objects library for users of IDE's. If I am using an ide - what source tree's am I supposed to include, the rules seem very unclear to me? If I am using jdk1.4 I would expect to include: /src/jdk/1.4 /src/jdk/common /src/j2ee/1.4 /src/2jee/common but if I do this I am missing classes. If I incclude both 1.3 and 1.4 I get conflicts - the best I appear to be able to do is: /src/jdk/1.4 /src/jdk/common /src/j2ee/1.3 /src/2jee/common But then the examples break because I guess the mailing list example uses something in j2ee/1.4? --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.467 / Virus Database: 266 - Release Date: 01/04/2003 |
From: Tim M. <ma...@us...> - 2003-04-06 22:19:56
|
Update of /cvsroot/mockobjects/mockobjects-java/src/examples/com/mockobjects/examples/password In directory sc8-pr-cvs1:/tmp/cvs-serv2490/src/examples/com/mockobjects/examples/password Modified Files: MailingException.java Log Message: Fixed incorrect package declaration Index: MailingException.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/examples/com/mockobjects/examples/password/MailingException.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- MailingException.java 17 Nov 2001 10:17:17 -0000 1.1 +++ MailingException.java 6 Apr 2003 22:19:53 -0000 1.2 @@ -1,4 +1,4 @@ -package src.examples.com.mockobjects.examples.password; +package com.mockobjects.examples.password; public class MailingException extends Exception { public MailingException() { |
From: Tim M. <ma...@us...> - 2003-04-04 16:55:52
|
Update of /cvsroot/mockobjects/mockobjects-java/src/examples/com/mockobjects/examples/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv21735/src/examples/com/mockobjects/examples/dynamic Log Message: Directory /cvsroot/mockobjects/mockobjects-java/src/examples/com/mockobjects/examples/dynamic added to the repository --> Using per-directory sticky tag `DynamicMockExperiment' |
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv21824/src/core/com/mockobjects/dynamic Modified Files: Tag: DynamicMockExperiment Mock.java C.java Added Files: Tag: DynamicMockExperiment CallMocker.java CallSet.java SingleCall.java Removed Files: Tag: DynamicMockExperiment MockCall.java MockThrowCall.java CallCounter.java CallBag.java MockReturnCall.java AbstractMockCall.java CallSequence.java CallCollection.java MethodExpectation.java MethodMap.java MockVoidCall.java Log Message: First stab at dynamic mocks with named calls etc. --- NEW FILE: CallMocker.java --- /* * Created on 04-Apr-2003 */ package com.mockobjects.dynamic; import com.mockobjects.*; public interface CallMocker extends Verifiable { Object call( Mock mock, String methodName, Object[] args ) throws Throwable; boolean matches(String methodName, Object[] args); } --- NEW FILE: CallSet.java --- /* * Created on 04-Apr-2003 */ package com.mockobjects.dynamic; import java.util.*; /** * @author dev */ public class CallSet implements CallMocker { private List expectedCalls = new ArrayList(); public CallSet() { super(); // dodgy Auto-generated constructor stub } public Object call(Mock mock, String methodName, Object[] args) throws Throwable { for (Iterator call = expectedCalls.iterator(); call.hasNext();) { CallMocker element = (CallMocker) call.next(); if(element.matches(methodName, args)) { return element.call(mock, methodName, args); } } return null; } public void verify() { for (Iterator call = expectedCalls.iterator(); call.hasNext();) { CallMocker element = (CallMocker) call.next(); element.verify(); } } public void add(CallMocker call) { expectedCalls.add(call); } public boolean matches(String methodName, Object[] args) { return false; } } --- NEW FILE: SingleCall.java --- /* * Created on 04-Apr-2003 * * To change this generated comment go to * Window>Preferences>Java>Code Generation>Code and Comments */ package com.mockobjects.dynamic; import junit.framework.*; import com.mockobjects.constraint.*; import com.mockobjects.util.*; public class SingleCall extends Assert implements CallMocker { private String methodName; private Constraint[] constraints; private boolean wasCalled = false; public SingleCall( String methodName, Constraint[] constraints ) { this.methodName = methodName; this.constraints = (Constraint[])constraints.clone(); } public Object call( Mock mock, String methodName, Object[] args ) throws Throwable { assertFalse( methodName + " has already been called", wasCalled ); assertEquals( methodName + " received the wrong number of arguments", constraints.length, args.length ); for( int i = 0; i < args.length; i++ ) { if( !constraints[i].eval(args[i]) ) { throw new AssertionFailedError( AssertMo.expectedErrorMessage( methodName + " received incorrect argument " + i, AssertMo.join(constraints), AssertMo.join(args) ) ); } } wasCalled = true; return null; } public void verify() { if( !wasCalled ) { throw new AssertionFailedError( methodName + " was not called" ); } } public boolean matches(String methodName, Object[] args) { if( !this.methodName.equals(methodName) ) return false; if( args.length != constraints.length ) return false; for (int i = 0; i < args.length; i++) { if( !constraints[i].eval(args[i]) ) return false; } return true; } } Index: Mock.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Mock.java,v retrieving revision 1.16 retrieving revision 1.16.2.1 diff -u -r1.16 -r1.16.2.1 --- Mock.java 24 Nov 2002 11:01:00 -0000 1.16 +++ Mock.java 4 Apr 2003 16:47:34 -0000 1.16.2.1 @@ -1,461 +1,72 @@ -/* Copyright (c) 2002 Nat Pryce. All rights reserved. +/* + * Created on 04-Apr-2003 * - * Created on February 10, 2002, 11:06 PM */ package com.mockobjects.dynamic; -import com.mockobjects.Verifiable; -import com.mockobjects.constraint.*; +import java.lang.reflect.*; -import junit.framework.Assert; +import junit.framework.*; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; -import java.util.*; +import com.mockobjects.*; - -/** A convenient class for creating simple - * <a href="http://www.mockobjects.com">mock objects</a>. +/** + * @author dev */ -public class Mock - extends Assert - implements InvocationHandler, Verifiable -{ - public static final Object VOID = new Object(); - - /** A convenient constant for defining expectations for methods that - * have no methods. - */ - public static final Constraint[] NO_ARGS = new Constraint[0]; - - - private Class[] _proxy_classes; - private Object _proxy; - private MethodMap methods = new MethodMap(); - private boolean _strict = false; - - private Map _default_results = new HashMap(); - - - /** 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( Class[] interfaces_to_mock ) { - _proxy_classes = (Class[])interfaces_to_mock.clone(); - _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) ); - setupDefaultResult( long.class, new Long(0L) ); - setupDefaultResult( float.class, new Float(0.0f) ); - setupDefaultResult( double.class, new Double(0.0d) ); - setupDefaultResult( boolean.class, Boolean.FALSE ); - 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 - * the call or return default arguments. - */ - public boolean isStrict() { - return _strict; - } - - public void setStrict( boolean strict ) { - _strict = strict; - } - - /** Mock the behaviour of a method without requiring that the method - * actually be called. Note: the ExpectedCall may check the arguments - * of the call but should usually not do so. - * - * @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 ); - methods.setupCall( method_name, call ); - } - - /** Set up calls to <var>method</var> to return <var>result</var>, - * but do not define any expectations upon arguments to those calls. - * Arguments of calls to <var>method</var> will be ignored. - * - * @param method_name - * The name of the method that will be called. - * @param result - * 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 ) ); - } - - /** Set up calls to <var>method</var> to throw <var>exception</var>, - * but do not define any expectations upon arguments to those calls. - * Arguments of calls to <var>method</var> will be ignored. - * - * @param method_name - * 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 ) ); - } - - /** Set up the value returned by methods that have the given result - * type, if no result or exception has been explicitly defined for - * the called method by {@link #setupResult}, {@link #setupThrow}, - * {@link #expectReturn} or {@link #expectThrow}. - * - * @param result_type - * The result type of methods to be mocked. - * @param result_value - * The default value returned by mocked methods that return values - * of type <var>result_type</var>. - */ - public void setupDefaultResult( Class result_type, Object result_value ) { - _default_results.put( result_type, result_value ); - } - - /** Expect a method call and mock the behaviour of that call. - * - * @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 ); - methods.expectCall( method_name, call ); - } - - /** Expect a method call and return a result when it is called. - * - * @param method - * The name of the method that will be called. - * @param args - * 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 - * 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 expectAndReturn( String method, Constraint[] args, Object result ) { - expect( method, new MockReturnCall( args, result ) ); - } - - /** Expect a method call and return a result when it is called. - * - * @param method - * The name of the method that will be called. - * @param arg - * An single object that will be compared with predicate eq() - * @param result - * 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 expectAndReturn( String method, Object arg, Object result ) { - expectAndReturn( method, C.args(C.eq(arg) ), result); - } - - /** Expect a method call with no parameters and return a result when it is called. - * - * @param method - * The name of the method that will be called. - * @param result - * 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 expectAndReturn( String method, Object result ) { - expectAndReturn( method, NO_ARGS, result ); - } - - /** - * Expect a call to a method with a void return type. - * - * @param method - * The name of the method that will be called. - * @param args - * 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, Constraint[] args ) { - expect( method, new MockVoidCall( args ) ); - } - - /** - * Expect a call to a method with a void return type. - * - * @param method - * 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, C.args(C.eq(arg)) ); - } - - /** - * Expect a call to a method with a void return type and no parameters - * - * @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 ); - } - - /** Expect a method call and throw an exception or error when it is called. - * - * @param method - * The name of the method that will be called. - * @param args - * 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. - * @throws junit.framework.AssertionFailedError - * The method name is not the name of a method mocked by this - * Mock object. - */ - public void expectAndThrow( String method, Constraint[] args, Throwable exception ) { - expect( method, new MockThrowCall( args, exception ) ); - } - - /** Expect a method call and throw an exception or error when it is called. - * - * @param method - * The name of the method that will be called. - * @param arg - * 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 expectAndThrow( String method, Object arg, Throwable exception ) { - expectAndThrow( method, C.args(C.eq(arg)), exception ); - } - - /** Expect a method call with no parameters and throw an exception or error when it is called. - * - * @param method - * 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 expectAndThrow( String method, Throwable exception ) { - expectAndThrow( method, NO_ARGS, exception ); - } - - /** 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 method_name ) { - checkMethodName( method_name ); - methods.expectNotCalled(method_name); - } - - /** 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 - * 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 ); - } - - - /** - * @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 notAProxy) { - return super.equals(obj); - } - } - - /** Called by the {@link java.lang.reflect.Proxy} to mock the behaviour of an - * invoked method and check expectations. - */ - public Object invoke( Object obj, Method method, Object[] args ) - throws Throwable - { - MethodExpectation expectation = methods.startCall(method.getName()); - try { - return getMatchingMethod(method).invoke( this, args ); - } - catch( NoSuchMethodException ex ) { - return mockCall( expectation, method, 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 ) - throws Throwable - { - if( expectation.canBeCalled() ) { - return expectation.callAndCheckResult( method, args ); - } else { - assertTrue( "unexpected call to "+method.getName(), !_strict ); - return defaultResult( method.getReturnType() ); - } - } - - - private Method getMatchingMethod(Method method) - throws NoSuchMethodException - { - return getClass().getMethod( method.getName(), method.getParameterTypes() ); - } - - private Object defaultResult(Class return_type) { - return _default_results.get(return_type); - } - - /** - * Fails if not all the expected calls have been made to this mock object. - * @throws junit.framework.AssertionFailedError - * Not all expected calls were made to this mock object. - */ - public void verify() { - methods.verify(); - } - - private Object createInterface( Class[] interface_classes ) { - 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; - } +public class Mock implements Verifiable, InvocationHandler { + private String name; + private Object proxy; + private CallMocker call; + + + public Mock( Class mockedClass, String name) { + this.name = name; + this.proxy = Proxy.newProxyInstance( getClass().getClassLoader(), + new Class[] { mockedClass }, + this ); + } + + public Mock( Class mockedClass ) { + this( mockedClass, mockNameFromClass(mockedClass) ); + } + + public static String mockNameFromClass( Class c ) { + String name = c.getName(); + int dotIndex = name.lastIndexOf('.'); + if( dotIndex >= 0 ) { + return "mock-" + name.substring(dotIndex + 1 ); + } else { + return "mock-" + name; + } + } + + public Object proxy() { + return proxy; + } + + public Object invoke( Object proxy, Method method, Object[] args ) + throws Throwable + { + try { + return call.call( this, method.getName(), (args == null ? new Object[0] : args) ); + } + catch( AssertionFailedError ex ) { + throw new AssertionFailedError( name + ": " + ex.getMessage() ); + } + } + + public void expect(CallMocker mocker) { + call = mocker; + } + + public void verify() { + if( call != null ) { + try { + call.verify(); + } + catch( AssertionFailedError ex ) { + throw new AssertionFailedError( name + ": " + ex.getMessage() ); + } + } + } } Index: C.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/C.java,v retrieving revision 1.1 retrieving revision 1.1.2.1 diff -u -r1.1 -r1.1.2.1 --- C.java 24 Nov 2002 10:59:29 -0000 1.1 +++ C.java 4 Apr 2003 16:47:38 -0000 1.1.2.1 @@ -19,7 +19,7 @@ public static final Constraint IS_ZERO = eq(new Integer(0)); public static final Constraint IS_NOT_ZERO = not(IS_ZERO); - public static final Constraint[] ANY_ARGS = MockVoidCall.ANY_ARGS; + public static final Constraint[] ANY_ARGS = null; public static Constraint same( Object o ) { @@ -94,7 +94,7 @@ */ public static Constraint[] args() { - return Mock.NO_ARGS; + return new Constraint[0]; } public static Constraint[] args(Constraint p) { --- MockCall.java DELETED --- --- MockThrowCall.java DELETED --- --- CallCounter.java DELETED --- --- CallBag.java DELETED --- --- MockReturnCall.java DELETED --- --- AbstractMockCall.java DELETED --- --- CallSequence.java DELETED --- --- CallCollection.java DELETED --- --- MethodExpectation.java DELETED --- --- MethodMap.java DELETED --- --- MockVoidCall.java DELETED --- |
From: Tim M. <ma...@us...> - 2003-04-04 16:47:45
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/util In directory sc8-pr-cvs1:/tmp/cvs-serv21824/src/core/com/mockobjects/util Modified Files: Tag: DynamicMockExperiment AssertMo.java Log Message: First stab at dynamic mocks with named calls etc. Index: AssertMo.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/util/AssertMo.java,v retrieving revision 1.2 retrieving revision 1.2.4.1 diff -u -r1.2 -r1.2.4.1 --- AssertMo.java 25 Oct 2002 22:06:09 -0000 1.2 +++ AssertMo.java 4 Apr 2003 16:47:41 -0000 1.2.4.1 @@ -99,4 +99,23 @@ } fail(message); } + + public static String join( Object[] elements ) { + StringBuffer buf = new StringBuffer(); + + for (int i = 0; i < elements.length; i++) { + if( i > 0 ) buf.append(", "); + buf.append( "<" ); + buf.append( elements[i].toString() ); + buf.append( ">" ); + } + + return buf.toString(); + } + + public static String expectedErrorMessage(String description, String expectedMsg, String receivedMsg) { + return description + ":\n" + + "\tExpected: " + expectedMsg + "\n" + + "\tReceived: " + receivedMsg + "\n"; + } } |
From: Tim M. <ma...@us...> - 2003-04-04 16:47:44
|
Update of /cvsroot/mockobjects/mockobjects-java/src/examples/com/mockobjects/examples/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv21824/src/examples/com/mockobjects/examples/dynamic Added Files: Tag: DynamicMockExperiment SimpleServletTest.java SimpleServlet.java Log Message: First stab at dynamic mocks with named calls etc. --- NEW FILE: SimpleServletTest.java --- /* * Created on 04-Apr-2003 * * To change this generated comment go to * Window>Preferences>Java>Code Generation>Code and Comments */ package com.mockobjects.examples.dynamic; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import com.mockobjects.constraint.*; import com.mockobjects.dynamic.*; import junit.framework.*; /** * @author dev * * To change this generated comment go to * Window>Preferences>Java>Code Generation>Code and Comments */ public class SimpleServletTest extends TestCase { public SimpleServletTest(String name) { super(name); } // public void testDoGet() throws ServletException, IOException { // Mock mockHttpServletResponse = new Mock(HttpServletResponse.class); // Mock mockHttpServletRequest = new Mock(HttpServletRequest.class); // // //CallSequence calls = new CallSequence(); // //calls.add("getParameter", "body", "this is the body"); // //calls.add("getParameter", "subject", "mail from tim"); // //calls.add("getParameterValues", "recipients", new String[] {"na...@te...", "st...@mp..."} ); // // CallSequence params = new CallSequence(); // params.expectAndReturn( new Constraint[] { C.eq("body") }, "this is the body" ); // params.expectAndReturn( new Constraint[] { C.eq("subject") }, "mail from tim" ); // params.expectAndReturn( new Constraint[] { C.eq("recipients") }, new String[] { "nat...@b1...", "st...@m3..." } ); // // mockHttpServletRequest.expect( "getParameter", params ); // // SimpleServlet aServlet = new SimpleServlet(); // aServlet.doGet((HttpServletRequest) mockHttpServletRequest.proxy(), (HttpServletResponse) mockHttpServletResponse.proxy()); // // mockHttpServletRequest.verify(); // mockHttpServletResponse.verify(); // } public void testDoGetNew() throws ServletException, IOException { Mock mockHttpServletResponse = new Mock(HttpServletResponse.class, "response"); Mock mockHttpServletRequest = new Mock(HttpServletRequest.class); mockHttpServletRequest.expect( new SingleCall( "getParameter", C.args(C.eq("subject")) ) ); mockHttpServletRequest.expect( new SingleCall( "getParameter", C.args(C.eq("body")) ) ); // mockHttpServletRequest.expect( "getParameter", "subject"); //.returnValue("mail subject"); //mockHttpServletRequest.expect( "getParameter", "body").returnValue("mail body"); //mockHttpServletRequest.expect( "getParameter", "recipients").returnValue( new String[] { "person1", "person2" } ); final StringWriter contentWriter = new StringWriter(); mockHttpServletResponse.expect( new SingleCall( "setContentType", C.args(C.eq("text/html")) ) ); //mockHttpServletResponse.expect( "getWriter" ).returnValue( contentWriter ); SimpleServlet aServlet = new SimpleServlet(); aServlet.doGet((HttpServletRequest) mockHttpServletRequest.proxy(), (HttpServletResponse) mockHttpServletResponse.proxy()); mockHttpServletRequest.verify(); mockHttpServletResponse.verify(); } } --- NEW FILE: SimpleServlet.java --- /* * Created on 04-Apr-2003 * */ package com.mockobjects.examples.dynamic; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; /** * @author dev */ public class SimpleServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //super.doGet(arg0, arg1); String subject = request.getParameter("subjectx"); } } |
From: Tim M. <ma...@us...> - 2003-04-04 16:47:44
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv21824/src/core/test/mockobjects/dynamic Modified Files: Tag: DynamicMockExperiment MockTest.java Added Files: Tag: DynamicMockExperiment TestInterface.java TestThrowable.java SingleCallTest.java TestConstraint.java CallSetTest.java Removed Files: Tag: DynamicMockExperiment CallCollectionTest.java CallCounterTest.java Log Message: First stab at dynamic mocks with named calls etc. --- NEW FILE: TestInterface.java --- /* * Created on 04-Apr-2003 */ package test.mockobjects.dynamic; /** * @author dev */ public interface TestInterface { public String aMethod( String arg1, String arg2 ) throws Throwable; public void aMethodWithNoArguments(); } --- NEW FILE: TestThrowable.java --- /* * Created on 04-Apr-2003 */ package test.mockobjects.dynamic; /** * @author dev */ public class TestThrowable extends Throwable { public TestThrowable() { super(); } public TestThrowable(String message) { super(message); } public TestThrowable(String message, Throwable cause) { super(message, cause); } public TestThrowable(Throwable cause) { super(cause); } } --- NEW FILE: SingleCallTest.java --- /* * Created on 04-Apr-2003 * * To change this generated comment go to * Window>Preferences>Java>Code Generation>Code and Comments */ package test.mockobjects.dynamic; import com.mockobjects.constraint.*; import com.mockobjects.dynamic.*; import com.mockobjects.util.*; import junit.framework.*; public class SingleCallTest extends TestCase { final String methodName = "methodName"; Mock mock = new Mock(TestInterface.class,"mock"); SingleCall call; public SingleCallTest(String name) { super(name); } public void testUncalledCallDoesNotVerify() { final String methodName = "methodName"; SingleCall call = new SingleCall(methodName, C.args() ); try { call.verify(); } catch( AssertionFailedError ex ) { AssertMo.assertIncludes("should include call name", methodName, ex.getMessage() ); return; } fail("expected verify to fail"); } public void testSuccessfulCallVerifies() throws Throwable { SingleCall call = new SingleCall("methodName", C.args() ); call.call( mock, "methodName", new Object[0] ); call.verify(); } public void testMultipleCallsFail() throws Throwable { SingleCall call = new SingleCall(methodName, C.args() ); call.call( mock, methodName, new Object[0] ); try { call.call( mock, methodName, new Object[0] ); } catch( AssertionFailedError ex ) { AssertMo.assertIncludes("should include call name", methodName, ex.getMessage() ); return; } fail("expected second call to fail"); } public void testArgumentsCheckedAgainstConstraints() throws Throwable { String[] args = { "arg1", "arg2", "arg3" }; TestConstraint[] constraints = { new TestConstraint( "constraint1", args[0], true ), new TestConstraint( "constraint2", args[1], true ), new TestConstraint( "constraint3", args[2], true ) }; SingleCall call = new SingleCall( methodName, (Constraint[])constraints ); call.call( mock, methodName, args ); for( int i = 0; i < constraints.length; i++ ) { constraints[i].verify(); } } public void testWrongNumberOfArguments() throws Throwable { String[] args = { "arg1", "arg2" }; TestConstraint[] constraints = { new TestConstraint( "constraint1", args[0], true ), new TestConstraint( "constraint2", args[1], true ), new TestConstraint( "constraint3", args[1], true ) }; SingleCall call = new SingleCall( methodName, (Constraint[])constraints ); boolean passed = true; try { call.call( mock, methodName, args ); passed = false; } catch (AssertionFailedError ex) { AssertMo.assertIncludes("Should show expected number of arguments", Integer.toString(constraints.length), ex.getMessage()); AssertMo.assertIncludes("Should show actual number of arguments", Integer.toString(args.length), ex.getMessage()); AssertMo.assertIncludes("Should include the method name", methodName, ex.getMessage()); } assertTrue("Should fail is call doesn't give an exception", passed); } public void testConstraintFailure() throws Throwable { String[] args = { "argA", "argB", "argC" }; TestConstraint[] constraints = { new TestConstraint( "constraintA", args[0], true ), new TestConstraint( "constraintB", args[1], false ), new TestConstraint( "constraintC", args[2], true ) }; SingleCall call = new SingleCall( methodName, (Constraint[])constraints ); boolean passed = true; try { call.call( mock, methodName, args ); passed = false; } catch (AssertionFailedError ex) { AssertMo.assertIncludes("Should include the method name", methodName, ex.getMessage()); AssertMo.assertIncludes("Should show index of failed argument", "1", ex.getMessage() ); AssertMo.assertIncludes("Should show expected arguments", AssertMo.join(constraints), ex.getMessage()); AssertMo.assertIncludes("Should show actual arguments", AssertMo.join(args), ex.getMessage()); } assertTrue("Should fail is call doesn't give an exception", passed); } public void testCallMatchesArguments() throws Throwable { String[] args = { "arg1", "arg2", "arg3" }; TestConstraint[] constraints = { new TestConstraint( "constraint1", args[0], true ), new TestConstraint( "constraint2", args[1], true ), new TestConstraint( "constraint3", args[2], true ) }; SingleCall call = new SingleCall( methodName, (Constraint[])constraints ); assertTrue( "call matches", call.matches( methodName, args) ); } public void testCallDoesNotMatchWhenWrongName() throws Throwable { SingleCall call = new SingleCall( methodName, new Constraint[0] ); assertFalse( "call does not match", call.matches( "anotherName", new Object[0]) ); } public void testCallDoesNotMatchWhenWrongNumberOfArguments() throws Throwable { String[] args = { "arg1", "arg2" }; TestConstraint[] constraints = { new TestConstraint( "constraint1", args[0], true ), new TestConstraint( "constraint2", args[1], true ), new TestConstraint( "constraint3", args[1], true ) }; SingleCall call = new SingleCall( methodName, (Constraint[])constraints ); assertFalse( "call does not match", call.matches( methodName, args) ); } public void testCallDoesNotMatchWhenConstraintIsViolated() throws Throwable { String[] args = { "argA", "argB", "argC" }; TestConstraint[] constraints = { new TestConstraint( "constraintA", args[0], true ), new TestConstraint( "constraintB", args[1], false ), new TestConstraint( "constraintC", args[2], true ) }; SingleCall call = new SingleCall( methodName, (Constraint[])constraints ); assertFalse( "call does not match", call.matches( methodName, args) ); } } --- NEW FILE: TestConstraint.java --- /* * Created on 04-Apr-2003 */ package test.mockobjects.dynamic; import junit.framework.*; import com.mockobjects.*; import com.mockobjects.constraint.*; /** * @author dev */ public class TestConstraint extends Assert implements Constraint, Verifiable { private String description; private Object expectedArg; private boolean result; private boolean wasChecked = false; public TestConstraint( String description, Object expectedArg, boolean result ) { this.description = description; this.expectedArg = expectedArg; this.result = result; } public String toString() { return description; } public boolean eval( Object o ) { assertSame( "should be expected argument", expectedArg, o ); wasChecked = true; return result; } public void verify() { assertTrue( description + " should have been checked", wasChecked ); } } --- NEW FILE: CallSetTest.java --- /* * Created on 04-Apr-2003 */ package test.mockobjects.dynamic; import com.mockobjects.dynamic.*; import junit.framework.*; /** * @author dev */ public class CallSetTest extends TestCase { private CallSet callSet = new CallSet(); private Mock unusedMock = null; public CallSetTest(String name) { super(name); } public void testEmptySetVerifies() throws Exception { callSet.verify(); } public void testSingleItemNotCalledFails() throws Exception { callSet.add(new SingleCall("methodThatWontBeCalled",C.args())); try { callSet.verify(); } catch (AssertionFailedError ex) { return; } fail("Should have got a failure for a method that wasn't called"); } public void testSingleItemCalledSuccessfully() throws Throwable { callSet.add(new SingleCall("methodThatWillBeCalled",C.args())); callSet.call( unusedMock, "methodThatWillBeCalled", new Object[0] ); callSet.verify(); } public void testTwoItemsCalledSameOrder() throws Throwable { callSet.add(new SingleCall("methodA",C.args())); callSet.add(new SingleCall("methodB",C.args())); callSet.call( unusedMock, "methodA", new Object[0] ); callSet.call( unusedMock, "methodB", new Object[0] ); callSet.verify(); } } Index: MockTest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic/MockTest.java,v retrieving revision 1.8 retrieving revision 1.8.2.1 diff -u -r1.8 -r1.8.2.1 --- MockTest.java 12 Nov 2002 17:42:38 -0000 1.8 +++ MockTest.java 4 Apr 2003 16:47:39 -0000 1.8.2.1 @@ -1,563 +1,222 @@ -/* Copyright (c) 2002 Nat Pryce. All rights reserved. - * - * Created on February 11, 2002, 12:34 AM +/* + * Created on 04-Apr-2003 + * + * To change this generated comment go to + * Window>Preferences>Java>Code Generation>Code and Comments */ package test.mockobjects.dynamic; -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; +import com.mockobjects.util.*; + +import junit.framework.*; + +/** + * @author dev + * + * To change this generated comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public class MockTest extends TestCase { + private Mock aMock; + private TestInterface proxy; + private static final String MOCK_NAME = "Test mock"; + + public MockTest(String name) { + super(name); + } + + public void setUp() { + aMock = new Mock( TestInterface.class, MOCK_NAME ); + try { + proxy = (TestInterface)aMock.proxy(); + } + catch( ClassCastException ex ) { + fail("proxy is not of expected interface type"); + } + } + + public void testNewMockVerifies() throws Exception { + aMock.verify(); + } + + public void testMockNameFromClass() throws Exception { + assertEquals( "mock-String", Mock.mockNameFromClass(String.class) ); + } + + public void testVerifyFailsIfExpectedCallNotCalled() throws Throwable { + aMock.expect( new CallMocker() { + public void verify() { throw new AssertionFailedError("example error"); } + public boolean matches(String methodName, Object[] args) { + return false; + } + public Object call(Mock mock, String methodName, Object[] args) { + return null; + } + } ); + + try { + aMock.verify(); + } + catch( AssertionFailedError ex ) { + AssertMo.assertIncludes( "mock name should be in exception message", + MOCK_NAME, ex.getMessage() ); + return; + } + fail("verify should have failed"); + } + + public void testVerifiesIfExpectedCallIsCalled() throws Throwable { + aMock.expect( new CallMocker() { + public void verify() {} + public boolean matches(String methodName, Object[] args) { + return false; + } + + public Object call(Mock mock, String methodName, Object[] args) { + return null; + } + } ); + + proxy.aMethod( "hello", "world" ); + aMock.verify(); + } + + public void testCallMockerReceivesArgumentsFromProxy() throws Throwable { + final String[] expectedArgs = { "hello", "world" }; + final String[] receivedArgs = new String[2]; + + aMock.expect( new CallMocker() { + public void verify() {} + public boolean matches(String methodName, Object[] args) { + return false; + } + + public Object call(Mock mock, String methodName, Object[] args) { + assertEquals( "should be expected number of args", expectedArgs.length, args.length ); + System.arraycopy( args, 0, receivedArgs, 0, args.length ); + return null; + } + } ); + + proxy.aMethod( expectedArgs[0], expectedArgs[1] ); + for( int i = 0; i < expectedArgs.length; i++ ) { + assertSame( "arg " + (i+1), expectedArgs[i], receivedArgs[i] ); + } + } + + public void testCallMockerReceivesEmptyArrayWhenNoArguments() throws Exception { + aMock.expect( new CallMocker() { + public void verify() {} + public boolean matches(String methodName, Object[] args) { + return false; + } + public Object call( Mock mock, String methodName, Object[] args ) { + assertNotNull( "Arg array should not be null", args ); + assertEquals( "Arg array should have zero length", 0, args.length ); + return null; + } + } ); + + proxy.aMethodWithNoArguments(); + } + + public void testCallMockerResultReturnedByProxy() throws Throwable { + final String result = "result"; + + aMock.expect( new CallMocker() { + public void verify() {} + + public Object call(Mock mock, String methodName, Object[] args) { + return result; + } + + public boolean matches(String methodName, Object[] args) { + return false; + } + } ); + + assertSame( "result is returned by mock", + result, proxy.aMethod( "hello", "world" ) ); + } + + public void testCallMockerThrowableThrownThroughProxy() throws Throwable { + final Throwable throwable = new TestThrowable(); + + aMock.expect( new CallMocker() { + public void verify() {} + public boolean matches(String methodName, Object[] args) { + return false; + } + + public Object call(Mock mock, String methodName, Object[] args) + throws Throwable + { + throw throwable; + } + } ); + + try { + proxy.aMethod( "hello", "world" ); + } + catch( Throwable ex ) { + assertSame( "exception is caught by mock", + throwable, ex ); + } + } + + public void testCallMockerAnnotatesAssertionFailedErrors() throws Throwable { + final String originalMessage = "original message"; + final AssertionFailedError error = new AssertionFailedError(originalMessage); + + aMock.expect( new CallMocker() { + public void verify() {} + public boolean matches(String methodName, Object[] args) { + return false; + } + + public Object call(Mock mock, String methodName, Object[] args) + throws Throwable + { + throw error; + } + } ); + + try { + proxy.aMethod( "hello", "world" ); + } + catch( AssertionFailedError err ) { + AssertMo.assertIncludes( "should contain original message", + originalMessage, err.getMessage() ); + AssertMo.assertIncludes( "should contain mock name", + MOCK_NAME, err.getMessage() ); + } + } + + public void testMockDispatchesCallToMatchingCallMocker() throws Throwable { + final String[] expectedArgs = { "hello", "world" }; + final String[] receivedArgs = new String[2]; + + aMock.expect( new CallMocker() { + public void verify() {} + public boolean matches(String methodName, Object[] args) { + return false; + } + + public Object call(Mock mock, String methodName, Object[] args) { + assertEquals( "should be expected number of args", expectedArgs.length, args.length ); + System.arraycopy( args, 0, receivedArgs, 0, args.length ); + return null; + } + } ); + + proxy.aMethod( expectedArgs[0], expectedArgs[1] ); + + for( int i = 0; i < expectedArgs.length; i++ ) { + assertSame( "arg " + (i+1), expectedArgs[i], receivedArgs[i] ); + } + } + -public class MockTest - extends TestCaseMo -{ - public static interface ExampleInterface { - Object noArgs(); - void voidMethod(); - String objectTypes( Integer i ); - int primitiveTypes( int x, int y ); - void sideEffect( StringBuffer buf ); - - // These are used to test default return values - boolean booleanResult(); - byte byteResult(); - char charResult(); - short shortResult(); - int intResult(); - long longResult(); - float floatResult(); - double doubleResult(); - String stringResult(); - - // Used to test ordered calls - void first(); - void second(); - } - - private Mock _mock; - private ExampleInterface _interface; - - - public MockTest( String test ) { - super(test); - } - - public void setUp() { - _mock = new Mock( ExampleInterface.class ); - _interface = (ExampleInterface)_mock.proxy(); - } - - public void tearDown() { - _mock = null; - _interface = null; - } - - public void testNewMockVerifies() { - _mock.verify(); - } - - public void testMockCallToNoArgMethod() { - Object result = new Object(); - - _mock.expectAndReturn( "noArgs", Mock.NO_ARGS, result ); - - assertSame( result, _interface.noArgs() ); - - _mock.verify(); - } - - public void testMockCallToVoidMethod() { - _mock.expectVoid( "voidMethod", Mock.NO_ARGS ); - - _interface.voidMethod(); - - _mock.verify(); - } - - public void testObjectTypes() { - _mock.expectAndReturn( "objectTypes", - new Constraint[] { new IsEqual( new Integer(1) ) }, - "1" ); - - assertEquals( "1", _interface.objectTypes( new Integer(1) ) ); - _mock.verify(); - } - - public void testPrimitiveTypes() { - _mock.expectAndReturn( "primitiveTypes", - new Constraint[] { new IsEqual( new Integer(2) ), - new IsEqual( new Integer(3) ) }, - new Integer(6) ); - - assertEquals( 6, _interface.primitiveTypes(2,3) ); - _mock.verify(); - } - - public void testLaterExpectationsOverrideEarlierExpectations() { - Object result1 = new Object(); - Object result2 = new Object(); - - _mock.expectAndReturn( "noArgs", Mock.NO_ARGS, result1 ); - _mock.expectAndReturn( "noArgs", Mock.NO_ARGS, result2 ); - - assertSame( result2, _interface.noArgs() ); - assertSame( result2, _interface.noArgs() ); - _mock.verify(); - } - - public void testThrow() { - _mock.expectAndThrow( "primitiveTypes", - new Constraint[] { new IsEqual( new Integer(2) ), - new IsEqual( new Integer(3) ) }, - new ArithmeticException("message") ); - - try { - _interface.primitiveTypes( 2, 3 ); - fail( "expected ArithmeticException to be thrown" ); - } - catch( ArithmeticException ex ) { - assertEquals( "message", ex.getMessage() ); - } - - _mock.verify(); - } - - public void testExpectCallWithSideEffect() { - final StringBuffer buf = new StringBuffer(); - _mock.expect( "sideEffect", new MockCall() { - public Object call( Object[] args ) throws Throwable { - assertSame( "wrong buffer", buf, args[0] ); - buf.append("hello"); - return Mock.VOID; - } - } ); - - _interface.sideEffect( buf ); - assertEquals( "hello", buf.toString() ); - _mock.verify(); - } - - public void testFailingExpectationInCallWithSideEffect() { - final StringBuffer buf = new StringBuffer(); - _mock.expect( "sideEffect", new MockCall() { - public Object call( Object[] args ) throws Throwable { - assertSame( "wrong buffer", buf, args[0] ); - buf.append("hello"); - return Mock.VOID; - } - } ); - - assertFails( "should fail with wrong buffer", new Runnable() { - public void run() { - _interface.sideEffect( new StringBuffer() ); - } - } ); - } - - public void testNotAllMethodsCalled() { - _mock.expectVoid("noArgs", Mock.NO_ARGS); - - assertFails("verify did not fail when not all of the expected methods were called", - new Runnable() { - public void run() { _mock.verify(); } - }); - } - - public void testCalledExpectationClearedBySubsequentExpecation() { - _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() { - public void run() { _mock.verify(); } - }); - } - - public void testUnexpectedMethodThrowsWhenStrict() { - _mock.setStrict(true); - - assertFails("strict mock did not fail when unexpected method was called", - new Runnable() { - public void run() { _interface.voidMethod();} - }); - } - - public void testUnexpectedMethodDoesNotThrowWhenNotStrict() { - try { - _interface.voidMethod(); - } - catch( AssertionFailedError ex ) { - fail( "unstrict mock failed when unexpected method was called" ); - } - } - - public void testDefaultResultFromUnexpectedCalls() { - assertEquals( false, _interface.booleanResult() ); - assertEquals( 0, _interface.byteResult() ); - assertEquals( '\0', _interface.charResult() ); - assertEquals( 0, _interface.shortResult() ); - assertEquals( 0, _interface.intResult() ); - assertEquals( 0L, _interface.longResult() ); - assertEquals( 0.0f, _interface.floatResult(), 0.0f ); - assertEquals( 0.0d, _interface.doubleResult(), 0.0d ); - assertEquals( "", _interface.stringResult() ); - } - - public void testSetupDefaultResult() { - _mock.setupDefaultResult( boolean.class, new Boolean(true) ); - _mock.setupDefaultResult( byte.class, new Byte((byte)1) ); - _mock.setupDefaultResult( char.class, new Character( '2' ) ); - _mock.setupDefaultResult( short.class, new Short( (short)3 ) ); - _mock.setupDefaultResult( int.class, new Integer(4) ); - _mock.setupDefaultResult( long.class, new Long(5L) ); - _mock.setupDefaultResult( float.class, new Float(6.0f) ); - _mock.setupDefaultResult( double.class, new Double(7.0d) ); - _mock.setupDefaultResult( String.class, "8" ); - - assertEquals( true, _interface.booleanResult() ); - assertEquals( (byte)1, _interface.byteResult() ); - assertEquals( '2', _interface.charResult() ); - assertEquals( 3, _interface.shortResult() ); - assertEquals( 4, _interface.intResult() ); - assertEquals( 5L, _interface.longResult() ); - assertEquals( 6.0f, _interface.floatResult(), 0.0f ); - assertEquals( 7.0d, _interface.doubleResult(), 0.0d ); - assertEquals( "8", _interface.stringResult() ); - } - - public void testWrongNumberOfArguments() { - Constraint p = new IsEqual( new Integer(2) ); - Constraint q = new IsAnything(); - - _mock.expectAndReturn( "objectTypes", new Constraint[]{p,q}, "2" ); - - assertFails( "mock did not fail when wrong number of arguments passed", - new Runnable() { - public void run() { _interface.objectTypes( new Integer(1) ); } - }); - } - - public void testArgumentsPassedToNoArgMethod() { - Constraint p = new IsAnything(); - - _mock.expectVoid( "voidMethod", new Constraint[]{p} ); - - try { - _interface.voidMethod(); - } - catch( AssertionFailedError ex ) { - return; - } - - fail( "mock did not fail when arguments passed to void method" ); - } - - public void testPredicateFailure() { - Constraint p = new IsEqual( new Integer(2) ); - - _mock.expectAndReturn( "objectTypes", new Constraint[]{p}, "2" ); - - assertTrue( !p.eval( new Integer(1) ) ); - try { - _interface.objectTypes( new Integer(1) ); - } - catch( AssertionFailedError ex ) { - return; - } - - fail( "mock did not fail when predicate returned false" ); - } - - public void testErrorWhenOrderedMethodsCalledInWrongOrder() { - _mock.expectVoid( "first", Mock.NO_ARGS ); - _mock.expectVoid( "second", Mock.NO_ARGS ); - - _mock.order( "first", "second" ); - - try { - _interface.second(); - } - catch( AssertionFailedError ex ) { - return; - } - - fail( "mock did not enforce order of calls" ); - } - - public void testExpectNotCalled() { - _mock.expectNotCalled("noArgs"); - try { - _interface.noArgs(); - } - catch( AssertionFailedError ex ) { - return; - } - - fail("AssertionFailedError expected"); - } - - public void testExpectNotCalledClearedBySubsequentExpectation() { - _mock.expectNotCalled("voidMethod"); - _mock.expectVoid( "voidMethod", Mock.NO_ARGS ); - - _interface.voidMethod(); - - _mock.verify(); - } - - public void testSetupResult() { - final String RESULT = "result"; - - _mock.setupResult( "objectTypes", RESULT ); - - assertEquals( RESULT, _interface.objectTypes(null) ); - assertEquals( RESULT, _interface.objectTypes(new Integer(0)) ); - - _mock.verify(); - } - - public void testSetupThrow() { - _mock.setupThrow( "objectTypes", new IllegalArgumentException() ); - - try { - _interface.objectTypes(null); - fail("expected IllegalArgumentException"); - } - catch( IllegalArgumentException ex ) { - // expected - } - - try { - _interface.objectTypes(new Integer(0)); - fail("expected IllegalArgumentException"); - } - catch( IllegalArgumentException ex ) { - // expected - } - - _mock.verify(); - } - - public void testSetupCallWithSideEffect() { - final StringBuffer buf = new StringBuffer(); - _mock.setup( "sideEffect", new MockCall() { - public Object call( Object[] args ) throws Throwable { - buf.append("hello"); - return Mock.VOID; - } - } ); - - _interface.sideEffect( buf ); - assertEquals( "hello", buf.toString() ); - _mock.verify(); - } - - public void testSetupResultDoesNotRequireCall() { - _mock.setupResult( "objectTypes", "result" ); - _mock.verify(); - } - - public void testSetupThrowDoesNotRequireCall() { - _mock.setupThrow( "objectTypes", new RuntimeException() ); - _mock.verify(); - } - - public void testSetupCallWithSideEffectDoesNotRequireCall() { - _mock.setup( "sideEffect", new MockVoidCall() { - public Object call( Object[] args ) throws Throwable { - throw new RuntimeException("should not be called"); - } - } ); - - _mock.verify(); - } - - public void testNoErrorWhenOrderedMethodsCalledInCorrectOrder() { - _mock.expectVoid( "first", Mock.NO_ARGS ); - _mock.expectVoid( "second", Mock.NO_ARGS ); - - _mock.order( "first", "second" ); - - _interface.first(); - _interface.second(); - } - - public void testErrorWhenMockedVoidMethodReturnsAValue() { - _mock.expectAndReturn( "voidMethod", Mock.NO_ARGS, Boolean.TRUE ); - - try { - _interface.voidMethod(); - } - catch( AssertionFailedError ex ) { - return; - } - 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 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 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 - { - 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( - getClass().getClassLoader(), - new Class[]{ ExampleInterface.class }, - mock ); - - i.voidMethod(); - - assertTrue( "mock method not called on derived class", - mock.was_called ); - mock.verify(); - } - - public void testDerivedClassPassingInvocationToMockCall() { - DerivedMock mock = new DerivedMock(); - ExampleInterface i = (ExampleInterface)Proxy.newProxyInstance( - getClass().getClassLoader(), - new Class[]{ ExampleInterface.class }, - mock ); - - mock.expectAndReturn( "objectTypes", - new Constraint[] { new IsAnything() }, - "result" ); - - assertEquals( "result", i.objectTypes( new Integer(1) ) ); - - mock.verify(); - } } --- CallCollectionTest.java DELETED --- --- CallCounterTest.java DELETED --- |
From: Asbell, J. <Jon...@Mc...> - 2003-04-04 14:44:53
|
We are trying to supply a HashMap of name/value pairs representing column name and column value for a row: mockResult.addExpectedNamedValues(myHashMapFullOfRowData); I create mock row data in this fashion..... ================================= MockDataSource mockDataSource = new MockDataSource(); MockConnection mockConn = new MockConnection(); MockStatement mockStatement = new MockStatement(); MockSingleRowResultSet mockResult = new MockSingleRowResultSet(); expectedDataHashMap.put("ORDER DATE", new java.sql.Date(System.currentTimeMillis())); When I execute I retrieve the data in the following manner..... ================================= anotherHashMap.put("ORDER DATE", resultSet.getDate("ORDER_DATE").toString()); ......an Exception gets thrown on the line above........ CommonMockSingleRowResultSet.SqlRow keys did not receive an expected item Unexpected:ORDER_DATE; Am I forgetting to set something in a relevant Mock Sql Object? |
From: Tim M. <ma...@us...> - 2003-04-04 11:13:34
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv3249/src/core/com/mockobjects/dynamic Modified Files: MethodExpectation.java CallSequence.java Added Files: CallBag.java CallCollection.java Log Message: CallBag added + refactoring --- NEW FILE: CallBag.java --- package com.mockobjects.dynamic; /** * Represents a collection of calls for which the order in which they are called is not checked but the total number of times is. */ public class CallBag extends CallCollection { public CallBag() { super(); } protected int findCallIndexAndCheckArguments(Object[] args,int callnumber) { for (int i = 0; i < _expected_constraints.size(); i++) { if (!hasBeenCalled(i) && checkArguments(i, args)) { return i; } } fail(errorMessage(args)); return -1; } } --- NEW FILE: CallCollection.java --- /** Created on Oct 31, 2002 by npryce * Copyright (c) B13media Ltd. */ package com.mockobjects.dynamic; import java.util.ArrayList; import java.util.List; import com.mockobjects.Verifiable; import com.mockobjects.constraint.*; import com.mockobjects.util.AssertMo; /** A {@link MockCall} that expects a sequence of calls, checks their * arguments and mocks their behaviour. * A test will fail if too few or too many calls are made. */ public abstract class CallCollection extends AssertMo implements MockCall, Verifiable { protected List _expected_calls = new ArrayList(); protected List _expected_constraints = new ArrayList(); public static final String EXPECTED_CALLS="expected calls were:"; public static final String NO_EXPECTED_CALLS="no expected calls were set"; public static final String CALLED="called already" ; public static final String NOT_CALLED="not called"; public static final String ARGS="\nreceived arguments were "; private int numcalls = 0; protected List _hasBeenCalled = new ArrayList(); public CallCollection() { super(); } public void expect(MockCall call, Constraint[] constraints) { _expected_calls.add(call); _expected_constraints.add(constraints); _hasBeenCalled.add(Boolean.FALSE); } /* The following were copy-and-pasted from Mock.java with minor editing. * Is there any way to remove this duplication? */ /** Expect a method call and return a result when it is called. * * @param args * 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 * 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. */ public void expectAndReturn(Constraint[] args, Object result) { expect(new MockReturnCall(args, result), args); } /** Expect a method call and return a result when it is called. * * @param arg * An single object that will be compared with predicate same() * @param result * 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. */ public void expectAndReturn(Object arg, Object result) { expectAndReturn(C.args(C.eq(arg)), result); } /** Expect a method call with no parameters and return a result when it is called. * * @param result * 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. */ public void expectAndReturn(Object result) { expectAndReturn(Mock.NO_ARGS, result); } /** Expect a call to a method with a void return type. * * @param args * 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(Constraint[] args) { expect(new MockVoidCall(args), args); } /** Expect a call to a method with a void return type. * * @param method * The name of the method that will be called. * @param arg * An single object that will be compared with predicate eq() */ public void expectVoid(Object arg) { expectVoid(C.args(C.eq(arg))); } /** Expect a call to a method with a void return type and no parameters */ public void expectVoid() { expectVoid(Mock.NO_ARGS); } /** Expect a method call and throw an exception or error when it is called. * * @param args * 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 expectAndThrow(Constraint[] args, Throwable exception) { expect(new MockThrowCall(args, exception), args); } /** Expect a method call and throw an exception or error when it is called. * * @param arg * 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. */ public void expectAndThrow(Object arg, Throwable exception) { expectAndThrow(C.args(C.eq(arg)), exception); } /** Expect a method call with no parameters and throw an exception or error when it is called. * * @param exception * The exception or error that will be thrown as a result of this call. */ public void expectAndThrow(Throwable exception) { expectAndThrow(Mock.NO_ARGS, exception); } public Object call(Object[] args) throws Throwable { numcalls++; assertTrue(errorMessage(args), numcalls <= _expected_calls.size()); int callIndex = findCallIndexAndCheckArguments(args,numcalls); MockCall call = (MockCall) _expected_calls.get(callIndex); _hasBeenCalled.add(callIndex, Boolean.TRUE); return call.call(args); } abstract protected int findCallIndexAndCheckArguments(Object[] args,int callNumber); protected boolean checkArguments(int index, Object[] args) { Constraint[] cons =(Constraint[]) _expected_constraints.get(index); int cons_count = (cons == null) ? 0 : cons.length; int arg_count = (args == null) ? 0 : args.length; if (cons_count != arg_count) { return false; } for (int i = 0; i < arg_count; i++) { if (!cons[i].eval(args[i])) { return false; } } return true; } public void verify() { assertTrue(errorMessage(null), _expected_calls.size() == numcalls); } public String printConstraint(int i) { if (i < 0 || i > (_expected_constraints.size() - 1)) { return ""; } Constraint[] cons = (Constraint[]) _expected_constraints.get(i); return printArgsArray(cons); } protected String printArgsArray(Object[] array) { if (array.length == 0) { return "[no args]"; } StringBuffer result = new StringBuffer("["); for (int j = 0; j < array.length; j++) { result.append(array[j].toString()); result.append(','); } result.deleteCharAt(result.length() - 1); result.append(']'); return result.toString(); } public String errorMessage(Object[] args) { StringBuffer result = new StringBuffer(EXPECTED_CALLS); if (_expected_constraints.size() == 0) { result = new StringBuffer(NO_EXPECTED_CALLS); } for (int i = 0; i < _expected_constraints.size(); i++) { result.append('\n'); result.append(printConstraint(i)); result.append(" :" + (hasBeenCalled(i) ? CALLED : NOT_CALLED)); } if (args != null) { result.append( ARGS+ printArgsArray(args)); } return result.toString(); } protected boolean hasBeenCalled(int i) { return ((Boolean) _hasBeenCalled.get(i)).booleanValue(); } } Index: MethodExpectation.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/MethodExpectation.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- MethodExpectation.java 24 Nov 2002 11:03:28 -0000 1.5 +++ MethodExpectation.java 4 Apr 2003 11:13:31 -0000 1.6 @@ -55,9 +55,12 @@ prerequisites.verify(); } - public void verify() { - wasCalled.verify(); - } + public void verify() { + wasCalled.verify(); + if (mockCall instanceof Verifiable) { + ((CallCollection) mockCall).verify(); + } + } private void initializeWasCalled() { wasCalled = new ExpectationValue(name); Index: CallSequence.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CallSequence.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- CallSequence.java 24 Nov 2002 11:02:38 -0000 1.3 +++ CallSequence.java 4 Apr 2003 11:13:31 -0000 1.4 @@ -1,147 +1,28 @@ -/** Created on Oct 31, 2002 by npryce - * Copyright (c) B13media Ltd. - */ package com.mockobjects.dynamic; -import java.util.ArrayList; -import java.util.List; - -import com.mockobjects.Verifiable; -import com.mockobjects.constraint.*; -import com.mockobjects.util.AssertMo; - - -/** A {@link MockCall} that expects a sequence of calls, checks their - * arguments and mocks their behaviour. - * A test will fail if too few or too many calls are made. +/** + * @author chris + * + * Represents a collection of calls on the same method for which the order of the calls is important */ -public class CallSequence - extends AssertMo - implements MockCall, Verifiable -{ - List _expected_calls = new ArrayList(); - - public CallSequence() { - super(); - } - - public void expect( MockCall call ) { - _expected_calls.add(call); - } - - /* The following were copy-and-pasted from Mock.java with minor editing. - * Is there any way to remove this duplication? - */ - - /** Expect a method call and return a result when it is called. - * - * @param args - * 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 - * 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. - */ - public void expectReturn( Constraint[] args, Object result ) { - expect( new MockReturnCall( args, result ) ); - } - - /** Expect a method call and return a result when it is called. - * - * @param arg - * An single object that will be compared with predicate same() - * @param result - * 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. - */ - public void expectReturn( Object arg, Object result ) { - expectReturn( C.args(C.eq(arg) ), result); - } - - /** Expect a method call with no parameters and return a result when it is called. - * - * @param result - * 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. - */ - public void expectReturn( Object result ) { - expectReturn( Mock.NO_ARGS, result ); - } - - /** Expect a call to a method with a void return type. - * - * @param args - * 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( Constraint[] args ) { - expect( new MockVoidCall( args ) ); - } - - /** Expect a call to a method with a void return type. - * - * @param method - * The name of the method that will be called. - * @param arg - * An single object that will be compared with predicate eq() - */ - public void expectVoid( Object arg ) { - expectVoid( C.args(C.eq(arg)) ); - } +public class CallSequence extends CallCollection { - /** Expect a call to a method with a void return type and no parameters - */ - public void expectVoid() { - expectVoid( Mock.NO_ARGS ); - } + /** + * Constructor for CallSequence. + */ + public CallSequence() { + super(); + } + + protected int findCallIndexAndCheckArguments(Object[] args,int callnumber) { + int callIndex = callnumber - 1; + if (! checkArguments(callIndex, args) ){ + fail(errorMessage(args)); + } + return callIndex; + } + - /** Expect a method call and throw an exception or error when it is called. - * - * @param args - * 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( Constraint[] args, Throwable exception ) { - expect( new MockThrowCall( args, exception ) ); - } - /** Expect a method call and throw an exception or error when it is called. - * - * @param arg - * 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. - */ - public void expectThrow( Object arg, Throwable exception ) { - expectThrow( C.args(C.eq(arg)), exception ); - } - /** Expect a method call with no parameters and throw an exception or error when it is called. - * - * @param exception - * The exception or error that will be thrown as a result of this call. - */ - public void expectThrow( Throwable exception ) { - expectThrow( Mock.NO_ARGS, exception ); - } - - - public Object call(Object[] args) throws Throwable { - assertTrue("Too many calls", 0 != _expected_calls.size()); - - MockCall call = (MockCall)_expected_calls.remove(0); - return call.call( args ); - } - - public void verify() { - assertEquals("Too few calls", 0, _expected_calls.size()); - } } |
From: Tim M. <ma...@us...> - 2003-04-04 11:13:34
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv3249/src/core/test/mockobjects/dynamic Added Files: CallCollectionTest.java Removed Files: CallSequenceTest.java Log Message: CallBag added + refactoring --- NEW FILE: CallCollectionTest.java --- /** Created on Oct 31, 2002 by npryce * Copyright (c) B13media Ltd. */ package test.mockobjects.dynamic; import java.util.List; import junit.framework.AssertionFailedError; import com.mockobjects.constraint.Constraint; import com.mockobjects.dynamic.C; import com.mockobjects.dynamic.CallBag; import com.mockobjects.dynamic.CallCollection; import com.mockobjects.dynamic.CallSequence; import com.mockobjects.dynamic.Mock; import com.mockobjects.dynamic.MockCall; import com.mockobjects.util.TestCaseMo; public class CallCollectionTest extends TestCaseMo { private Mock mock_call_1 = new Mock(MockCall.class); private Mock mock_call_2 = new Mock(MockCall.class); private CallSequence call_list = new CallSequence(); private CallBag call_bag = new CallBag(); private final Object[] ARGS_1 = { "ARG1" }; private final Object RESULT_1 = new Object(); private final Object[] ARGS_2 = { "ARG2" }; private final Object RESULT_2 = new Object(); private Constraint[] CONS_1 = new Constraint[] { C.eq(ARGS_1[0])}; private Constraint[] CONS_2 = new Constraint[] { C.eq(ARGS_2[0])}; private Constraint[] NO_CONSTRAINTS = new Constraint[0]; public CallCollectionTest(String name) { super(name); } public void setUp() { } public void testCallListInitiallyExpectsNoCalls() throws Throwable { call_list.verify(); } public void testCallToEmptyCallListFails() throws Throwable { try { call_list.call(new Object[0]); } catch (AssertionFailedError expected) { assertTrue( "should have nice error message", -1 != expected.getMessage().indexOf(CallCollection.NO_EXPECTED_CALLS)); return; } fail("call to empty call list should fail"); } public void testCallListPassesArgumentsAndReturnsValue() throws Throwable { mock_call_1.expectAndReturn("call", ARGS_1, RESULT_1); call_list.expect((MockCall) mock_call_1.proxy(), CONS_1); mock_call_2.expectAndReturn("call", ARGS_2, RESULT_2); call_list.expect((MockCall) mock_call_2.proxy(), CONS_2); assertSame(RESULT_1, call_list.call(ARGS_1)); assertSame(RESULT_2, call_list.call(ARGS_2)); mock_call_1.verify(); mock_call_2.verify(); call_list.verify(); } public void testCallBagOrderDoesNotMatter() throws Throwable { mock_call_1.expectAndReturn("call", ARGS_1, RESULT_1); call_bag.expect((MockCall) mock_call_1.proxy(), CONS_1); mock_call_2.expectAndReturn("call", ARGS_2, RESULT_2); call_bag.expect((MockCall) mock_call_2.proxy(), CONS_2); assertSame(RESULT_2, call_bag.call(ARGS_2)); assertSame(RESULT_1, call_bag.call(ARGS_1)); mock_call_1.verify(); mock_call_2.verify(); call_bag.verify(); } public void testCallListOrderDoesMatter() throws Throwable { mock_call_1.expectAndReturn("call", ARGS_1, RESULT_1); call_list.expect((MockCall) mock_call_1.proxy(), CONS_1); mock_call_2.expectAndReturn("call", ARGS_2, RESULT_2); call_list.expect((MockCall) mock_call_2.proxy(), CONS_2); try { call_list.call(ARGS_2); } catch (AssertionFailedError expected) { assertTrue( "should have nice error message which refers to the arguments", -1 != expected.getMessage().indexOf((String) ARGS_1[0])); return; } fail("should fail if a call is done in wrong order"); } public void testCallBagOrderDoesNotMatterButNumberOfCallsDoes() throws Throwable { mock_call_1.expectAndReturn("call", ARGS_1, RESULT_1); call_bag.expect((MockCall) mock_call_1.proxy(), CONS_1); mock_call_2.expectAndReturn("call", ARGS_2, RESULT_2); call_bag.expect((MockCall) mock_call_2.proxy(), CONS_2); assertSame(RESULT_2, call_bag.call(ARGS_2)); try { call_bag.call(ARGS_2); } catch (AssertionFailedError expected) { assertTrue( "should have nice error message which refers to the arguments", -1 != expected.getMessage().indexOf((String) ARGS_1[0])); return; } fail("should fail if a call is done too often"); } public void testNicelyFormattedConstraintArrays() throws Throwable { Constraint[] cons1 = new Constraint[] { C.eq("hello"), C.gt(2)}; call_list.expect(CALL, cons1); call_list.expect(CALL, new Constraint[0]); String expected1 = "[a value equal to <hello>,a value greater than <2>]"; assertEquals("should get the nicely formatted message", expected1, call_list.printConstraint(0)); assertEquals("should get no args message if empty constraint array", "[no args]", call_list.printConstraint(1)); assertEquals("should just return empty string if given bad index", "", call_list.printConstraint(2)); } public void testErrorMessage() throws Throwable { Constraint[] cons1 = new Constraint[] { C.eq("hello"), C.gt(2)}; call_list.expect(CALL, cons1); call_list.expect(CALL, new Constraint[0]); call_list.call(new Object[] { "hello", new Integer(3)}); Object[] badargs = new Object[] { "wibble", "foobar" }; String expected1 = "expected calls were:\n[a value equal to <hello>,a value greater than <2>] :called already\n[no args] :not called\nreceived arguments were [wibble,foobar]"; String result = call_list.errorMessage(badargs); assertEquals("should get the nicely formatted message", expected1, result); String expectedWithNullArgs = "expected calls were:\n[a value equal to <hello>,a value greater than <2>] :called already\n[no args] :not called"; assertEquals( "should get the nicely formatted message with null args", expectedWithNullArgs, call_list.errorMessage(null)); } public void testErrorMessageNoCallsSetup() throws Throwable { Object[] badargs = new Object[] { "wibble", "foobar" }; String expected1 = "no expected calls were set\nreceived arguments were [wibble,foobar]"; String result = call_list.errorMessage(badargs); assertEquals("should get the nicely formatted message", expected1, result); } public void testCallListThrowsExceptionValue() throws Throwable { final ExampleException EXCEPTION_1 = new ExampleException(); final ExampleException EXCEPTION_2 = new ExampleException(); mock_call_1.expectAndThrow("call", C.args(C.same(ARGS_1)), EXCEPTION_1); call_list.expect((MockCall) mock_call_1.proxy(), CONS_1); mock_call_2.expectAndThrow("call", C.args(C.eq(ARGS_2)), EXCEPTION_2); call_list.expect((MockCall) mock_call_2.proxy(), CONS_2); try { call_list.call(ARGS_1); fail("expected ExampleException to be thrown"); } catch (ExampleException ex) { assertSame(EXCEPTION_1, ex); } try { call_list.call(ARGS_2); fail("expected ExampleException to be thrown"); } catch (ExampleException ex) { assertSame(EXCEPTION_2, ex); } mock_call_1.verify(); mock_call_2.verify(); call_list.verify(); } static final MockCall CALL = new MockCall() { public Object call(Object[] args) throws Throwable { return Mock.VOID; } }; static final Object[] NO_ARGS = { }; public void testTooManyCalls() throws Throwable { call_list.expect(CALL, NO_CONSTRAINTS); call_list.expect(CALL, NO_CONSTRAINTS); call_list.call(NO_ARGS); call_list.call(NO_ARGS); try { call_list.call(NO_ARGS); } catch (AssertionFailedError expected) { assertTrue("should have nice error message", -1 != expected.getMessage().indexOf(CallCollection.CALLED)); return; } fail("third call should have failed"); } public void testTooFewCalls() throws Throwable { call_list.expect(CALL, NO_CONSTRAINTS); call_list.expect(CALL, NO_CONSTRAINTS); call_list.call(NO_ARGS); try { call_list.verify(); } catch (AssertionFailedError expected) { assertTrue( "should have nice error message", -1 != expected.getMessage().indexOf(CallCollection.EXPECTED_CALLS)); return; } fail("verify should have failed"); } public void testCheckMockVerifiesCallList() throws Throwable { Mock mockList = new Mock(List.class); List aList = (List) mockList.proxy(); call_list.expectAndReturn(new Constraint[] { C.eq("value")}, Boolean.TRUE); call_list.expectVoid(new Constraint[] { C.eq(1), C.eq("value2")}); mockList.expect("add", call_list); aList.add("value"); try { mockList.verify(); } catch (AssertionFailedError expected) { return; } fail("the mock should have verified it's call sequence"); } public void testFirstMatchingCallIsUsedInBag() throws Throwable { Constraint[] greaterThan3 = C.args(C.gt(3)); Constraint[] greaterThan7 = C.args(C.gt(7)); call_bag.expectAndReturn(greaterThan3, RESULT_1); call_bag.expectAndReturn(greaterThan7, RESULT_2); assertSame("should get the first call", RESULT_1, call_bag.call(new Object[] { new Integer(8)})); try { call_bag.call(new Object[] { new Integer(5)}); } catch (AssertionFailedError e) { return; } fail("should have failed to find a matching call for the second call since 5 is not greater than 7"); } private static class ExampleException extends Exception { } } --- CallSequenceTest.java DELETED --- |
From: Steve F. <st...@m3...> - 2003-03-24 22:22:47
|
Should be junit.jar and j2ee.jar. Shackelford, John-Mason wrote: > What jars do I need in the lib dir to build mockobjects-java from source? I > am trying to build a version with the cvs fix for > MockHttpSession.removeAttribute(Object). S. -- [Advert: Come to http://www.ot2003.org] "A LISP programmer knows the value of everything but the cost of nothing. A C programmer knows the cost of everything but the value of nothing." (Todd Proebsting) |
From: Shackelford, John-M. <joh...@pe...> - 2003-03-24 18:44:37
|
What jars do I need in the lib dir to build mockobjects-java from source? I am trying to build a version with the cvs fix for MockHttpSession.removeAttribute(Object). Thanks, John-Mason Shackelford Software Developer Pearson Educational Measurement - eMeasurement Group 2510 North Dodge St. Iowa City, IA 52245 ph. 319-354-9200x6214 joh...@pe... http://etest.ncspearson.com **************************************************************************** This email may contain confidential material. If you were not an intended recipient, Please notify the sender and delete all copies. We may monitor email to and from our network. **************************************************************************** |
From: Jeff M. <cus...@us...> - 2003-03-24 11:23:22
|
Update of /cvsroot/mockobjects/mockobjects-java/src/jdk/common/com/mockobjects/io In directory sc8-pr-cvs1:/tmp/cvs-serv11550/src/jdk/common/com/mockobjects/io Modified Files: MockOutputStream.java Log Message: Added expectations for flush() calls on MockOutputStream. patch from Francois Beausoleil Index: MockOutputStream.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/jdk/common/com/mockobjects/io/MockOutputStream.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- MockOutputStream.java 8 Jul 2002 18:31:29 -0000 1.3 +++ MockOutputStream.java 24 Mar 2003 11:23:16 -0000 1.4 @@ -12,6 +12,7 @@ public class MockOutputStream extends OutputStream implements Verifiable { private ExpectationValue myWriteWasCalled = new ExpectationValue("MockOutputStream.writeWasCalled"); private ExpectationCounter myCloseCalls = new ExpectationCounter("MockOutputStream.close()"); + private ExpectationCounter myFlushCalls = new ExpectationCounter("MockOutputStream.flush()"); private ByteArrayOutputStream myBuffer = new ByteArrayOutputStream(); private boolean shouldThrowException = false; @@ -27,6 +28,10 @@ myCloseCalls.inc(); } + public void flush() throws IOException { + myFlushCalls.inc(); + } + public String getContents() { return myBuffer.toString(); } @@ -42,6 +47,10 @@ myCloseCalls.setExpected(closeCall); } + public void setExpectedFlushCalls(int flushCall) { + myFlushCalls.setExpected(flushCall); + } + public void setExpectingWriteCalls(boolean expectingWriteCall) { myWriteWasCalled.setExpected(expectingWriteCall); } @@ -56,7 +65,7 @@ public void write(int b) throws IOException { myWriteWasCalled.setActual(true); - if(shouldThrowException) { + if (shouldThrowException) { throw new IOException("Test IOException generated by request"); } myBuffer.write(b); |
From: Jeff M. <cus...@us...> - 2003-03-24 11:10:24
|
Update of /cvsroot/mockobjects/mockobjects-java/src/j2ee/1.3/com/mockobjects/servlet In directory sc8-pr-cvs1:/tmp/cvs-serv7064/src/j2ee/1.3/com/mockobjects/servlet Modified Files: MockHttpSession.java Log Message: Attribute patch from Marvin Lau Index: MockHttpSession.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/j2ee/1.3/com/mockobjects/servlet/MockHttpSession.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- MockHttpSession.java 28 Aug 2002 18:27:11 -0000 1.3 +++ MockHttpSession.java 24 Mar 2003 11:10:20 -0000 1.4 @@ -93,6 +93,7 @@ public void removeAttribute(String anAttributeName) { myRemovedAttributes.addActual(anAttributeName); + myAttributeValues.remove(anAttributeName); } public void removeValue(String arg1) { |
From: Jeff M. <je...@mk...> - 2003-03-24 11:04:43
|
On Sun, 2003-03-23 at 22:04, Tim wrote: > Guys - I've always used an internal connextra version of the mock objects > stuff. Now I'm no longer with connextra I thought I would try using the > official release and see if I could maybe integrate some stuff... but why is > it so complicated? > > Its certainly not easy to just pull this down in eclipse and use it... there > are jdk versions to worry about (yes I know this is an issue but only for > very advanced stuff - surely?), and the directory structures don't easily > map into the eclipse view of the world (I guess you guys all use some > complicated scheme in intellij? But why not use eclipse as the lowest common > denominator? I want a head version in my environment that I can easily apply > fixes to and check in - I have access to lots of code and ideas, but it has > to be simple for me to make modifications with an onsite partner and put > them back in (without lots of messing around - this is why lots of good > stuff got left out, because for ages connextra used visual age and it was > too much work to put stuff back in, so we just didn't). It's quite easy to build from CVS if you use the lowest common denominator which is ant. Both Eclipse and IntelliJ support executing ant build files and it's also what allows nightly builds to be performed by Gump http://cvs.apache.org/builds/gump/latest/mockobjects.html I've got no problem with re-arranging things to make the layout clear and the build file is far from as simple as I think it could be, but I'd be very un-happy to see us abandon it infavour of something else. ANy effort in changing the project layout should be based arround this system and making it nicer to intergrate with IDE's rather than concentrating on one IDE and leaving the build file as a vestigial process. It's also the basis for some work I've started for producing RPM spec files which will make installation on RPM based systems much easier to handle. > > Having played with the dynamic mock stuff I am suprised that all the people > that I've seen post messages about using it - haven't complained about the > horrible error messages (the original non dynamic version went to great > pains to provide useful error messages that would help you quickly locate an > error and fix it - see my paper A Plea for Assert Equals). I'm also suprised > no-one has needed an UnorderedExpectationList... I think this is really an > indication that people just haven't used this stuff in anger, or seen how it > works at connextra to know that there is much better. > > Anyway - all this aside, I'm a bit perturbed by all this complication and > would like to try creating a whole new Project that takes the best from both > worlds. With the dynamic stuff you can drastically cut down the hard coded > mocks you need (e.g. httpServletRequest can use a dynamic version) although > some clases that don't have interfaces (like stream stuff) will need hard > coded versions. Plus there are some useful helper classes that are kicking > around in the connextra code base that they have agreed to donate. > > So I'm thinking maybe having a mockobjects-java-dynamic (or > mockobjects2-java?) module with a simple src subdirectory and just pulling > all of the relevent pieces in one by one as I need them (I am doing some > work for a company called e2x and we are using the mocks in anger - with > myself and john nolan on site to supervise their usage). If I can do this - > and get a good starting point, then everyone can jump in and do all the > magic that you normally do to make it all open-sourcy. > I really think this is the wrong thing to do. If there's something wrong with things at the moment then we should be trying to migrate what we have rather than abandon it and all the work that has gone into it and the people who are already using it. Open source projects work best when every moves together at the same pace. The whole thing it about tiny steps. If nothing else trying to start a new project put's you under pressure as your then the single point of failure, everyones stood around waiting for the hero's to rush in and save them. "everyone can jump in and do all the magic that you normally do to make it all open-sourcy" -- and the award for best supporting programmer goes to ... > what do you think? We have to make life simpler for ourselves and stop > having to answer the "method x is not implemented in that mock here's my > patch" hard work that seems to be going on at the moment. I like this approach. One of the reasons I've no been hot on the dynamic stuff is that I see it as encouraging people to be continually re-inventing the wheel rather than pooling our efforts and reusing each others code. It's not that hard to create a patch it's not that hard to apply one. Every other "open-sourcy" project seems to manage it why is it beyond our capabilities. > > Tim > --- > Outgoing mail is certified Virus Free. > Checked by AVG anti-virus system (http://www.grisoft.com). > Version: 6.0.463 / Virus Database: 262 - Release Date: 17/03/2003 > > > > ------------------------------------------------------- > This SF.net email is sponsored by:Crypto Challenge is now open! > Get cracking and register here for some mind boggling fun and > the chance of winning an Apple iPod: > http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0031en > _______________________________________________ > Mockobjects-java-dev mailing list > Moc...@li... > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev |
From: Nat P. <nat...@b1...> - 2003-03-24 09:35:23
|
> Its certainly not easy to just pull this down in eclipse and use it... there > are jdk versions to worry about (yes I know this is an issue but only for > very advanced stuff - surely?), and the directory structures don't easily > map into the eclipse view of the world (I guess you guys all use some > complicated scheme in intellij? But why not use eclipse as the lowest common > denominator? I'm using Eclipse and have had no problem bringing the MO CVS repository into Eclipse. Yes, it's a bit more involved than the projects that are created by Eclipse's wizards, but then it has to deal with more complicated issues such as supporting multiple versions of the JDK in one project. Can you describe the problems you've had with Eclipse in more detail? > Having played with the dynamic mock stuff I am suprised that all the people > that I've seen post messages about using it - haven't complained about the > horrible error messages (the original non dynamic version went to great > pains to provide useful error messages that would help you quickly locate an > error and fix it - see my paper A Plea for Assert Equals). I'm also suprised > no-one has needed an UnorderedExpectationList... I think this is really an > indication that people just haven't used this stuff in anger, or seen how it > works at connextra to know that there is much better. The dynamic mocks can be improved in many ways. Unfortunately I've been offline for a couple of months while working in Africa and have not had a chance to put as much effort into the project as I'd have liked. Now that I'm back I will be conferring with Joe, Steve F and other mockistas to make sure that the dynamic package evolves in a good direction. Help is always appreciated. Could you describe how you think error messages can be improved? Cheers, Nat. |
From: Steve F. <st...@m3...> - 2003-03-23 22:40:45
|
Tim wrote: > Guys - I've always used an internal connextra version of the mock > objects stuff. Now I'm no longer with connextra I thought I would try > using the official release and see if I could maybe integrate some > stuff... but why is it so complicated? because we have to support multiple VMs and multiple J2ee's. Yes, it's a pig. > Its certainly not easy to just pull this down in eclipse and use > it... there are jdk versions to worry about (yes I know this is an > issue but only for very advanced stuff - surely?), and the directory > structures don't easily map into the eclipse view of the world (I > guess you guys all use some complicated scheme in intellij? But why > not use eclipse as the lowest common denominator? It can be setup in an eclipse project, it's not an Idea thing. Given that VisualAge is effectively dead, some of those issues will have gone away. > what do you think? We have to make life simpler for ourselves and > stop having to answer the "method x is not implemented in that mock > here's my patch" hard work that seems to be going on at the moment. I think a rebuild is an excellent idea, we've gone off the rails in a couple of places, but we might want to do it incrementally. We still want a batch build, and I stronly suspect that we'll want some stuff that will vary by version. I suggest that the first step would be to pull out the website and the alt. packages. S. |
From: Tim <ma...@po...> - 2003-03-23 22:01:45
|
Guys - I've always used an internal connextra version of the mock objects stuff. Now I'm no longer with connextra I thought I would try using the official release and see if I could maybe integrate some stuff... but why is it so complicated? Its certainly not easy to just pull this down in eclipse and use it... there are jdk versions to worry about (yes I know this is an issue but only for very advanced stuff - surely?), and the directory structures don't easily map into the eclipse view of the world (I guess you guys all use some complicated scheme in intellij? But why not use eclipse as the lowest common denominator? I want a head version in my environment that I can easily apply fixes to and check in - I have access to lots of code and ideas, but it has to be simple for me to make modifications with an onsite partner and put them back in (without lots of messing around - this is why lots of good stuff got left out, because for ages connextra used visual age and it was too much work to put stuff back in, so we just didn't). Having played with the dynamic mock stuff I am suprised that all the people that I've seen post messages about using it - haven't complained about the horrible error messages (the original non dynamic version went to great pains to provide useful error messages that would help you quickly locate an error and fix it - see my paper A Plea for Assert Equals). I'm also suprised no-one has needed an UnorderedExpectationList... I think this is really an indication that people just haven't used this stuff in anger, or seen how it works at connextra to know that there is much better. Anyway - all this aside, I'm a bit perturbed by all this complication and would like to try creating a whole new Project that takes the best from both worlds. With the dynamic stuff you can drastically cut down the hard coded mocks you need (e.g. httpServletRequest can use a dynamic version) although some clases that don't have interfaces (like stream stuff) will need hard coded versions. Plus there are some useful helper classes that are kicking around in the connextra code base that they have agreed to donate. So I'm thinking maybe having a mockobjects-java-dynamic (or mockobjects2-java?) module with a simple src subdirectory and just pulling all of the relevent pieces in one by one as I need them (I am doing some work for a company called e2x and we are using the mocks in anger - with myself and john nolan on site to supervise their usage). If I can do this - and get a good starting point, then everyone can jump in and do all the magic that you normally do to make it all open-sourcy. what do you think? We have to make life simpler for ourselves and stop having to answer the "method x is not implemented in that mock here's my patch" hard work that seems to be going on at the moment. Tim --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.463 / Virus Database: 262 - Release Date: 17/03/2003 |
From: Johannsen, C. <cjo...@re...> - 2003-03-21 17:22:08
|
>| Don't think there's any reason, just no one has needed to do that yet. >My comment has nothing to do with MockConnection, but usually it is >better for database performance if you use prepared statements, at least >if there are variable parameters. >(At least some) databases cache statements execution plans and use the >string statement as key for the plan - this doesn't work with changing >parameters in every execute. Even worse, as the database cache is >limited in size, it may be that ad hoc statements even make prepared >statements flush from the cache. >(On the other hand, perfect reasons for adhoc statements exist, just >wanted to share this thought) I agree,and normally use PreparedStatements (if for nothing else than the type conversion for Strings), but in this case I'm dealing with code someone else has written, that I cannot alter (for a variety of reasons). There are certainly performance tradeoffs between Statement and PreparedStatement, but I normally find PreparedStatements more useable, even if they are generally slower (and require more round-trips to the database). Cory |
From: Olaf K. <ok...@ab...> - 2003-03-21 17:03:44
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 | Don't think there's any reason, just no one has needed to do that yet. My comment has nothing to do with MockConnection, but usually it is better for database performance if you use prepared statements, at least if there are variable parameters. (At least some) databases cache statements execution plans and use the string statement as key for the plan - this doesn't work with changing parameters in every execute. Even worse, as the database cache is limited in size, it may be that ad hoc statements even make prepared statements flush from the cache. (On the other hand, perfect reasons for adhoc statements exist, just wanted to share this thought) Olaf -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.0 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQE+e0XC7/xtFKqdCzURAt8vAJ4m3dukx5iz8d+K/LSbw677mepicgCfeVvG ExnOp/4rx2kvY2Gpf7n9F8c= =v08c -----END PGP SIGNATURE----- |
From: Jeff M. <je...@mk...> - 2003-03-21 16:55:02
|
Don't think there's any reason, just no one has needed to do that yet. If you do want to enhance it it would probably be better to use CommonMockConnection2 rather than CommonMockConnection as the later is deprecated in favour of the former. On Fri, 2003-03-21 at 16:19, Johannsen, Cory wrote: > Hello, > > Is there a reason that CommonMockConnection only allows a single > Statement, but allows multiple PreparedStatements? I have a code > chunk that executes two separate Statements (different SQL) in order, > and the test fails since the CommonMockConnection implementation only > allows a single Statement. > > If there is no particular reason that this limitation is present, I'd > like to enhance CommonMockConnection to allow multiple Statements in > the same manner that it allows multiple PreparedStatements. > > Cory Johannsen > |
From: Johannsen, C. <cjo...@re...> - 2003-03-21 16:40:05
|
Hello, Is there a reason that CommonMockConnection only allows a single Statement, but allows multiple PreparedStatements? I have a code chunk that executes two separate Statements (different SQL) in order, and the test fails since the CommonMockConnection implementation only allows a single Statement. If there is no particular reason that this limitation is present, I'd like to enhance CommonMockConnection to allow multiple Statements in the same manner that it allows multiple PreparedStatements. Cory Johannsen |
From: Jeff M. <cus...@us...> - 2003-03-18 14:28:50
|
Update of /cvsroot/mockobjects/mockobjects-java/src/j2ee/common/com/mockobjects/naming/directory In directory sc8-pr-cvs1:/tmp/cvs-serv22955/src/j2ee/common/com/mockobjects/naming/directory Modified Files: MockAttribute.java MockDirContext.java Log Message: Pepper Mocks with ReturnValue Index: MockAttribute.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/j2ee/common/com/mockobjects/naming/directory/MockAttribute.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- MockAttribute.java 22 Feb 2002 16:25:05 -0000 1.1 +++ MockAttribute.java 18 Mar 2003 14:28:44 -0000 1.2 @@ -5,7 +5,7 @@ import javax.naming.*; public class MockAttribute extends MockObject implements Attribute{ - private Object myObjectToReturn; + private final ReturnValue myObjectToReturn = new ReturnValue("object"); public NamingEnumeration getAll() throws NamingException{ notImplemented(); @@ -13,11 +13,11 @@ } public void setupGet(Object aObjectToReturn){ - this.myObjectToReturn = aObjectToReturn; + this.myObjectToReturn.setValue(aObjectToReturn); } public Object get() throws NamingException{ - return myObjectToReturn; + return myObjectToReturn.getValue(); } public int size(){ Index: MockDirContext.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/j2ee/common/com/mockobjects/naming/directory/MockDirContext.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- MockDirContext.java 22 Feb 2002 16:25:05 -0000 1.1 +++ MockDirContext.java 18 Mar 2003 14:28:44 -0000 1.2 @@ -2,59 +2,60 @@ import javax.naming.*; import javax.naming.directory.*; + import com.mockobjects.*; import com.mockobjects.naming.*; -public class MockDirContext extends MockContext implements DirContext{ - private Attributes myAttributeToReturn; - private ExpectationValue myName = new ExpectationValue("myName"); +public class MockDirContext extends MockContext implements DirContext { + private final ReturnValue myAttributeToReturn = new ReturnValue("attribute"); + private final ExpectationValue myName = new ExpectationValue("myName"); private ExpectationValue mySearchName = new ExpectationValue("mySearchName"); - private ExpectationValue myAttributes = + private final ExpectationValue myAttributes = new ExpectationValue("myAttributes"); - private ExpectationValue myModificationOperation = + private final ExpectationValue myModificationOperation = new ExpectationValue("myModificationOperation"); - private ExpectationValue myFilter = new ExpectationValue("myFilter"); - private ExpectationValue mySearchControls = new ExpectationValue("mySearchControls"); - private NamingEnumeration myResults; + private final ExpectationValue myFilter = new ExpectationValue("myFilter"); + private final ExpectationValue mySearchControls = new ExpectationValue("mySearchControls"); + private final ReturnValue myResults = new ReturnValue("results"); private ExpectationCounter myAttributesCallCount = new ExpectationCounter("getAttributes"); - public void setupAttributes(Attributes anAttributeToReturn){ - this.myAttributeToReturn = anAttributeToReturn; + public void setupAttributes(Attributes anAttributeToReturn) { + this.myAttributeToReturn.setValue(anAttributeToReturn); } - public void setExpectedGetAttributesName(Object aName){ + public void setExpectedGetAttributesName(Object aName) { this.myName.setExpected(aName); } - public void setExpectedGetAttributesCount(int callCount){ + public void setExpectedGetAttributesCount(int callCount) { this.myAttributesCallCount.setExpected(callCount); } - public Attributes getAttributes(Name aName) throws NamingException{ + public Attributes getAttributes(Name aName) throws NamingException { return getAttributes(aName.toString()); } - public Attributes getAttributes(String aName) throws NamingException{ + public Attributes getAttributes(String aName) throws NamingException { return getAttributes(aName, null); } public Attributes getAttributes(Name aName, String[] attrIds) - throws NamingException{ + throws NamingException { return getAttributes(aName.toString(), attrIds); } public Attributes getAttributes(String aName, String[] attrIds) - throws NamingException{ + throws NamingException { this.myName.setActual(aName); this.myAttributesCallCount.inc(); - return myAttributeToReturn; + return (Attributes) myAttributeToReturn.getValue(); } public void setExpectedModifyAttributes(String aName, - int aModificationOperation, Attributes attributes){ + int aModificationOperation, Attributes attributes) { this.myName.setExpected(aName); this.myModificationOperation.setExpected(aModificationOperation); @@ -62,13 +63,13 @@ } public void modifyAttributes(Name aName, int aModificationOperation, - Attributes attributes) throws NamingException{ + Attributes attributes) throws NamingException { modifyAttributes(aName.toString(), aModificationOperation, attributes); } public void modifyAttributes(String aName, int aModificationOperation, - Attributes attributes) throws NamingException{ + Attributes attributes) throws NamingException { this.myName.setActual(aName); this.myModificationOperation.setActual(aModificationOperation); @@ -76,121 +77,121 @@ } public void modifyAttributes(Name aName, ModificationItem[] mods) - throws NamingException{ + throws NamingException { notImplemented(); } public void modifyAttributes(String aName, ModificationItem[] mods) - throws NamingException{ + throws NamingException { notImplemented(); } public void bind(Name aName, Object object, Attributes attributes) - throws NamingException{ + throws NamingException { notImplemented(); } public void bind(String aName, Object object, Attributes attributes) - throws NamingException{ + throws NamingException { notImplemented(); } public void rebind(Name aName, Object object, Attributes attributes) - throws NamingException{ + throws NamingException { notImplemented(); } public void rebind(String aName, Object object, Attributes attributes) - throws NamingException{ + throws NamingException { notImplemented(); } public DirContext createSubcontext(Name aName, Attributes attributes) - throws NamingException{ + throws NamingException { notImplemented(); return null; } public DirContext createSubcontext(String aName, Attributes attributes) - throws NamingException{ + throws NamingException { notImplemented(); return null; } - public DirContext getSchema(Name aName) throws NamingException{ + public DirContext getSchema(Name aName) throws NamingException { notImplemented(); return null; } - public DirContext getSchema(String aName) throws NamingException{ + public DirContext getSchema(String aName) throws NamingException { notImplemented(); return null; } public DirContext getSchemaClassDefinition(Name aName) - throws NamingException{ + throws NamingException { notImplemented(); return null; } public DirContext getSchemaClassDefinition(String aName) - throws NamingException{ + throws NamingException { notImplemented(); return null; } public NamingEnumeration search(Name aName, Attributes attributes, - String[] anAttributeToReturn) throws NamingException{ - return myResults; + String[] anAttributeToReturn) throws NamingException { + return (NamingEnumeration) myResults.getValue(); } public NamingEnumeration search(String aName, Attributes attributes, - String[] anAttributeToReturn) throws NamingException{ - return myResults; + String[] anAttributeToReturn) throws NamingException { + return (NamingEnumeration) myResults.getValue(); } public NamingEnumeration search(Name aName, Attributes attributes) - throws NamingException{ - return myResults; + throws NamingException { + return (NamingEnumeration) myResults.getValue(); } public NamingEnumeration search(String aName, Attributes attributes) - throws NamingException{ - return myResults; + throws NamingException { + return (NamingEnumeration) myResults.getValue(); } public NamingEnumeration search(Name aName, String aFilter, - SearchControls cons) throws NamingException{ - return myResults; + SearchControls cons) throws NamingException { + return (NamingEnumeration) myResults.getValue(); } public void setExpectedSearch(String aSearchName, String aFilter, - SearchControls searchControls){ + SearchControls searchControls) { this.mySearchName.setExpected(aSearchName); this.myFilter.setExpected(aFilter); this.mySearchControls.setExpected(searchControls); } - public void setupSearchResult(NamingEnumeration results){ - this.myResults = results; + public void setupSearchResult(NamingEnumeration results) { + this.myResults.setValue(results); } public NamingEnumeration search(String aSearchName, String aFilter, - SearchControls searchControls) throws NamingException{ + SearchControls searchControls) throws NamingException { this.mySearchName.setActual(aSearchName); this.myFilter.setActual(aFilter); this.mySearchControls.setActual(searchControls); - return myResults; + return (NamingEnumeration) myResults.getValue(); } public NamingEnumeration search(Name aName, String aFilter, - Object[] filterArgs, SearchControls cons) throws NamingException{ - return myResults; + Object[] filterArgs, SearchControls cons) throws NamingException { + return (NamingEnumeration) myResults.getValue(); } public NamingEnumeration search(String aName, String aFilter, - Object[] filterArgs, SearchControls cons) throws NamingException{ - return myResults; + Object[] filterArgs, SearchControls cons) throws NamingException { + return (NamingEnumeration) myResults.getValue(); } } |
From: Jeff M. <cus...@us...> - 2003-03-18 14:28:49
|
Update of /cvsroot/mockobjects/mockobjects-java/src/jdk/common/com/mockobjects/net In directory sc8-pr-cvs1:/tmp/cvs-serv22955/src/jdk/common/com/mockobjects/net Modified Files: MockSocket.java MockSocketFactory.java Log Message: Pepper Mocks with ReturnValue Index: MockSocket.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/jdk/common/com/mockobjects/net/MockSocket.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- MockSocket.java 19 Jun 2002 15:26:24 -0000 1.1 +++ MockSocket.java 18 Mar 2003 14:28:45 -0000 1.2 @@ -4,6 +4,7 @@ import com.mockobjects.ExpectationCounter; import com.mockobjects.ExpectationValue; import com.mockobjects.MockObject; +import com.mockobjects.ReturnValue; import java.io.IOException; import java.io.InputStream; @@ -13,10 +14,9 @@ public class MockSocket extends MockObject implements Socket { private final ExpectationValue mySoTimeout = new ExpectationValue("so timeout"); - private InputStream myInputStream; - private OutputStream myOutputStream; - private final ExpectationCounter myCloseCalls = - new ExpectationCounter("close calls"); + private final ReturnValue myInputStream = new ReturnValue("input stream"); + private final ReturnValue myOutputStream = new ReturnValue("output stream"); + private final ExpectationCounter myCloseCalls = new ExpectationCounter("close calls"); public InetAddress getInetAddress() { notImplemented(); @@ -39,19 +39,19 @@ } public void setupGetInputStream(InputStream anInputStream) { - myInputStream = anInputStream; + myInputStream.setValue(anInputStream); } public InputStream getInputStream() throws IOException { - return myInputStream; + return (InputStream) myInputStream.getValue(); } public void setupGetOutputStream(OutputStream anOutputStream) { - myOutputStream = anOutputStream; + myOutputStream.setValue(anOutputStream); } public OutputStream getOutputStream() throws IOException { - return myOutputStream; + return (OutputStream) myOutputStream.getValue(); } public void setTcpNoDelay(boolean on) throws SocketException { Index: MockSocketFactory.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/jdk/common/com/mockobjects/net/MockSocketFactory.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- MockSocketFactory.java 19 Jun 2002 15:26:25 -0000 1.1 +++ MockSocketFactory.java 18 Mar 2003 14:28:45 -0000 1.2 @@ -4,27 +4,28 @@ import alt.java.net.Socket; import com.mockobjects.MockObject; import com.mockobjects.ExpectationValue; +import com.mockobjects.ReturnValue; -public class MockSocketFactory extends MockObject implements SocketFactory{ +public class MockSocketFactory extends MockObject implements SocketFactory { private final ExpectationValue myHost = new ExpectationValue("host"); private final ExpectationValue myPort = new ExpectationValue("port"); - private Socket mySocket; + private final ReturnValue mySocket = new ReturnValue("socket"); - public void setupCreateSocket(Socket aSocket){ - mySocket = aSocket; + public void setupCreateSocket(Socket aSocket) { + mySocket.setValue(aSocket); } - public void setExpectedHost(String aHost){ + public void setExpectedHost(String aHost) { myHost.setExpected(aHost); } - public void setExpectedPort(String aPort){ + public void setExpectedPort(String aPort) { myPort.setExpected(aPort); } public Socket createSocket(String aHost, int aPort) { myHost.setActual(aHost); myPort.setActual(aPort); - return mySocket; + return (Socket) mySocket.getValue(); } } |
Update of /cvsroot/mockobjects/mockobjects-java/src/j2ee/common/com/mockobjects/jms In directory sc8-pr-cvs1:/tmp/cvs-serv22955/src/j2ee/common/com/mockobjects/jms Modified Files: MockConnection.java MockMessage.java MockMessageConsumer.java MockMessageProducer.java MockObjectMessage.java MockQueue.java MockQueueConnection.java MockQueueConnectionFactory.java MockQueueSession.java MockTemporaryQueue.java MockTextMessage.java MockTopicConnection.java MockTopicConnectionFactory.java MockTopicSession.java Log Message: Pepper Mocks with ReturnValue Index: MockConnection.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/j2ee/common/com/mockobjects/jms/MockConnection.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- MockConnection.java 28 Jun 2002 17:35:39 -0000 1.3 +++ MockConnection.java 18 Mar 2003 14:28:44 -0000 1.4 @@ -15,9 +15,6 @@ private JMSException myException; - public MockConnection() { - } - public void close() throws JMSException { myCloseCalls.inc(); throwExceptionIfAny(); Index: MockMessage.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/j2ee/common/com/mockobjects/jms/MockMessage.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- MockMessage.java 5 Apr 2002 10:45:43 -0000 1.2 +++ MockMessage.java 18 Mar 2003 14:28:44 -0000 1.3 @@ -16,7 +16,7 @@ /** * Used for both messageID and correlationID */ - private String myJMSMessageID; + private final ReturnValue myJMSMessageID = new ReturnValue("messageID / correlationID"); public void acknowledge() throws JMSException { myAcknowledgeCount.inc(); @@ -60,7 +60,7 @@ } public String getJMSCorrelationID() { - return myJMSMessageID; + return (String)myJMSMessageID.getValue(); } public byte[] getJMSCorrelationIDAsBytes() { @@ -84,7 +84,7 @@ } public String getJMSMessageID() { - return myJMSMessageID; + return (String)myJMSMessageID.getValue(); } public int getJMSPriority() { @@ -232,7 +232,7 @@ } public void setupJMSMessageID(String jmsMessageID) { - myJMSMessageID = jmsMessageID; + myJMSMessageID.setValue(jmsMessageID); } public void setupThrowException(JMSException e) { Index: MockMessageConsumer.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/j2ee/common/com/mockobjects/jms/MockMessageConsumer.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- MockMessageConsumer.java 21 Feb 2003 14:07:24 -0000 1.3 +++ MockMessageConsumer.java 18 Mar 2003 14:28:44 -0000 1.4 @@ -4,7 +4,7 @@ import javax.jms.*; public class MockMessageConsumer extends MockObject implements MessageConsumer{ - private Message myMessage; + private final ReturnValue myMessage = new ReturnValue("message"); private boolean myExpiresOnTimeout = false; private JMSException myException; protected ExpectationCounter myCloseCalls = @@ -47,7 +47,7 @@ } } } - return myMessage; + return (Message)myMessage.getValue(); } public Message receive(long timeout) throws JMSException { @@ -57,7 +57,7 @@ if (myExpiresOnTimeout) { return null; } else { - return myMessage; + return (Message)myMessage.getValue(); } } @@ -68,7 +68,7 @@ public Message receiveNoWait() throws JMSException { throwExceptionIfAny(); myReceiveCalls.inc(); - return myMessage; + return (Message)myMessage.getValue(); } public void setExpectedCloseCalls(int callCount) { @@ -80,7 +80,7 @@ } public void setupReceivedMessage(Message message) { - myMessage = message; + myMessage.setValue(message); } public void setupExpiresOnTimeout(boolean expiresOnTimeout) { Index: MockMessageProducer.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/j2ee/common/com/mockobjects/jms/MockMessageProducer.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- MockMessageProducer.java 22 Feb 2002 16:25:05 -0000 1.1 +++ MockMessageProducer.java 18 Mar 2003 14:28:44 -0000 1.2 @@ -5,12 +5,9 @@ public abstract class MockMessageProducer extends MockObject implements MessageProducer { - protected ExpectationCounter myCloseCalls = new ExpectationCounter("MockMessageConsumer.close"); + protected final ExpectationCounter myCloseCalls = new ExpectationCounter("MockMessageConsumer.close"); private JMSException myException; - - public MockMessageProducer() { - } public void close() throws JMSException { myCloseCalls.inc(); Index: MockObjectMessage.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/j2ee/common/com/mockobjects/jms/MockObjectMessage.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- MockObjectMessage.java 23 Feb 2002 18:50:35 -0000 1.1 +++ MockObjectMessage.java 18 Mar 2003 14:28:44 -0000 1.2 @@ -1,18 +1,20 @@ package com.mockobjects.jms; +import com.mockobjects.ReturnValue; + import java.io.*; import javax.jms.*; public class MockObjectMessage extends MockMessage implements ObjectMessage{ - private Serializable objectToReturn; + private final ReturnValue objectToReturn = new ReturnValue("object"); public void setupGetObject(Serializable objectToReturn){ - this.objectToReturn = objectToReturn; + this.objectToReturn.setValue(objectToReturn); } public Serializable getObject() throws JMSException{ - return objectToReturn; + return (Serializable)objectToReturn.getValue(); } public void setObject(Serializable serialisable) throws JMSException{ Index: MockQueue.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/j2ee/common/com/mockobjects/jms/MockQueue.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- MockQueue.java 21 Feb 2003 14:07:24 -0000 1.2 +++ MockQueue.java 18 Mar 2003 14:28:44 -0000 1.3 @@ -1,6 +1,7 @@ package com.mockobjects.jms; import com.mockobjects.MockObject; +import com.mockobjects.ReturnValue; import javax.jms.JMSException; import javax.jms.Queue; @@ -8,33 +9,19 @@ public class MockQueue extends MockObject implements Queue { private JMSException myException; - private String myName; - - public MockQueue(String name) { - myName = name; - } + private final ReturnValue myName = new ReturnValue("name"); public String getQueueName() throws JMSException { throwExceptionIfAny(); - return myName; - } - - public boolean equals(Object object) { - if (!(object instanceof Queue)) return false; - try { - return myName.equals(((Queue) object).getQueueName()); - } catch (JMSException e) { - throw new junit.framework.AssertionFailedError( - "JMSException caught while getting actual queue name"); - } + return (String)myName.getValue(); } - public int hashCode() { - return myName.hashCode(); + public void setupGetQueueName(final String name){ + myName.setValue(name); } public String toString() { - return this.getClass().getName() + ", " + myName; + return this.getClass().getName() + ", " + myName.getValue(); } public void setupThrowException(JMSException e) { Index: MockQueueConnection.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/j2ee/common/com/mockobjects/jms/MockQueueConnection.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- MockQueueConnection.java 22 Feb 2002 16:25:05 -0000 1.1 +++ MockQueueConnection.java 18 Mar 2003 14:28:44 -0000 1.2 @@ -5,7 +5,7 @@ public class MockQueueConnection extends MockConnection implements QueueConnection { - private QueueSession myQueueSession; + private final ReturnValue myQueueSession = new ReturnValue("queue session"); public MockQueueConnection() { } @@ -20,10 +20,10 @@ public QueueSession createQueueSession(boolean transacted, int acknowledgeMode) throws JMSException { throwExceptionIfAny(); - return myQueueSession; + return (QueueSession)myQueueSession.getValue(); } public void setupQueueSession(QueueSession queueSession) { - myQueueSession = queueSession; + myQueueSession.setValue(queueSession); } } Index: MockQueueConnectionFactory.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/j2ee/common/com/mockobjects/jms/MockQueueConnectionFactory.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- MockQueueConnectionFactory.java 22 Feb 2002 16:25:05 -0000 1.1 +++ MockQueueConnectionFactory.java 18 Mar 2003 14:28:44 -0000 1.2 @@ -1,52 +1,50 @@ package com.mockobjects.jms; import com.mockobjects.*; + import javax.jms.*; public class MockQueueConnectionFactory extends MockObject implements - QueueConnectionFactory { + QueueConnectionFactory { + + private final ExpectationValue myUserName = new ExpectationValue("MockQueueConnectionFactory.createQueueConnection"); + private final ExpectationValue myPassword = new ExpectationValue("MockQueueConnectionFactory.createQueueConnection"); - protected ExpectationValue myUserName = new ExpectationValue("MockQueueConnectionFactory.createQueueConnection"); - protected ExpectationValue myPassword = new ExpectationValue("MockQueueConnectionFactory.createQueueConnection"); + private JMSException myException; + private final ReturnValue myQueueConnection = new ReturnValue("queue connection"); + + public QueueConnection createQueueConnection() throws JMSException { + throwExceptionIfAny(); + return (QueueConnection) myQueueConnection.getValue(); + } - private JMSException myException; - private QueueConnection myQueueConnection; + public QueueConnection createQueueConnection(String userName, String password) + throws JMSException { + throwExceptionIfAny(); + myUserName.setActual(userName); + myPassword.setActual(password); + return (QueueConnection) myQueueConnection.getValue(); + } + + public void setExpectedUserName(String userName) { + myUserName.setExpected(userName); + } + + public void setExpectedPassword(String password) { + myPassword.setExpected(password); + } + + public void setupQueueConnection(QueueConnection queueConnection) { + myQueueConnection.setValue(queueConnection); + } + + public void setupThrowException(JMSException e) { + myException = e; + } - public MockQueueConnectionFactory() { - } - - public QueueConnection createQueueConnection() throws JMSException { - throwExceptionIfAny(); - return myQueueConnection; - } - - public QueueConnection createQueueConnection(String userName, String password) - throws JMSException { - throwExceptionIfAny(); - myUserName.setActual(userName); - myPassword.setActual(password); - return myQueueConnection; - } - - public void setExpectedUserName(String userName) { - myUserName.setExpected(userName); - } - - public void setExpectedPassword(String password) { - myPassword.setExpected(password); - } - - public void setupQueueConnection(QueueConnection queueConnection) { - myQueueConnection = queueConnection; - } - - public void setupThrowException(JMSException e) { - myException = e; - } - - private void throwExceptionIfAny() throws JMSException { - if (null != myException) { - throw myException; + private void throwExceptionIfAny() throws JMSException { + if (null != myException) { + throw myException; + } } - } } Index: MockQueueSession.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/j2ee/common/com/mockobjects/jms/MockQueueSession.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- MockQueueSession.java 21 Feb 2003 14:07:25 -0000 1.2 +++ MockQueueSession.java 18 Mar 2003 14:28:44 -0000 1.3 @@ -11,6 +11,7 @@ private final ExpectationValue messageSelector = new ExpectationValue("message selector"); private final ExpectationValue queue = new ExpectationValue("queue"); + private final ReturnValue queueToReturn = new ReturnValue("queue"); private final ReturnValue myReceiver = new ReturnValue("reciever"); private final ReturnValue mySender = new ReturnValue("reciever"); private final ReturnValue myTemporaryQueue = new ReturnValue("reciever"); @@ -34,9 +35,13 @@ return null; } + public void setupCreateQueue(Queue queue) { + this.queueToReturn.setValue(queue); + } + public Queue createQueue(String queueName) throws JMSException { throwExceptionIfAny(); - return new MockQueue(queueName); + return (Queue) queueToReturn.getValue(); } public QueueReceiver createReceiver(Queue queue) throws JMSException { Index: MockTemporaryQueue.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/j2ee/common/com/mockobjects/jms/MockTemporaryQueue.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- MockTemporaryQueue.java 22 Feb 2002 16:25:05 -0000 1.1 +++ MockTemporaryQueue.java 18 Mar 2003 14:28:44 -0000 1.2 @@ -6,11 +6,7 @@ public class MockTemporaryQueue extends MockQueue implements TemporaryQueue { - protected ExpectationCounter myDeleteCalls = new ExpectationCounter("MockTemporaryQueue.delete"); - - public MockTemporaryQueue() { - super("TemporaryQueue"); - } + private final ExpectationCounter myDeleteCalls = new ExpectationCounter("MockTemporaryQueue.delete"); public void delete() throws JMSException { myDeleteCalls.inc(); @@ -20,4 +16,4 @@ public void setExpectedDeleteCalls(int callCount) { myDeleteCalls.setExpected(callCount); } -} \ No newline at end of file +} Index: MockTextMessage.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/j2ee/common/com/mockobjects/jms/MockTextMessage.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- MockTextMessage.java 22 Feb 2002 16:25:05 -0000 1.1 +++ MockTextMessage.java 18 Mar 2003 14:28:44 -0000 1.2 @@ -6,25 +6,22 @@ public class MockTextMessage extends MockMessage implements TextMessage { - protected ExpectationValue myExpectedText = new ExpectationValue("MockTextMessage.setText"); - private String myText; + private final ExpectationValue myExpectedText = new ExpectationValue("MockTextMessage.setText"); + private final ReturnValue myText = new ReturnValue("text"); - public MockTextMessage() { - } + public void setText(String text) { + myExpectedText.setActual(text); + } - public MockTextMessage(String text) { - myText = text; - } + public String getText() { + return (String)myText.getValue(); + } - public void setText(String text) { - myExpectedText.setActual(text); - } + public void setupGetText(String text) { + myText.setValue(text); + } - public String getText() { - return myText; - } - - public void setExpectedText(String text) { - myExpectedText.setExpected(text); - } + public void setExpectedText(String text) { + myExpectedText.setExpected(text); + } } Index: MockTopicConnection.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/j2ee/common/com/mockobjects/jms/MockTopicConnection.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- MockTopicConnection.java 22 Apr 2002 16:53:13 -0000 1.2 +++ MockTopicConnection.java 18 Mar 2003 14:28:44 -0000 1.3 @@ -1,35 +1,36 @@ package com.mockobjects.jms; import com.mockobjects.*; + import javax.jms.*; -public class MockTopicConnection extends MockConnection implements TopicConnection{ +public class MockTopicConnection extends MockConnection implements TopicConnection { - private TopicSession topicSessionToReturn; + private final ReturnValue topicSessionToReturn = new ReturnValue("topic session"); - public void setupCreateTopicSession(TopicSession topicSessionToReturn){ - this.topicSessionToReturn = topicSessionToReturn; + public void setupCreateTopicSession(TopicSession topicSessionToReturn) { + this.topicSessionToReturn.setValue(topicSessionToReturn); } public ConnectionConsumer createConnectionConsumer(Topic topic, - String messageSelector, ServerSessionPool sessionPool, int maxMessages) - throws JMSException{ + String messageSelector, ServerSessionPool sessionPool, int maxMessages) + throws JMSException { notImplemented(); return null; } - + public ConnectionConsumer createDurableConnectionConsumer(Topic topic, - String subscriptionName, String messageSelector, - ServerSessionPool sessionPool, int maxMessages) throws JMSException{ + String subscriptionName, String messageSelector, + ServerSessionPool sessionPool, int maxMessages) throws JMSException { notImplemented(); return null; } public TopicSession createTopicSession(boolean transacted, - int acknowledgeMode) throws JMSException{ + int acknowledgeMode) throws JMSException { - return topicSessionToReturn; + return (TopicSession)topicSessionToReturn.getValue(); } } Index: MockTopicConnectionFactory.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/j2ee/common/com/mockobjects/jms/MockTopicConnectionFactory.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- MockTopicConnectionFactory.java 23 Feb 2002 18:50:35 -0000 1.1 +++ MockTopicConnectionFactory.java 18 Mar 2003 14:28:44 -0000 1.2 @@ -6,21 +6,21 @@ public class MockTopicConnectionFactory extends MockObject implements TopicConnectionFactory{ - private TopicConnection topicConnectionToReturn; + private final ReturnValue topicConnectionToReturn = new ReturnValue("topic connection"); public void setupCreateTopicConnection( TopicConnection topicConnectionToReturn){ - this.topicConnectionToReturn = topicConnectionToReturn; + this.topicConnectionToReturn.setValue(topicConnectionToReturn); } public TopicConnection createTopicConnection() throws JMSException{ - return topicConnectionToReturn; + return (TopicConnection)topicConnectionToReturn.getValue(); } public TopicConnection createTopicConnection(String userName, String password) throws JMSException{ - return topicConnectionToReturn; + return (TopicConnection)topicConnectionToReturn.getValue(); } } Index: MockTopicSession.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/j2ee/common/com/mockobjects/jms/MockTopicSession.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- MockTopicSession.java 22 Apr 2002 16:53:13 -0000 1.3 +++ MockTopicSession.java 18 Mar 2003 14:28:44 -0000 1.4 @@ -4,15 +4,15 @@ import javax.jms.*; public class MockTopicSession extends MockSession implements TopicSession{ - private Topic topicToReturn; + private final ReturnValue topicToReturn = new ReturnValue("topic"); private ExpectationValue topicName = new ExpectationValue("topicName"); private ExpectationCounter createTopicCalls = new ExpectationCounter("createTopicCalls"); - private TopicPublisher topicPublisherToReturn; - private TopicSubscriber topicSubscriberToReturn; + private final ReturnValue topicPublisherToReturn = new ReturnValue("topic publisher"); + private final ReturnValue topicSubscriberToReturn = new ReturnValue("topic subscriber"); public void setupCreateTopic(Topic topicToReturn){ - this.topicToReturn = topicToReturn; + this.topicToReturn.setValue(topicToReturn); } public void setExpectedTopicName(String topicName){ @@ -25,33 +25,33 @@ public TopicSubscriber createDurableSubscriber(Topic topic, String name) throws JMSException{ - return topicSubscriberToReturn; + return (TopicSubscriber)topicSubscriberToReturn.getValue(); } public TopicSubscriber createDurableSubscriber(Topic topic, String name, String messsageSelecter, boolean noLocal) throws JMSException{ - return topicSubscriberToReturn; + return (TopicSubscriber)topicSubscriberToReturn.getValue(); } public void setupCreatePublisher(TopicPublisher topicPublisherToReturn){ - this.topicPublisherToReturn = topicPublisherToReturn; + this.topicPublisherToReturn.setValue(topicPublisherToReturn); } public TopicPublisher createPublisher(Topic topic) throws JMSException{ - return topicPublisherToReturn; + return (TopicPublisher)topicPublisherToReturn.getValue(); } public void setupTopicSubscriber(TopicSubscriber topicSubscriberToReturn){ - this.topicSubscriberToReturn = topicSubscriberToReturn; + this.topicSubscriberToReturn.setValue(topicSubscriberToReturn); } public TopicSubscriber createSubscriber(Topic topic) throws JMSException{ - return topicSubscriberToReturn; + return (TopicSubscriber)topicSubscriberToReturn.getValue(); } public TopicSubscriber createSubscriber(Topic topic, String messsageSelecter, boolean noLocal) throws JMSException{ - return topicSubscriberToReturn; + return (TopicSubscriber)topicSubscriberToReturn.getValue(); } public TemporaryTopic createTemporaryTopic() throws JMSException{ @@ -62,7 +62,7 @@ public Topic createTopic(String topicName) throws JMSException{ this.topicName.setActual(topicName); this.createTopicCalls.inc(); - return topicToReturn; + return (Topic)topicToReturn.getValue(); } public void unsubscribe(String topicName) throws JMSException{ |