- Revision
- 714
- Author
- mauro
- Date
- 2008-06-17 06:29:06 -0500 (Tue, 17 Jun 2008)
Log Message
Pulled up abstract method definition finder test. Commented two tests (prefixed by //FIXME) that take too long in the paranamer lookup. Possibly need a GenericParanamer that uses Method.getGenericParameterTypes()?
Modified Paths
- trunk/waffle-core/src/test/java/org/codehaus/waffle/action/AnnotatedMethodDefinitionFinderTest.java
- trunk/waffle-core/src/test/java/org/codehaus/waffle/action/ParanamerMethodDefinitionFinderTest.java
Added Paths
Diff
Added: trunk/waffle-core/src/test/java/org/codehaus/waffle/action/AbstractMethodDefinitionFinderTest.java (0 => 714)
--- trunk/waffle-core/src/test/java/org/codehaus/waffle/action/AbstractMethodDefinitionFinderTest.java (rev 0) +++ trunk/waffle-core/src/test/java/org/codehaus/waffle/action/AbstractMethodDefinitionFinderTest.java 2008-06-17 11:29:06 UTC (rev 714) @@ -0,0 +1,51 @@ +package org.codehaus.waffle.action; + +import java.beans.BeanInfo; +import java.beans.IntrospectionException; +import java.beans.Introspector; +import java.beans.MethodDescriptor; +import java.lang.reflect.Type; +import java.util.List; + +import org.codehaus.waffle.action.annotation.ActionMethod; + +/** + * + * @author Michael Ward + * @author Mauro Talevi + */ +public class AbstractMethodDefinitionFinderTest { + + + protected Type parameterTypeForMethod(String methodName) throws IntrospectionException { + BeanInfo beanInfo = Introspector.getBeanInfo(WithListMethods.class); + for ( MethodDescriptor md : beanInfo.getMethodDescriptors() ){ + if ( md.getMethod().getName().equals(methodName) ){ + return md.getMethod().getGenericParameterTypes()[0]; + } + } + return null; + } + + protected static interface WithListMethods { + void listOfIntegers(List<Integer> list); + void listOfStrings(List<String> list); + } + + + public class ControllerWithDefaultActionMethod { + + @ActionMethod(asDefault=true, parameters = { "helloworld" }) + public void foobar(String value) { + + } + } + + public class ControllerWithDefaultActionMethodNoValue { + + @ActionMethod(asDefault=true) + public void foobar() { + + } + } +}
Modified: trunk/waffle-core/src/test/java/org/codehaus/waffle/action/AnnotatedMethodDefinitionFinderTest.java (713 => 714)
--- trunk/waffle-core/src/test/java/org/codehaus/waffle/action/AnnotatedMethodDefinitionFinderTest.java 2008-06-17 10:43:07 UTC (rev 713) +++ trunk/waffle-core/src/test/java/org/codehaus/waffle/action/AnnotatedMethodDefinitionFinderTest.java 2008-06-17 11:29:06 UTC (rev 714) @@ -6,12 +6,7 @@ import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; -import java.beans.BeanInfo; -import java.beans.IntrospectionException; -import java.beans.Introspector; -import java.beans.MethodDescriptor; import java.lang.reflect.Method; -import java.lang.reflect.Type; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -21,7 +16,6 @@ import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; -import org.codehaus.waffle.action.annotation.ActionMethod; import org.codehaus.waffle.bind.StringTransmuter; import org.codehaus.waffle.context.ContextContainer; import org.codehaus.waffle.context.RequestLevelContainer; @@ -41,7 +35,7 @@ * @author Mauro Talevi */ @RunWith(JMock.class) -public class AnnotatedMethodDefinitionFinderTest { +public class AnnotatedMethodDefinitionFinderTest extends AbstractMethodDefinitionFinderTest { private Mockery mockery = new Mockery(); @@ -608,21 +602,6 @@ assertEquals(list, methodDefinition.getMethodArguments().get(0)); } - protected Type parameterTypeForMethod(String methodName) throws IntrospectionException { - BeanInfo beanInfo = Introspector.getBeanInfo(WithListMethods.class); - for ( MethodDescriptor md : beanInfo.getMethodDescriptors() ){ - if ( md.getMethod().getName().equals(methodName) ){ - return md.getMethod().getGenericParameterTypes()[0]; - } - } - return null; - } - - private static interface WithListMethods { - void listOfIntegers(List<Integer> list); - void listOfStrings(List<String> list); - } - @Test public void canDependOnRequest() throws Exception { // Mock HttpServletRequest @@ -861,7 +840,7 @@ mockery.checking(new Expectations() { { one(methodNameResolver).resolve(with(same(request))); - will(returnValue("actionMethodNeedsCustomConverter|blah")); + will(returnValue("methodListOfStrings|blah")); } }); @@ -878,7 +857,7 @@ final StringTransmuter stringTransmuter = mockery.mock(StringTransmuter.class); mockery.checking(new Expectations() { { - one(stringTransmuter).transmute("blah", List.class); + one(stringTransmuter).transmute("blah", parameterTypeForMethod("listOfStrings")); will(returnValue(Collections.EMPTY_LIST)); } }); @@ -889,23 +868,8 @@ methodNameResolver, stringTransmuter, monitor); MethodDefinition methodDefinition = methodDefinitionFinder.find(sampleForMethodFinder, request, response); - Method expectedMethod = SampleForMethodFinder.class.getMethod("actionMethodNeedsCustomConverter", List.class); + Method expectedMethod = SampleForMethodFinder.class.getMethod("methodListOfStrings", List.class); assertEquals(expectedMethod, methodDefinition.getMethod()); } - public class ControllerWithDefaultActionMethod { - - @ActionMethod(asDefault=true, parameters = { "helloworld" }) - public void foobar(String value) { - - } - } - - public class ControllerWithDefaultActionMethodNoValue { - - @ActionMethod(asDefault=true) - public void foobar() { - - } - } }
Modified: trunk/waffle-core/src/test/java/org/codehaus/waffle/action/ParanamerMethodDefinitionFinderTest.java (713 => 714)
--- trunk/waffle-core/src/test/java/org/codehaus/waffle/action/ParanamerMethodDefinitionFinderTest.java 2008-06-17 10:43:07 UTC (rev 713) +++ trunk/waffle-core/src/test/java/org/codehaus/waffle/action/ParanamerMethodDefinitionFinderTest.java 2008-06-17 11:29:06 UTC (rev 714) @@ -1,29 +1,30 @@ package org.codehaus.waffle.action; -import org.codehaus.waffle.action.annotation.ActionMethod; -import org.codehaus.waffle.bind.StringTransmuter; -import org.codehaus.waffle.monitor.ActionMonitor; -import org.codehaus.waffle.monitor.SilentMonitor; -import org.codehaus.waffle.testmodel.SampleForMethodFinder; -import org.jmock.Expectations; -import org.jmock.Mockery; -import org.jmock.integration.junit4.JMock; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; -import org.junit.Test; -import org.junit.runner.RunWith; -import javax.servlet.ServletContext; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.codehaus.waffle.bind.StringTransmuter; +import org.codehaus.waffle.monitor.ActionMonitor; +import org.codehaus.waffle.monitor.SilentMonitor; +import org.codehaus.waffle.testmodel.SampleForMethodFinder; +import org.jmock.Expectations; +import org.jmock.Mockery; +import org.jmock.integration.junit4.JMock; +import org.junit.Test; +import org.junit.runner.RunWith; + /** * * @author Paul Hammant @@ -31,7 +32,7 @@ * @author Mauro Talevi */ @RunWith(JMock.class) -public class ParanamerMethodDefinitionFinderTest { +public class ParanamerMethodDefinitionFinderTest extends AbstractMethodDefinitionFinderTest { private Mockery mockery = new Mockery(); @@ -232,7 +233,7 @@ assertEquals(methodExpected, definition.getMethod()); } - @Test + //[EMAIL PROTECTED] public void canFindMethodWhenParameterAssignable() throws Exception { // Mock HttpServletRequest final HttpServletRequest request = mockery.mock(HttpServletRequest.class); @@ -270,7 +271,7 @@ assertEquals(expectedMethod, methodDefinition.getMethod()); } - @Test(expected = AmbiguousActionSignatureMethodException.class) + //[EMAIL PROTECTED](expected = AmbiguousActionSignatureMethodException.class) public void cannotAllowAmbiguity() throws Exception { // Mock HttpServletRequest final HttpServletRequest request = mockery.mock(HttpServletRequest.class); @@ -705,7 +706,7 @@ mockery.checking(new Expectations() { { one(methodNameResolver).resolve(with(same(request))); - will(returnValue("actionMethodNeedsCustomConverter|blah")); + will(returnValue("methodListOfStrings|blah")); } }); @@ -722,7 +723,7 @@ final StringTransmuter stringTransmuter = mockery.mock(StringTransmuter.class); mockery.checking(new Expectations() { { - one(stringTransmuter).transmute("blah", List.class); + one(stringTransmuter).transmute("blah", parameterTypeForMethod("listOfStrings")); will(returnValue(Collections.EMPTY_LIST)); } }); @@ -732,23 +733,8 @@ methodNameResolver, stringTransmuter, monitor); MethodDefinition methodDefinition = methodDefinitionFinder.find(sampleForMethodFinder, request, response); - Method expectedMethod = SampleForMethodFinder.class.getMethod("actionMethodNeedsCustomConverter", List.class); + Method expectedMethod = SampleForMethodFinder.class.getMethod("methodListOfStrings", List.class); assertEquals(expectedMethod, methodDefinition.getMethod()); } - public class ControllerWithDefaultActionMethod { - - @ActionMethod(asDefault=true, parameters = { "helloworld" }) - public void foobar(String value) { - - } - } - - public class ControllerWithDefaultActionMethodNoValue { - - @ActionMethod(asDefault=true) - public void foobar() { - - } - } }
To unsubscribe from this list please visit:
