Title: [waffle-scm] [322] trunk/core/src/main/java/org/codehaus/waffle/action: Updated InterceptorChainImplTest to use JUnit4 format
Revision
322
Author
mward
Date
2007-10-10 17:24:19 -0500 (Wed, 10 Oct 2007)

Log Message

Updated InterceptorChainImplTest to use JUnit4 format

Modified Paths


Diff

Modified: trunk/core/src/main/java/org/codehaus/waffle/action/DefaultActionMethodResponseHandler.java (321 => 322)

--- trunk/core/src/main/java/org/codehaus/waffle/action/DefaultActionMethodResponseHandler.java	2007-10-10 12:36:24 UTC (rev 321)
+++ trunk/core/src/main/java/org/codehaus/waffle/action/DefaultActionMethodResponseHandler.java	2007-10-10 22:24:19 UTC (rev 322)
@@ -24,9 +24,9 @@
  * <p/>
  * - A View response indicates which view the user should be directed (either redirected or forwarded) to.
  * <p/>
- * - An exception sets the response status to 400 and sends the mesage directly (perfect for ajax)
+ * - A ActionMethodException will set the response status and sends the mesage directly (perfect for ajax).
  * <p/>
- * - otherwise the response value will be sent directly to the browser as a String via Object.toString().
+ * - otherwise the response value will be sent directly to the browser as a String via Object.toString() method.
  *
  * @author Michael Ward
  */

Modified: trunk/core/src/test/java/org/codehaus/waffle/action/intercept/InterceptorChainImplTest.java (321 => 322)

--- trunk/core/src/test/java/org/codehaus/waffle/action/intercept/InterceptorChainImplTest.java	2007-10-10 12:36:24 UTC (rev 321)
+++ trunk/core/src/test/java/org/codehaus/waffle/action/intercept/InterceptorChainImplTest.java	2007-10-10 22:24:19 UTC (rev 322)
@@ -1,60 +1,65 @@
 package org.codehaus.waffle.action.intercept;
 
 import org.codehaus.waffle.controller.ControllerDefinition;
-import org.codehaus.waffle.action.intercept.MethodInterceptor;
-import org.codehaus.waffle.action.intercept.InterceptorChainImpl;
-import org.codehaus.waffle.action.intercept.InterceptorChain;
-import org.jmock.Mock;
-import org.jmock.MockObjectTestCase;
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+import org.jmock.integration.junit4.JMock;
+import org.jmock.integration.junit4.JUnit4Mockery;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.List;
 
-public class InterceptorChainImplTest extends MockObjectTestCase {
[EMAIL PROTECTED](JMock.class)
+public class InterceptorChainImplTest {
+    private final Mockery context = new JUnit4Mockery();
 
-    public void testProceed() throws Exception {
-        ControllerDefinition controllerDefinition = new ControllerDefinition(null, null, null);
-        Method method = this.getClass().getMethods()[0];
-        Object argument = "foobar";
+    @Test
+    public void interceptorAcceptsMethod() throws Exception {
+        final ControllerDefinition controllerDefinition = new ControllerDefinition(null, null, null);
+        final Method method = this.getClass().getMethods()[0];
+        final Object argument = "foobar";
 
         // Mock MethodInterceptor
-        Mock mockMethodInterceptor = mock(MethodInterceptor.class);
-        mockMethodInterceptor.expects(once())
-                .method("accept")
-                .with(same(method))
-                .will(returnValue(true));
-        mockMethodInterceptor.expects(once())
-                .method("intercept")
-                .with(same(controllerDefinition), same(method), isA(InterceptorChain.class), eq(new Object[]{argument}))
-                .will(returnValue("hello"));
-        MethodInterceptor methodInterceptor = (MethodInterceptor) mockMethodInterceptor.proxy();
+        final MethodInterceptor methodInterceptor = context.mock(MethodInterceptor.class);
+        context.checking(new Expectations() {{
+            one (methodInterceptor).accept(method);
+            will(returnValue(true));
+            one(methodInterceptor).intercept(with(same(controllerDefinition)),
+                    with(same(method)),
+                    with(any(InterceptorChain.class)),
+                    with(equal(new Object[] {argument})));
+            will(returnValue("hello"));
+        }});
 
         List<MethodInterceptor> interceptors = new ArrayList<MethodInterceptor>();
         interceptors.add(methodInterceptor);
 
         InterceptorChain interceptorChain = new InterceptorChainImpl(interceptors);
-        assertEquals("hello", interceptorChain.proceed(controllerDefinition, method, argument));
+        Assert.assertEquals("hello", interceptorChain.proceed(controllerDefinition, method, argument));
     }
 
-    public void testProceedWhenAcceptIsFalse() throws Exception {
+    @Test
+    public void interceptorDoesNotAcceptMethod() throws Exception {
         ControllerDefinition controllerDefinition = new ControllerDefinition(null, null, null);
-        Method method = this.getClass().getMethods()[0];
+        final Method method = this.getClass().getMethods()[0];
         Object argument = "foobar";
 
         // Mock MethodInterceptor
-        Mock mockMethodInterceptor = mock(MethodInterceptor.class);
-        mockMethodInterceptor.expects(once())
-                .method("accept")
-                .with(same(method))
-                .will(returnValue(false));
-        MethodInterceptor methodInterceptor = (MethodInterceptor) mockMethodInterceptor.proxy();
+        final MethodInterceptor methodInterceptor = context.mock(MethodInterceptor.class);
+        context.checking(new Expectations() {{
+            one (methodInterceptor).accept(method);
+            will(returnValue(false));
+        }});
 
         List<MethodInterceptor> interceptors = new ArrayList<MethodInterceptor>();
         interceptors.add(methodInterceptor);
 
         InterceptorChainImpl interceptorChain = new InterceptorChainImpl(interceptors);
-        assertNull(interceptorChain.proceed(controllerDefinition, method, argument));
+        Assert.assertNull(interceptorChain.proceed(controllerDefinition, method, argument));
     }
 
 }


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to