You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2006/11/23 02:27:55 UTC

svn commit: r478422 - in /tapestry/tapestry5/tapestry-ioc/trunk/src: main/java/org/apache/tapestry/ioc/internal/ main/java/org/apache/tapestry/ioc/test/ test/java/org/apache/tapestry/ioc/internal/ test/java/org/apache/tapestry/ioc/internal/services/

Author: hlship
Date: Wed Nov 22 17:27:54 2006
New Revision: 478422

URL: http://svn.apache.org/viewvc?view=rev&rev=478422
Log:
Make use of the EasyMock expect().andReturn() coding pattern.

Modified:
    tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/IOCInternalTestCase.java
    tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/test/IOCTestCase.java
    tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/test/TestBase.java
    tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/ContributionDefImplTest.java
    tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/ModuleImplTest.java
    tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/ServiceBuilderMethodInvokerTest.java
    tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/services/ChainBuilderImplTest.java
    tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/services/ClassFabImplTest.java
    tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/services/LoggingDecoratorImplTest.java
    tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/services/ServiceLoggerTest.java

Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/IOCInternalTestCase.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/IOCInternalTestCase.java?view=diff&rev=478422&r1=478421&r2=478422
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/IOCInternalTestCase.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/IOCInternalTestCase.java Wed Nov 22 17:27:54 2006
@@ -1,8 +1,8 @@
 package org.apache.tapestry.ioc.internal;
 
-import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newList;
 import static org.easymock.EasyMock.isA;
 
+import java.util.Collections;
 import java.util.List;
 
 import org.apache.tapestry.ioc.Registry;
@@ -64,15 +64,14 @@
     protected final void train_findDecoratorsForService(Module module, String serviceId,
             List<ServiceDecorator> decorators)
     {
-        module.findDecoratorsForService(serviceId);
-        setReturnValue(decorators);
+        expect(module.findDecoratorsForService(serviceId)).andReturn(decorators);
     }
 
     protected final void train_findDecoratorsForService(InternalRegistry registry)
     {
-        registry.findDecoratorsForService(isA(ServiceDef.class));
-        setReturnValue(newList());
+        List<ServiceDecorator> result = Collections.emptyList();
 
+        expect(registry.findDecoratorsForService(isA(ServiceDef.class))).andReturn(result);
     }
 
     protected final InternalRegistry newInternalRegistry()
@@ -83,15 +82,13 @@
     protected final void train_getLifecycle(InternalRegistry registry, String name,
             ServiceLifecycle lifecycle)
     {
-        registry.getServiceLifecycle(name);
-        setReturnValue(lifecycle);
+        expect(registry.getServiceLifecycle(name)).andReturn(lifecycle);
     }
 
     protected final <T> void train_getService(InternalRegistry registry, String serviceId,
             Class<T> serviceInterface, Module module, T service)
     {
-        registry.getService(serviceId, serviceInterface, module);
-        setReturnValue(service);
+        expect(registry.getService(serviceId, serviceInterface, module)).andReturn(service);
     }
 
     protected final Module newModule()

Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/test/IOCTestCase.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/test/IOCTestCase.java?view=diff&rev=478422&r1=478421&r2=478422
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/test/IOCTestCase.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/test/IOCTestCase.java Wed Nov 22 17:27:54 2006
@@ -82,14 +82,12 @@
 
     protected final void train_getServiceInterface(ServiceDef def, Class serviceInterface)
     {
-        def.getServiceInterface();
-        setReturnValue(serviceInterface).atLeastOnce();
+        expect(def.getServiceInterface()).andReturn(serviceInterface).atLeastOnce();
     }
 
     protected final void train_getServiceId(ServiceDef def, String serviceId)
     {
-        def.getServiceId();
-        setReturnValue(serviceId).atLeastOnce();
+        expect(def.getServiceId()).andReturn(serviceId).atLeastOnce();
     }
 
     protected final ServiceResources newServiceResources()
@@ -104,29 +102,25 @@
 
     protected final void train_getServiceLog(ServiceResources resources, Log log)
     {
-        resources.getServiceLog();
-        setReturnValue(log).atLeastOnce();
+        expect(resources.getServiceLog()).andReturn(log).atLeastOnce();
 
     }
 
     protected final <T> void train_getService(ServiceLocator locator, String serviceId,
             Class<T> serviceInterface, T service)
     {
-        locator.getService(serviceId, serviceInterface);
-        setReturnValue(service);
+        expect(locator.getService(serviceId, serviceInterface)).andReturn(service);
     }
-    
+
     protected final <T> void train_getService(ServiceLocator locator, Class<T> serviceInterface,
             T service)
     {
-        locator.getService(serviceInterface);
-        setReturnValue(service);
+        expect(locator.getService(serviceInterface)).andReturn(service);
     }
 
     protected final void train_createObject(ObjectCreator creator, Object service)
     {
-        creator.createObject();
-        setReturnValue(service);
+        expect(creator.createObject()).andReturn(service);
     }
 
     protected final ObjectProvider newObjectProvider()
@@ -137,8 +131,7 @@
     protected final <T> void train_provide(ObjectProvider provider, String expression,
             Class<T> objectType, ServiceLocator locator, T object)
     {
-        provider.provide(expression, objectType, locator);
-        setReturnValue(object);
+        expect(provider.provide(expression, objectType, locator)).andReturn(object);
     }
 
     protected final ObjectCreator newObjectCreator()
@@ -149,22 +142,19 @@
     protected final void train_getServiceInterface(ServiceResources resources,
             Class serviceInterface)
     {
-        resources.getServiceInterface();
-        setReturnValue(serviceInterface).atLeastOnce();
+        expect(resources.getServiceInterface()).andReturn(serviceInterface).atLeastOnce();
     }
 
     protected final void train_getServiceId(ServiceResources resources, String serviceId)
     {
-        resources.getServiceId();
-        setReturnValue(serviceId).atLeastOnce();
+        expect(resources.getServiceId()).andReturn(serviceId).atLeastOnce();
 
     }
 
     protected final void train_createInterceptor(ServiceDecorator decorator, Object coreObject,
             Object interceptor)
     {
-        decorator.createInterceptor(coreObject);
-        setReturnValue(interceptor);
+        expect(decorator.createInterceptor(coreObject)).andReturn(interceptor);
     }
 
     protected final ServiceBuilderResources newServiceCreatorResources()
@@ -179,14 +169,12 @@
 
     protected final void train_getLog(LogSource source, String serviceId, Log log)
     {
-        source.getLog(serviceId);
-        setReturnValue(log).atLeastOnce();
+        expect(source.getLog(serviceId)).andReturn(log).atLeastOnce();
     }
 
     protected final void train_getModuleId(ModuleDef def, String moduleId)
     {
-        def.getModuleId();
-        setReturnValue(moduleId).atLeastOnce();
+        expect(def.getModuleId()).andReturn(moduleId).atLeastOnce();
     }
 
     /** Frequently used as a placeholder for an arbitrary service (but its nice and simple). */
@@ -203,8 +191,7 @@
     protected final void train_matches(DecoratorDef decoratorDef, ServiceDef serviceDef,
             boolean matches)
     {
-        decoratorDef.matches(serviceDef);
-        setReturnValue(matches);
+        expect(decoratorDef.matches(serviceDef)).andReturn(matches);
     }
 
     protected final DecoratorDef newDecoratorDef()
@@ -234,8 +221,7 @@
     protected <S, T> void train_coerce(TypeCoercer coercer, S input, Class<T> expectedType,
             T coercedValue)
     {
-        coercer.coerce(input, expectedType);
-        setReturnValue(coercedValue);
+        expect(coercer.coerce(input, expectedType)).andReturn(coercedValue);
     }
 
     protected final TypeCoercer newTypeCoercer()

Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/test/TestBase.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/test/TestBase.java?view=diff&rev=478422&r1=478421&r2=478422
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/test/TestBase.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/test/TestBase.java Wed Nov 22 17:27:54 2006
@@ -12,128 +12,141 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package org.apache.tapestry.ioc.test;
-
-import org.apache.commons.logging.Log;
-import org.easymock.EasyMock;
-import org.easymock.IExpectationSetters;
-import org.easymock.IMocksControl;
-import org.testng.Assert;
-import org.testng.annotations.AfterMethod;
-
-/**
- * Manages a set of EasyMock mock objects. Used as a base class for test cases.
- * <p>
- * Extends from {@link org.testng.Assert} to bring in all the public static assert methods without
- * requiring extra imports.
- * <p>
- * Provides common mock factory and mock trainer methods. Uses a thread-local <em>nice</em> mock
- * control for all created mocks. Nice mocks don't care about the order in which mock methods are
- * invoked, and will return an appropriate null/0/false value for any unexpected method invocations.
- */
-public class TestBase extends Assert
-{
-    private class ThreadLocalControl extends ThreadLocal<IMocksControl>
-    {
-        @Override
-        protected IMocksControl initialValue()
-        {
-            return EasyMock.createControl();
-        }
-    }
-
-    private final ThreadLocalControl _localControl = new ThreadLocalControl();
-
-    /**
-     * Returns the {@link IMocksControl} for this thread.
-     */
-    protected final IMocksControl getMocksControl()
-    {
-        return _localControl.get();
-    }
-
-    /**
-     * Discards any mock objects created during the test.
-     */
-    @AfterMethod(alwaysRun = true)
-    public final void discardMockControl()
-    {
-        _localControl.remove();
-    }
-
-    /**
-     * Creates a new mock object of the indicated type. The shared mock control does <strong>not</strong>
-     * check order, but does fail on any unexpected method invocations.
-     * 
-     * @param <T>
-     *            the type of the mock object
-     * @param mockClass
-     *            the class to mock
-     * @return the mock object, ready for training
-     */
-    protected final <T> T newMock(Class<T> mockClass)
-    {
-        return getMocksControl().createMock(mockClass);
-    }
-
-    /**
-     * Replay's each mock object created by {@link #newMock(Class)}.
-     */
-    protected final void replay()
-    {
-        getMocksControl().replay();
-    }
-
-    /**
-     * Verifies each created mock object, then resets the mock for additional training.
-     */
-    protected final void verify()
-    {
-        getMocksControl().verify();
-        getMocksControl().reset();
-    }
-
-    /**
-     * Sets the return value for the most recent method call upon the mock.
-     * 
-     * @param returnValue
-     *            value to be returned from the method call
-     */
-    @SuppressWarnings("unchecked")
-    protected final <T> IExpectationSetters<T> setReturnValue(Object returnValue)
-    {
-        return getMocksControl().andReturn(returnValue);
-    }
-
-    /**
-     * Trains a mock object to throw an exception (for the most recent method call).
-     * 
-     * @param throwable
-     *            the exception to be thrown by the most recent method call on the mock
-     */
-    protected final void setThrowable(Throwable throwable)
-    {
-        getMocksControl().andThrow(throwable);
-    }
-
-    /**
-     * Invoked from code that should not be reachable. For example, place a call to unreachable()
-     * after invoking a method that is expected to throw an exception.
-     */
-
-    protected final void unreachable()
-    {
-        fail("This code should not be reachable.");
-    }
-
-    protected final Log newLog()
-    {
-        return newMock(Log.class);
-    }
-
-    protected final void train_isDebugEnabled(Log log, boolean debugEnabled)
-    {
-        log.isDebugEnabled();
-        setReturnValue(debugEnabled);
-    }
-}
+package org.apache.tapestry.ioc.test;
+
+import org.apache.commons.logging.Log;
+import org.easymock.EasyMock;
+import org.easymock.IExpectationSetters;
+import org.easymock.IMocksControl;
+import org.testng.Assert;
+import org.testng.annotations.AfterMethod;
+
+/**
+ * Manages a set of EasyMock mock objects. Used as a base class for test cases.
+ * <p>
+ * Extends from {@link org.testng.Assert} to bring in all the public static assert methods without
+ * requiring extra imports.
+ * <p>
+ * Provides common mock factory and mock trainer methods. Uses a thread-local <em>nice</em> mock
+ * control for all created mocks. Nice mocks don't care about the order in which mock methods are
+ * invoked, and will return an appropriate null/0/false value for any unexpected method invocations.
+ */
+public class TestBase extends Assert
+{
+    private class ThreadLocalControl extends ThreadLocal<IMocksControl>
+    {
+        @Override
+        protected IMocksControl initialValue()
+        {
+            return EasyMock.createControl();
+        }
+    }
+
+    private final ThreadLocalControl _localControl = new ThreadLocalControl();
+
+    /**
+     * Returns the {@link IMocksControl} for this thread.
+     */
+    protected final IMocksControl getMocksControl()
+    {
+        return _localControl.get();
+    }
+
+    /**
+     * Discards any mock objects created during the test.
+     */
+    @AfterMethod(alwaysRun = true)
+    public final void discardMockControl()
+    {
+        _localControl.remove();
+    }
+
+    /**
+     * Creates a new mock object of the indicated type. The shared mock control does <strong>not</strong>
+     * check order, but does fail on any unexpected method invocations.
+     * 
+     * @param <T>
+     *            the type of the mock object
+     * @param mockClass
+     *            the class to mock
+     * @return the mock object, ready for training
+     */
+    protected final <T> T newMock(Class<T> mockClass)
+    {
+        return getMocksControl().createMock(mockClass);
+    }
+
+    /**
+     * Replay's each mock object created by {@link #newMock(Class)}.
+     */
+    protected final void replay()
+    {
+        getMocksControl().replay();
+    }
+
+    /**
+     * Verifies each created mock object, then resets the mock for additional training.
+     */
+    protected final void verify()
+    {
+        IMocksControl control = getMocksControl();
+
+        control.verify();
+        control.reset();
+    }
+
+    /**
+     * Sets the return value for the most recent method call upon the mock.
+     * 
+     * @param returnValue
+     *            value to be returned from the method call
+     * @deprecated Use {@link #expect} instead
+     */
+    @SuppressWarnings("unchecked")
+    protected final <T> IExpectationSetters<T> setReturnValue(Object returnValue)
+    {
+        return getMocksControl().andReturn(returnValue);
+    }
+
+    /**
+     * Trains a mock object to throw an exception (for the most recent method call). Generally,
+     * using {@link #expect(Object)}.andThrow() is preferred, but that doesn't work for void
+     * methods.
+     * 
+     * @param throwable
+     *            the exception to be thrown by the most recent method call on the mock
+     */
+    protected final void setThrowable(Throwable throwable)
+    {
+        getMocksControl().andThrow(throwable);
+    }
+
+    /**
+     * Invoked from code that should not be reachable. For example, place a call to unreachable()
+     * after invoking a method that is expected to throw an exception.
+     */
+
+    protected final void unreachable()
+    {
+        fail("This code should not be reachable.");
+    }
+
+    protected final Log newLog()
+    {
+        return newMock(Log.class);
+    }
+
+    protected final void train_isDebugEnabled(Log log, boolean debugEnabled)
+    {
+        expect(log.isDebugEnabled()).andReturn(debugEnabled);
+    }
+
+    @SuppressWarnings("unchecked")
+    protected final <T> IExpectationSetters<T> expect(T value)
+    {
+        // value will have been evaluated, we can then return the control to string together
+        // andReturn() or etc. calls
+
+        return getMocksControl();
+    }
+}

Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/ContributionDefImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/ContributionDefImplTest.java?view=diff&rev=478422&r1=478421&r2=478422
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/ContributionDefImplTest.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/ContributionDefImplTest.java Wed Nov 22 17:27:54 2006
@@ -85,8 +85,7 @@
 
         Throwable t = new RuntimeException("Missing service.");
 
-        locator.getService(MappedConfiguration.class);
-        setThrowable(t);
+        expect(locator.getService(MappedConfiguration.class)).andThrow(t);
 
         replay();
 

Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/ModuleImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/ModuleImplTest.java?view=diff&rev=478422&r1=478421&r2=478422
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/ModuleImplTest.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/ModuleImplTest.java Wed Nov 22 17:27:54 2006
@@ -72,8 +72,7 @@
     protected final void train_newClass(InternalRegistry registry, ClassFactory factory,
             Class serviceInterface)
     {
-        registry.newClass(serviceInterface);
-        setReturnValue(factory.newClass(serviceInterface));
+        expect(registry.newClass(serviceInterface)).andReturn(factory.newClass(serviceInterface));
     }
 
     @Test
@@ -178,11 +177,9 @@
 
         ModuleDef moduleDef = newModuleDef();
 
-        moduleDef.getDecoratorDefs();
-        setReturnValue(rawDefs);
+        expect(moduleDef.getDecoratorDefs()).andReturn(rawDefs);
 
-        rawDefs.iterator();
-        setReturnValue(Arrays.asList(def1, def2).iterator());
+        expect(rawDefs.iterator()).andReturn(Arrays.asList(def1, def2).iterator());
 
         train_matches(def1, serviceDef, false);
         train_matches(def2, serviceDef, true);

Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/ServiceBuilderMethodInvokerTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/ServiceBuilderMethodInvokerTest.java?view=diff&rev=478422&r1=478421&r2=478422
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/ServiceBuilderMethodInvokerTest.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/ServiceBuilderMethodInvokerTest.java Wed Nov 22 17:27:54 2006
@@ -132,6 +132,7 @@
         verify();
     }
 
+    @SuppressWarnings("unchecked")
     @Test
     public void injected_ordered_collection()
     {
@@ -140,14 +141,14 @@
         Log log = newLog();
 
         fixture._fie = newFieService();
-        fixture._expectedConfiguration = newMock(List.class);
+        List<Runnable> result = newMock(List.class);
+        fixture._expectedConfiguration = result;
 
         trainForConstructor(resources, log);
 
         train_getModuleBuilder(resources, fixture);
 
-        resources.getOrderedConfiguration(Runnable.class);
-        setReturnValue(fixture._expectedConfiguration);
+        expect(resources.getOrderedConfiguration(Runnable.class)).andReturn(result);
 
         train_isDebugEnabled(log, false);
 
@@ -165,6 +166,7 @@
 
     }
 
+    @SuppressWarnings("unchecked")
     @Test
     public void injected_unordered_collection()
     {
@@ -173,14 +175,14 @@
         Log log = newLog();
 
         fixture._fie = newFieService();
-        fixture._expectedConfiguration = newMock(Collection.class);
+        Collection<Runnable> result = newMock(Collection.class);
+        fixture._expectedConfiguration = result;
 
         trainForConstructor(resources, log);
 
         train_getModuleBuilder(resources, fixture);
 
-        resources.getUnorderedConfiguration(Runnable.class);
-        setReturnValue(fixture._expectedConfiguration);
+        expect(resources.getUnorderedConfiguration(Runnable.class)).andReturn(result);
 
         train_isDebugEnabled(log, false);
 
@@ -306,8 +308,7 @@
     protected final void train_getModuleBuilder(ServiceBuilderResources resources,
             Object moduleBuilder)
     {
-        resources.getModuleBuilder();
-        setReturnValue(moduleBuilder);
+        expect(resources.getModuleBuilder()).andReturn(moduleBuilder);
     }
 
     @Test

Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/services/ChainBuilderImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/services/ChainBuilderImplTest.java?view=diff&rev=478422&r1=478421&r2=478422
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/services/ChainBuilderImplTest.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/services/ChainBuilderImplTest.java Wed Nov 22 17:27:54 2006
@@ -54,11 +54,9 @@
         ChainCommand c1 = newChainCommand();
         ChainCommand c2 = newChainCommand();
 
-        c1.workInt(7);
-        setReturnValue(0);
+        expect(c1.workInt(7)).andReturn(0);
 
-        c2.workInt(7);
-        setReturnValue(99);
+        expect(c2.workInt(7)).andReturn(99);
 
         replay();
 
@@ -75,8 +73,7 @@
         ChainCommand c1 = newChainCommand();
         ChainCommand c2 = newChainCommand();
 
-        c1.workInt(7);
-        setReturnValue(88);
+        expect(c1.workInt(7)).andReturn(88);
 
         replay();
 
@@ -93,11 +90,8 @@
         ChainCommand c1 = newChainCommand();
         ChainCommand c2 = newChainCommand();
 
-        c1.workBoolean(true);
-        setReturnValue(false);
-
-        c2.workBoolean(true);
-        setReturnValue(true);
+        train_workBoolean(c1, true, false);
+        train_workBoolean(c2, true, true);
 
         replay();
 
@@ -108,17 +102,20 @@
         verify();
     }
 
+    protected final void train_workBoolean(ChainCommand command, boolean parameter, boolean result)
+    {
+        expect(command.workBoolean(parameter)).andReturn(result);
+    }
+
     @Test
     public void string_method()
     {
         ChainCommand c1 = newChainCommand();
         ChainCommand c2 = newChainCommand();
 
-        c1.workString("fred");
-        setReturnValue(null);
+        expect(c1.workString("fred")).andReturn(null);
 
-        c2.workString("fred");
-        setReturnValue("flintstone");
+        expect(c2.workString("fred")).andReturn("flintstone");
 
         replay();
 
@@ -136,11 +133,9 @@
         ChainCommand c1 = newChainCommand();
         ChainCommand c2 = newChainCommand();
 
-        c1.workDouble(1.2d);
-        setReturnValue(0);
+        expect(c1.workDouble(1.2d)).andReturn(0d);
 
-        c2.workDouble(1.2d);
-        setReturnValue(3.14d);
+        expect(c2.workDouble(1.2d)).andReturn(3.14d);
 
         replay();
 

Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/services/ClassFabImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/services/ClassFabImplTest.java?view=diff&rev=478422&r1=478421&r2=478422
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/services/ClassFabImplTest.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/services/ClassFabImplTest.java Wed Nov 22 17:27:54 2006
@@ -132,13 +132,11 @@
 
         SampleService proxy = (SampleService) clazz.getConstructors()[0].newInstance(delegate);
 
-        delegate.primitiveMethod(5);
-        setReturnValue(10);
+        expect(delegate.primitiveMethod(5)).andReturn(10);
 
         delegate.voidMethod("fred");
 
-        delegate.objectMethod("barney");
-        setReturnValue("rubble");
+        expect(delegate.objectMethod("barney")).andReturn("rubble");
 
         replay();
 

Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/services/LoggingDecoratorImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/services/LoggingDecoratorImplTest.java?view=diff&rev=478422&r1=478421&r2=478422
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/services/LoggingDecoratorImplTest.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/services/LoggingDecoratorImplTest.java Wed Nov 22 17:27:54 2006
@@ -52,7 +52,7 @@
     public void void_method()
     {
         Log log = newLog();
-        Runnable delegate = newMock(Runnable.class);
+        Runnable delegate = newRunnable();
 
         train_isDebugEnabled(log, true);
         log.debug("[ENTER] run()");
@@ -85,7 +85,7 @@
     {
         Throwable t = new RuntimeException("From delegate.");
         Log log = newLog();
-        Runnable delegate = newMock(Runnable.class);
+        Runnable delegate = newRunnable();
 
         train_isDebugEnabled(log, true);
         log.debug("[ENTER] run()");

Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/services/ServiceLoggerTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/services/ServiceLoggerTest.java?view=diff&rev=478422&r1=478421&r2=478422
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/services/ServiceLoggerTest.java (original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/services/ServiceLoggerTest.java Wed Nov 22 17:27:54 2006
@@ -153,9 +153,7 @@
 
     private void train_exceptionLogged(ExceptionTracker tracker, Throwable exception, boolean logged)
     {
-        tracker.exceptionLogged(exception);
-        setReturnValue(logged);
-
+        expect(tracker.exceptionLogged(exception)).andReturn(logged);
     }
 
     @Test