- Revision
- 729
- Author
- mauro
- Date
- 2008-06-18 03:16:13 -0500 (Wed, 18 Jun 2008)
Log Message
Added fake controller with list methods to test model so it can be re-used by several tests.
Modified Paths
- trunk/waffle-core/src/test/java/org/codehaus/waffle/action/AbstractMethodDefinitionFinderTest.java
- trunk/waffle-core/src/test/java/org/codehaus/waffle/action/AnnotatedMethodDefinitionFinderTest.java
- trunk/waffle-core/src/test/java/org/codehaus/waffle/bind/converters/NumberListValueConverterTest.java
- trunk/waffle-core/src/test/java/org/codehaus/waffle/bind/ognl/DelegatingTypeConverterTest.java
Added Paths
Diff
Modified: trunk/waffle-core/src/test/java/org/codehaus/waffle/action/AbstractMethodDefinitionFinderTest.java (728 => 729)
--- trunk/waffle-core/src/test/java/org/codehaus/waffle/action/AbstractMethodDefinitionFinderTest.java 2008-06-18 08:02:01 UTC (rev 728) +++ trunk/waffle-core/src/test/java/org/codehaus/waffle/action/AbstractMethodDefinitionFinderTest.java 2008-06-18 08:16:13 UTC (rev 729) @@ -5,12 +5,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.List; @@ -40,31 +35,15 @@ private Mockery mockery = new Mockery(); - protected Type parameterTypeForMethod(Class<?> controllerClass, String methodName) throws IntrospectionException { - BeanInfo beanInfo = Introspector.getBeanInfo(controllerClass); - for (MethodDescriptor md : beanInfo.getMethodDescriptors()) { - if (md.getMethod().getName().equals(methodName)) { - return md.getMethod().getGenericParameterTypes()[0]; - } - } - return null; - } + private static class ControllerWithDefaultActionMethod { - protected static interface ControllerWithListMethods { - void listOfIntegers(List<Integer> list); - - void listOfStrings(List<String> list); - } - - protected static class ControllerWithDefaultActionMethod { - @ActionMethod(asDefault = true, parameters = { "helloworld" }) public void foobar(String value) { } } - protected static class ControllerWithDefaultActionMethodNoValue { + private static class ControllerWithDefaultActionMethodNoValue { @ActionMethod(asDefault = true) public void foobar() {
Modified: trunk/waffle-core/src/test/java/org/codehaus/waffle/action/AnnotatedMethodDefinitionFinderTest.java (728 => 729)
--- trunk/waffle-core/src/test/java/org/codehaus/waffle/action/AnnotatedMethodDefinitionFinderTest.java 2008-06-18 08:02:01 UTC (rev 728) +++ trunk/waffle-core/src/test/java/org/codehaus/waffle/action/AnnotatedMethodDefinitionFinderTest.java 2008-06-18 08:16:13 UTC (rev 729) @@ -12,6 +12,7 @@ import org.codehaus.waffle.bind.StringTransmuter; import org.codehaus.waffle.monitor.SilentMonitor; +import org.codehaus.waffle.testmodel.FakeControllerWithListMethods; import org.codehaus.waffle.testmodel.FakeControllerWithMethodDefinitions; import org.jmock.Expectations; import org.jmock.Mockery; @@ -66,7 +67,7 @@ mockery.checking(new Expectations() { { one(stringTransmuter).transmute("blah", - parameterTypeForMethod(ControllerWithListMethods.class, "listOfStrings")); + FakeControllerWithListMethods.methodParameterType("listOfStrings")); will(returnValue(Collections.EMPTY_LIST)); } });
Modified: trunk/waffle-core/src/test/java/org/codehaus/waffle/bind/converters/NumberListValueConverterTest.java (728 => 729)
--- trunk/waffle-core/src/test/java/org/codehaus/waffle/bind/converters/NumberListValueConverterTest.java 2008-06-18 08:02:01 UTC (rev 728) +++ trunk/waffle-core/src/test/java/org/codehaus/waffle/bind/converters/NumberListValueConverterTest.java 2008-06-18 08:16:13 UTC (rev 729) @@ -2,17 +2,14 @@ import static java.text.MessageFormat.format; import static java.util.Arrays.asList; +import static org.codehaus.waffle.testmodel.FakeControllerWithListMethods.methodParameterType; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -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 java.util.Locale; @@ -47,32 +44,14 @@ }; - private Type listType(String methodName) throws IntrospectionException { - BeanInfo beanInfo = Introspector.getBeanInfo(CustomType.class); - for (MethodDescriptor md : beanInfo.getMethodDescriptors()) { - if (md.getMethod().getName().equals(methodName)) { - return md.getMethod().getGenericParameterTypes()[0]; - } - } - return null; - } - - private static interface CustomType { - void listOfStrings(List<String> list); - void listOfIntegers(List<Integer> list); - void listOfLongs(List<Integer> list); - void listOfDoubles(List<Integer> list); - void listOfFloats(List<Integer> list); - }; - @Test public void canAccept() throws IntrospectionException { NumberListValueConverter converter = new NumberListValueConverter(new DefaultMessageResources()); - assertTrue(converter.accept(listType("listOfIntegers"))); - assertTrue(converter.accept(listType("listOfLongs"))); - assertTrue(converter.accept(listType("listOfDoubles"))); - assertTrue(converter.accept(listType("listOfFloats"))); - assertFalse(converter.accept(listType("listOfStrings"))); + assertTrue(converter.accept(methodParameterType("listOfIntegers"))); + assertTrue(converter.accept(methodParameterType("listOfLongs"))); + assertTrue(converter.accept(methodParameterType("listOfDoubles"))); + assertTrue(converter.accept(methodParameterType("listOfFloats"))); + assertFalse(converter.accept(methodParameterType("listOfStrings"))); } @Test @@ -94,7 +73,7 @@ @SuppressWarnings("unchecked") private void assertCanConvertValueToList(NumberListValueConverter converter, List<?> expected, String value, Class<?> expectedType, String methodName) throws IntrospectionException { - List<?> actual = (List<?>) converter.convertValue("property-name", value, listType(methodName)); + List<?> actual = (List<?>) converter.convertValue("property-name", value, methodParameterType(methodName)); assertEquals(expected.toString(), actual.toString()); assertTrue(expectedType.isAssignableFrom(actual.get(0).getClass())); }
Modified: trunk/waffle-core/src/test/java/org/codehaus/waffle/bind/ognl/DelegatingTypeConverterTest.java (728 => 729)
--- trunk/waffle-core/src/test/java/org/codehaus/waffle/bind/ognl/DelegatingTypeConverterTest.java 2008-06-18 08:02:01 UTC (rev 728) +++ trunk/waffle-core/src/test/java/org/codehaus/waffle/bind/ognl/DelegatingTypeConverterTest.java 2008-06-18 08:16:13 UTC (rev 729) @@ -4,17 +4,14 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; -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.bind.ValueConverter; import org.codehaus.waffle.bind.converters.ListValueConverter; import org.codehaus.waffle.context.ContextLevel; import org.codehaus.waffle.i18n.DefaultMessageResources; +import org.codehaus.waffle.testmodel.FakeControllerWithListMethods; import org.jmock.Expectations; import org.jmock.Mockery; import org.jmock.integration.junit4.JMock; @@ -22,7 +19,6 @@ import org.junit.runner.RunWith; /** - * * @author Michael Ward * @author Mauro Talevi */ @@ -42,51 +38,38 @@ DelegatingTypeConverter converter = new DelegatingTypeConverter(); assertEquals(15, converter.convertValue("foobar", "15", Integer.class)); } - + @Test public void canDelegateToListValueConverter() { final ValueConverter valueConverter = new ListValueConverter(new DefaultMessageResources()); DelegatingTypeConverter converter = new DelegatingTypeConverter(new OgnlValueConverterFinder(valueConverter)); - assertEquals(asList("one","two"), converter.convertValue("propertyName", "one,two", List.class)); + assertEquals(asList("one", "two"), converter.convertValue("propertyName", "one,two", List.class)); assertEquals(asList(), converter.convertValue("propertyName", "", List.class)); } - + @Test public void canDelegateToCustomValueConverter() { - // Mock ValueConverter + // Mock ValueConverter final ValueConverter valueConverter = mockery.mock(ValueConverter.class); - final CustomType type = new CustomType(){ - public void list(List<String> list) { - }}; + final FakeControllerWithListMethods controller = new FakeControllerWithListMethods(); mockery.checking(new Expectations() { { - one(valueConverter).accept(CustomType.class); + one(valueConverter).accept(FakeControllerWithListMethods.class); will(returnValue(true)); - one(valueConverter).convertValue(with(same("propertyName")), with(same("foobar")), with(same(CustomType.class))); - will(returnValue(type)); + one(valueConverter).convertValue(with(same("propertyName")), with(same("foobar")), + with(same(FakeControllerWithListMethods.class))); + will(returnValue(controller)); } }); DelegatingTypeConverter converter = new DelegatingTypeConverter(new OgnlValueConverterFinder(valueConverter)); - assertSame(type, converter.convertValue("propertyName", "foobar", CustomType.class)); + assertSame(controller, converter.convertValue("propertyName", "foobar", FakeControllerWithListMethods.class)); } @Test public void canReturnValueIfNotConverterFoundForTypeThatIsNotAClass() throws IntrospectionException { DelegatingTypeConverter converter = new DelegatingTypeConverter(new OgnlValueConverterFinder()); - assertEquals("one,two", converter.convertValue("propertyName", "one,two", parameterType())); + assertEquals("one,two", converter.convertValue("propertyName", "one,two", FakeControllerWithListMethods + .methodParameterType("listOfStrings"))); } - - private Type parameterType() throws IntrospectionException { - BeanInfo beanInfo = Introspector.getBeanInfo(CustomType.class); - for (MethodDescriptor md : beanInfo.getMethodDescriptors()) { - if (md.getMethod().getName().equals("list")) { - return md.getMethod().getGenericParameterTypes()[0]; - } - } - return null; - } - private static interface CustomType { - void list(List<String> list); - }; }
Added: trunk/waffle-core/src/test/java/org/codehaus/waffle/testmodel/FakeControllerWithListMethods.java (0 => 729)
--- trunk/waffle-core/src/test/java/org/codehaus/waffle/testmodel/FakeControllerWithListMethods.java (rev 0) +++ trunk/waffle-core/src/test/java/org/codehaus/waffle/testmodel/FakeControllerWithListMethods.java 2008-06-18 08:16:13 UTC (rev 729) @@ -0,0 +1,26 @@ +package org.codehaus.waffle.testmodel; + +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; + +public class FakeControllerWithListMethods { + public static Type methodParameterType(String methodName) throws IntrospectionException { + BeanInfo beanInfo = Introspector.getBeanInfo(FakeControllerWithListMethods.class); + for (MethodDescriptor md : beanInfo.getMethodDescriptors()) { + if (md.getMethod().getName().equals(methodName)) { + return md.getMethod().getGenericParameterTypes()[0]; + } + } + return null; + } + + public void listOfStrings(List<String> list){}; + public void listOfIntegers(List<Integer> list){}; + public void listOfLongs(List<Integer> list){}; + public void listOfDoubles(List<Integer> list){}; + public void listOfFloats(List<Integer> list){}; +} \ No newline at end of file
To unsubscribe from this list please visit:
