Title: [waffle-scm] [732] trunk/examples/freemarker-example/src/main/webapp/WEB-INF: WAFFLE-85: Renamed ListValueConverter to StringListValueConverter and refactored to only accept parameterized types List<String>.

Diff

Modified: trunk/examples/freemarker-example/src/main/webapp/WEB-INF/web.xml (731 => 732)

--- trunk/examples/freemarker-example/src/main/webapp/WEB-INF/web.xml	2008-06-18 08:40:37 UTC (rev 731)
+++ trunk/examples/freemarker-example/src/main/webapp/WEB-INF/web.xml	2008-06-18 11:24:33 UTC (rev 732)
@@ -16,9 +16,13 @@
     <param-value>org.codehaus.waffle.bind.converters.DateValueConverter</param-value>
   </context-param>
   <context-param>
-    <param-name>register:ListValueConverter</param-name>
-    <param-value>org.codehaus.waffle.bind.converters.ListValueConverter</param-value>
+    <param-name>register:StringListValueConverter</param-name>
+    <param-value>org.codehaus.waffle.bind.converters.StringListValueConverter</param-value>
   </context-param>
+  <context-param>
+    <param-name>register:NumberListValueConverter</param-name>
+    <param-value>org.codehaus.waffle.bind.converters.NumberListValueConverter</param-value>
+  </context-param>
 
   <!-- Waffle context listener -->
   <listener>

Deleted: trunk/waffle-core/src/main/java/org/codehaus/waffle/bind/converters/ListValueConverter.java (731 => 732)

--- trunk/waffle-core/src/main/java/org/codehaus/waffle/bind/converters/ListValueConverter.java	2008-06-18 08:40:37 UTC (rev 731)
+++ trunk/waffle-core/src/main/java/org/codehaus/waffle/bind/converters/ListValueConverter.java	2008-06-18 11:24:33 UTC (rev 732)
@@ -1,81 +0,0 @@
-/*
- * Copyright (c) terms as published in http://waffle.codehaus.org/license.html
- */
-package org.codehaus.waffle.bind.converters;
-
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Properties;
-
-import org.codehaus.waffle.i18n.MessageResources;
-
-/**
- * <p>
- * <code>ValueConverter</code> that converts CSV values to List of Strings. A <code>null</code> or empty value (once
- * trimmed) will be returned as an empty list (behaviour which can be overridden via the [EMAIL PROTECTED] #convertMissingValue}
- * method). The message keys and default values used are:
- * <ul>
- * <li>"bind.error.list" ([EMAIL PROTECTED] #BIND_ERROR_LIST_KEY}): list is <code>null</code> or empty (message defaults to
- * [EMAIL PROTECTED] #DEFAULT_LIST_MESSAGE})</li>
- * </ul>
- * The patterns are also optionally injectable via <code>Properties</code> in the constructor and take precedence over
- * the ones configured in the messages resources.
- * </p>
- * 
- * @author Mauro Talevi
- */
-public class ListValueConverter extends AbstractValueConverter {
-
-    public static final String BIND_ERROR_LIST_KEY = "bind.error.list";
-    public static final String DEFAULT_LIST_MESSAGE = "Invalid list value for field {0}";
-
-    private static final String COMMA = ",";
-
-    public ListValueConverter(MessageResources messageResources) {
-        this(messageResources, new Properties());
-    }
-
-    public ListValueConverter(MessageResources messageResources, Properties patterns) {
-        super(messageResources, patterns);
-    }
-
-    public boolean accept(Type type) {
-        if (type instanceof Class) {
-            return List.class.isAssignableFrom((Class<?>) type);
-        } else if (type instanceof ParameterizedType) {
-            Type rawType = ((ParameterizedType) type).getRawType();
-            return List.class.isAssignableFrom((Class<?>) rawType);
-        }
-        return false;
-    }
-
-    @SuppressWarnings( { "unchecked" })
-    public Object convertValue(String propertyName, String value, Type toType) {
-
-        if (missingValue(value)) {
-            String fieldName = messageFor(propertyName, propertyName);
-            return convertMissingValue(BIND_ERROR_LIST_KEY, DEFAULT_LIST_MESSAGE, fieldName);
-        }
-
-        return listValues(value);
-    }
-
-    protected List<String> listValues(String value) {
-        String[] values = value.split(COMMA);
-        List<String> list = new ArrayList<String>();
-        for (String current : values) {
-            if (current.trim().length() > 0) {
-                list.add(current);
-            }
-        }
-        return list;
-    }
-
-    @SuppressWarnings("unchecked")
-    protected Object convertMissingValue(String key, String defaultMessage, Object... parameters) {
-        return new ArrayList();
-    }
-
-}

Modified: trunk/waffle-core/src/main/java/org/codehaus/waffle/bind/converters/NumberListValueConverter.java (731 => 732)

--- trunk/waffle-core/src/main/java/org/codehaus/waffle/bind/converters/NumberListValueConverter.java	2008-06-18 08:40:37 UTC (rev 731)
+++ trunk/waffle-core/src/main/java/org/codehaus/waffle/bind/converters/NumberListValueConverter.java	2008-06-18 11:24:33 UTC (rev 732)
@@ -16,14 +16,14 @@
 /**
  * <p>
  * <code>ValueConverter</code> that converts a CSV value to a List of Numbers. It extends
- * [EMAIL PROTECTED] org.codehaus.waffle.bind.converters.ListValueConverter ListValueConverter} to provide number parsing using the
- * <code>NumberFormat</code> instance provided (which defaults to <code>NumberFormat.getInstance()</code>) and if
- * not successful returns the string values.
+ * [EMAIL PROTECTED] org.codehaus.waffle.bind.converters.StringListValueConverter StringListValueConverter} to provide number
+ * parsing of the string values using the <code>NumberFormat</code> instance provided (which defaults to
+ * <code>NumberFormat.getInstance()</code>) and if not successful returns the string values themselves.
  * </p>
  * 
  * @author Mauro Talevi
  */
-public class NumberListValueConverter extends ListValueConverter {
+public class NumberListValueConverter extends StringListValueConverter {
 
     private NumberFormat numberFormat;
 
@@ -37,12 +37,10 @@
     }
 
     /**
-     * Accepts types of raw type List and argument type Number
+     * Accepts parameterized types of raw type List and argument type Number
      */
     public boolean accept(Type type) {
-        if (type instanceof Class) {
-            return List.class.isAssignableFrom((Class<?>) type);
-        } else if (type instanceof ParameterizedType) {
+        if (type instanceof ParameterizedType) {
             ParameterizedType parameterizedType = (ParameterizedType) type;
             Type rawType = parameterizedType.getRawType();
             Type argumentType = parameterizedType.getActualTypeArguments()[0];
@@ -73,5 +71,10 @@
         }
         return values;
     }
+    
+    @SuppressWarnings("unchecked")
+    protected Object convertMissingValue(String key, String defaultMessage, Object... parameters) {
+        return new ArrayList<Number>();
+    }
 
 }

Copied: trunk/waffle-core/src/main/java/org/codehaus/waffle/bind/converters/StringListValueConverter.java (from rev 728, trunk/waffle-core/src/main/java/org/codehaus/waffle/bind/converters/ListValueConverter.java) (0 => 732)

--- trunk/waffle-core/src/main/java/org/codehaus/waffle/bind/converters/StringListValueConverter.java	                        (rev 0)
+++ trunk/waffle-core/src/main/java/org/codehaus/waffle/bind/converters/StringListValueConverter.java	2008-06-18 11:24:33 UTC (rev 732)
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) terms as published in http://waffle.codehaus.org/license.html
+ */
+package org.codehaus.waffle.bind.converters;
+
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import org.codehaus.waffle.i18n.MessageResources;
+
+/**
+ * <p>
+ * <code>ValueConverter</code> that converts CSV values to List of Strings. A <code>null</code> or empty value (once
+ * trimmed) will be returned as an empty list (behaviour which can be overridden via the [EMAIL PROTECTED] #convertMissingValue}
+ * method). The message keys and default values used are:
+ * <ul>
+ * <li>"bind.error.list" ([EMAIL PROTECTED] #BIND_ERROR_LIST_KEY}): list is <code>null</code> or empty (message defaults to
+ * [EMAIL PROTECTED] #DEFAULT_LIST_MESSAGE})</li>
+ * </ul>
+ * The patterns are also optionally injectable via <code>Properties</code> in the constructor and take precedence over
+ * the ones configured in the messages resources.
+ * </p>
+ * 
+ * @author Mauro Talevi
+ */
+public class StringListValueConverter extends AbstractValueConverter {
+
+    public static final String BIND_ERROR_LIST_KEY = "bind.error.list";
+    public static final String DEFAULT_LIST_MESSAGE = "Invalid list value for field {0}";
+
+    private static final String COMMA = ",";
+
+    public StringListValueConverter(MessageResources messageResources) {
+        this(messageResources, new Properties());
+    }
+
+    public StringListValueConverter(MessageResources messageResources, Properties patterns) {
+        super(messageResources, patterns);
+    }
+
+    /**
+     * Accepts parameterized types of raw type List and argument type String
+     */
+    public boolean accept(Type type) {
+        if (type instanceof ParameterizedType) {
+            ParameterizedType parameterizedType = (ParameterizedType) type;
+            Type rawType = parameterizedType.getRawType();
+            Type argumentType = parameterizedType.getActualTypeArguments()[0];
+            return List.class.isAssignableFrom((Class<?>) rawType)
+                    && String.class.isAssignableFrom((Class<?>) argumentType);
+        }
+        return false;
+    }
+
+    @SuppressWarnings( { "unchecked" })
+    public Object convertValue(String propertyName, String value, Type toType) {
+
+        if (missingValue(value)) {
+            String fieldName = messageFor(propertyName, propertyName);
+            return convertMissingValue(BIND_ERROR_LIST_KEY, DEFAULT_LIST_MESSAGE, fieldName);
+        }
+
+        return listValues(value);
+    }
+
+    protected List<String> listValues(String value) {
+        String[] values = value.split(COMMA);
+        List<String> list = new ArrayList<String>();
+        for (String current : values) {
+            if (current.trim().length() > 0) {
+                list.add(current);
+            }
+        }
+        return list;
+    }
+
+    @SuppressWarnings("unchecked")
+    protected Object convertMissingValue(String key, String defaultMessage, Object... parameters) {
+        return new ArrayList<String>();
+    }
+
+}

Deleted: trunk/waffle-core/src/test/java/org/codehaus/waffle/bind/converters/ListValueConverterTest.java (731 => 732)

--- trunk/waffle-core/src/test/java/org/codehaus/waffle/bind/converters/ListValueConverterTest.java	2008-06-18 08:40:37 UTC (rev 731)
+++ trunk/waffle-core/src/test/java/org/codehaus/waffle/bind/converters/ListValueConverterTest.java	2008-06-18 11:24:33 UTC (rev 732)
@@ -1,103 +0,0 @@
-package org.codehaus.waffle.bind.converters;
-
-import static java.text.MessageFormat.format;
-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.IntrospectionException;
-import java.util.List;
-
-import ognl.OgnlException;
-
-import org.codehaus.waffle.bind.BindException;
-import org.codehaus.waffle.i18n.DefaultMessageResources;
-import org.junit.Test;
-
-/**
- * @author Mauro Talevi
- */
-public class ListValueConverterTest extends AbstractValueConverterTest {
-
-    @Test
-    public void canAccept() throws IntrospectionException {
-        ListValueConverter converter = new ListValueConverter(new DefaultMessageResources());
-        assertTrue(converter.accept(List.class));
-        assertTrue(converter.accept(methodParameterType("list")));
-        assertFalse(converter.accept(Object.class));
-        assertFalse(converter.accept(methodParameterType("object")));
-    }
-
-    @Test
-    public void canConvertLists() throws OgnlException {
-        ListValueConverter converter = new ListValueConverter(new DefaultMessageResources());
-        // Note: no conversion is done from String to Numbers and the assertion is done on the string representation
-        assertCanConvertValueToList(converter, INTEGERS, "-1,-2,-3");
-        assertCanConvertValueToList(converter, LONGS, "1000,2000,3000");
-        assertCanConvertValueToList(converter, DOUBLES, "0.1,0.2,0.3");
-        assertCanConvertValueToList(converter, FLOATS, "0.1,0.2,0.3");
-        assertCanConvertValueToList(converter, STRINGS, "one,two,three");
-        assertCanConvertValueToList(converter, STRINGS, ",one,two,three");
-        assertCanConvertValueToList(converter, STRINGS, "one,,two,three");
-        assertCanConvertValueToList(converter, MIXED_STRINGS, "0#.A,1#.B");
-    }
-
-    @SuppressWarnings("unchecked")
-    private void assertCanConvertValueToList(ListValueConverter converter, List<?> expected, String value) {
-        List<String> actual = (List<String>) converter.convertValue("property-name", value, List.class);
-        assertEquals(expected.toString(), actual.toString());
-    }
-
-    @Test
-    public void canHandleMissingValues() {
-        ListValueConverter converter = new ListValueConverter(new DefaultMessageResources());
-        assertEmptyList(converter, null);
-        assertEmptyList(converter, "");
-        assertEmptyList(converter, " ");
-    }
-
-    private void assertEmptyList(ListValueConverter converter, String value) {
-        List<?> list = (List<?>) converter.convertValue("property-name", value, List.class);
-        assertNotNull(list);
-        assertTrue(list.isEmpty());
-    }
-
-    @Test
-    public void canFailConversionWithCustomErrorMessages() {
-        DefaultMessageResources resources = new DefaultMessageResources(configuration);
-        ListValueConverter converter = new ListValueConverter(resources) {
-
-            @Override
-            protected Object convertMissingValue(String key, String defaultMessage, Object... parameters) {
-                throw newBindException(key, defaultMessage, parameters);
-            }
-        };
-        try {
-            converter.convertValue("property-name", null, List.class);
-            fail("Expected BindException");
-        } catch (BindException e) {
-            assertEquals(format(resources.getMessage(ListValueConverter.BIND_ERROR_LIST_KEY), "property-name"), e
-                    .getMessage());
-        }
-    }
-
-    @Test
-    public void canFailConversionWithDefaultErrorMessages() {
-        ListValueConverter converter = new ListValueConverter(new DefaultMessageResources()) {
-            @Override
-            protected Object convertMissingValue(String key, String defaultMessage, Object... parameters) {
-                throw newBindException(key, defaultMessage, parameters);
-            }
-        };
-        try {
-            converter.convertValue("property-name", null, List.class);
-            fail("Expected BindException");
-        } catch (BindException e) {
-            assertEquals(format(ListValueConverter.DEFAULT_LIST_MESSAGE, "property-name"), e.getMessage());
-        }
-    }
-
-}

Modified: trunk/waffle-core/src/test/java/org/codehaus/waffle/bind/converters/NumberListValueConverterTest.java (731 => 732)

--- trunk/waffle-core/src/test/java/org/codehaus/waffle/bind/converters/NumberListValueConverterTest.java	2008-06-18 08:40:37 UTC (rev 731)
+++ trunk/waffle-core/src/test/java/org/codehaus/waffle/bind/converters/NumberListValueConverterTest.java	2008-06-18 11:24:33 UTC (rev 732)
@@ -25,13 +25,13 @@
     @Test
     public void canAccept() throws IntrospectionException {
         NumberListValueConverter converter = new NumberListValueConverter(new DefaultMessageResources());
-        assertTrue(converter.accept(List.class));
-        assertTrue(converter.accept(methodParameterType("list")));
         assertTrue(converter.accept(methodParameterType("listOfIntegers")));
         assertTrue(converter.accept(methodParameterType("listOfLongs")));
         assertTrue(converter.accept(methodParameterType("listOfDoubles")));
         assertTrue(converter.accept(methodParameterType("listOfFloats")));
+        assertFalse(converter.accept(List.class));
         assertFalse(converter.accept(Object.class));
+        assertFalse(converter.accept(methodParameterType("list")));
         assertFalse(converter.accept(methodParameterType("listOfStrings")));
         assertFalse(converter.accept(methodParameterType("object")));            }
 

Copied: trunk/waffle-core/src/test/java/org/codehaus/waffle/bind/converters/StringListValueConverterTest.java (from rev 731, trunk/waffle-core/src/test/java/org/codehaus/waffle/bind/converters/ListValueConverterTest.java) (0 => 732)

--- trunk/waffle-core/src/test/java/org/codehaus/waffle/bind/converters/StringListValueConverterTest.java	                        (rev 0)
+++ trunk/waffle-core/src/test/java/org/codehaus/waffle/bind/converters/StringListValueConverterTest.java	2008-06-18 11:24:33 UTC (rev 732)
@@ -0,0 +1,103 @@
+package org.codehaus.waffle.bind.converters;
+
+import static java.text.MessageFormat.format;
+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.IntrospectionException;
+import java.util.List;
+
+import ognl.OgnlException;
+
+import org.codehaus.waffle.bind.BindException;
+import org.codehaus.waffle.i18n.DefaultMessageResources;
+import org.junit.Test;
+
+/**
+ * @author Mauro Talevi
+ */
+public class StringListValueConverterTest extends AbstractValueConverterTest {
+
+    @Test
+    public void canAccept() throws IntrospectionException {
+        StringListValueConverter converter = new StringListValueConverter(new DefaultMessageResources());
+        assertTrue(converter.accept(methodParameterType("listOfStrings")));
+        assertFalse(converter.accept(List.class));
+        assertFalse(converter.accept(Object.class));
+        assertFalse(converter.accept(methodParameterType("object")));
+    }
+
+    @Test
+    public void canConvertListsOfStrings() throws OgnlException {
+        StringListValueConverter converter = new StringListValueConverter(new DefaultMessageResources());
+        // Note: no conversion is done from String to Numbers and the assertion is done on the string representation
+        assertCanConvertValueToList(converter, INTEGERS, "-1,-2,-3");
+        assertCanConvertValueToList(converter, LONGS, "1000,2000,3000");
+        assertCanConvertValueToList(converter, DOUBLES, "0.1,0.2,0.3");
+        assertCanConvertValueToList(converter, FLOATS, "0.1,0.2,0.3");
+        assertCanConvertValueToList(converter, STRINGS, "one,two,three");
+        assertCanConvertValueToList(converter, STRINGS, ",one,two,three");
+        assertCanConvertValueToList(converter, STRINGS, "one,,two,three");
+        assertCanConvertValueToList(converter, MIXED_STRINGS, "0#.A,1#.B");
+    }
+
+    @SuppressWarnings("unchecked")
+    private void assertCanConvertValueToList(StringListValueConverter converter, List<?> expected, String value) {
+        List<String> actual = (List<String>) converter.convertValue("property-name", value, List.class);
+        assertEquals(expected.toString(), actual.toString());
+    }
+
+    @Test
+    public void canHandleMissingValues() {
+        StringListValueConverter converter = new StringListValueConverter(new DefaultMessageResources());
+        assertEmptyList(converter, null);
+        assertEmptyList(converter, "");
+        assertEmptyList(converter, " ");
+    }
+
+    private void assertEmptyList(StringListValueConverter converter, String value) {
+        List<?> list = (List<?>) converter.convertValue("property-name", value, List.class);
+        assertNotNull(list);
+        assertTrue(list.isEmpty());
+    }
+
+    @Test
+    public void canFailConversionWithCustomErrorMessages() {
+        DefaultMessageResources resources = new DefaultMessageResources(configuration);
+        StringListValueConverter converter = new StringListValueConverter(resources) {
+
+            @Override
+            protected Object convertMissingValue(String key, String defaultMessage, Object... parameters) {
+                throw newBindException(key, defaultMessage, parameters);
+            }
+        };
+        try {
+            converter.convertValue("property-name", null, List.class);
+            fail("Expected BindException");
+        } catch (BindException e) {
+            assertEquals(format(resources.getMessage(StringListValueConverter.BIND_ERROR_LIST_KEY), "property-name"), e
+                    .getMessage());
+        }
+    }
+
+    @Test
+    public void canFailConversionWithDefaultErrorMessages() {
+        StringListValueConverter converter = new StringListValueConverter(new DefaultMessageResources()) {
+            @Override
+            protected Object convertMissingValue(String key, String defaultMessage, Object... parameters) {
+                throw newBindException(key, defaultMessage, parameters);
+            }
+        };
+        try {
+            converter.convertValue("property-name", null, List.class);
+            fail("Expected BindException");
+        } catch (BindException e) {
+            assertEquals(format(StringListValueConverter.DEFAULT_LIST_MESSAGE, "property-name"), e.getMessage());
+        }
+    }
+
+}

Modified: trunk/waffle-core/src/test/java/org/codehaus/waffle/bind/ognl/DelegatingTypeConverterTest.java (731 => 732)

--- trunk/waffle-core/src/test/java/org/codehaus/waffle/bind/ognl/DelegatingTypeConverterTest.java	2008-06-18 08:40:37 UTC (rev 731)
+++ trunk/waffle-core/src/test/java/org/codehaus/waffle/bind/ognl/DelegatingTypeConverterTest.java	2008-06-18 11:24:33 UTC (rev 732)
@@ -1,14 +1,14 @@
 package org.codehaus.waffle.bind.ognl;
 
 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.assertSame;
 
 import java.beans.IntrospectionException;
-import java.util.List;
 
 import org.codehaus.waffle.bind.ValueConverter;
-import org.codehaus.waffle.bind.converters.ListValueConverter;
+import org.codehaus.waffle.bind.converters.StringListValueConverter;
 import org.codehaus.waffle.context.ContextLevel;
 import org.codehaus.waffle.i18n.DefaultMessageResources;
 import org.codehaus.waffle.testmodel.FakeControllerWithListMethods;
@@ -40,11 +40,11 @@
     }
 
     @Test
-    public void canDelegateToListValueConverter() {
-        final ValueConverter valueConverter = new ListValueConverter(new DefaultMessageResources());
+    public void canDelegateToListValueConverter() throws IntrospectionException {
+        final ValueConverter valueConverter = new StringListValueConverter(new DefaultMessageResources());
         DelegatingTypeConverter converter = new DelegatingTypeConverter(new OgnlValueConverterFinder(valueConverter));
-        assertEquals(asList("one", "two"), converter.convertValue("propertyName", "one,two", List.class));
-        assertEquals(asList(), converter.convertValue("propertyName", "", List.class));
+        assertEquals(asList("one", "two"), converter.convertValue("propertyName", "one,two", methodParameterType("listOfStrings")));
+        assertEquals(asList(), converter.convertValue("propertyName", "", methodParameterType("listOfStrings")));
     }
 
     @Test

Modified: trunk/waffle-core/src/test/java/org/codehaus/waffle/bind/ognl/OgnlDataBinderTest.java (731 => 732)

--- trunk/waffle-core/src/test/java/org/codehaus/waffle/bind/ognl/OgnlDataBinderTest.java	2008-06-18 08:40:37 UTC (rev 731)
+++ trunk/waffle-core/src/test/java/org/codehaus/waffle/bind/ognl/OgnlDataBinderTest.java	2008-06-18 11:24:33 UTC (rev 732)
@@ -16,7 +16,7 @@
 import org.codehaus.waffle.bind.BindErrorMessageResolver;
 import org.codehaus.waffle.bind.BindException;
 import org.codehaus.waffle.bind.ControllerDataBinder;
-import org.codehaus.waffle.bind.converters.ListValueConverter;
+import org.codehaus.waffle.bind.converters.StringListValueConverter;
 import org.codehaus.waffle.context.ContextLevel;
 import org.codehaus.waffle.i18n.DefaultMessageResources;
 import org.codehaus.waffle.monitor.SilentMonitor;
@@ -91,7 +91,7 @@
         });
 
         FakeController fakeController = new FakeController();
-        ControllerDataBinder binder = new OgnlControllerDataBinder(new OgnlValueConverterFinder(new ListValueConverter(new DefaultMessageResources())), null, new SilentMonitor());
+        ControllerDataBinder binder = new OgnlControllerDataBinder(new OgnlValueConverterFinder(new StringListValueConverter(new DefaultMessageResources())), null, new SilentMonitor());
         ErrorsContext errorsContext = new DefaultErrorsContext(null);
         binder.bind(request, null, errorsContext, fakeController);
 

Added: trunk/waffle-core/src/test/java/org/codehaus/waffle/bind/ognl/OgnlValueConverterFinderTest.java (0 => 732)

--- trunk/waffle-core/src/test/java/org/codehaus/waffle/bind/ognl/OgnlValueConverterFinderTest.java	                        (rev 0)
+++ trunk/waffle-core/src/test/java/org/codehaus/waffle/bind/ognl/OgnlValueConverterFinderTest.java	2008-06-18 11:24:33 UTC (rev 732)
@@ -0,0 +1,37 @@
+package org.codehaus.waffle.bind.ognl;
+
+import static org.codehaus.waffle.testmodel.FakeControllerWithListMethods.methodParameterType;
+import static org.junit.Assert.assertEquals;
+
+import java.beans.IntrospectionException;
+import java.lang.reflect.Type;
+import java.util.List;
+
+import org.codehaus.waffle.bind.ValueConverter;
+import org.codehaus.waffle.bind.ValueConverterFinder;
+import org.codehaus.waffle.bind.converters.StringListValueConverter;
+import org.codehaus.waffle.bind.converters.NumberListValueConverter;
+import org.codehaus.waffle.i18n.DefaultMessageResources;
+import org.codehaus.waffle.i18n.MessageResources;
+import org.junit.Test;
+
+/**
+ * @author Mauro Talevi
+ */
+public class OgnlValueConverterFinderTest {
+
+    private static MessageResources RESOURCES = new DefaultMessageResources();
+
+    @Test
+    public void canFindDifferentListConverters() throws IntrospectionException {
+        ValueConverterFinder finder = new OgnlValueConverterFinder(new StringListValueConverter(RESOURCES), new NumberListValueConverter(RESOURCES));
+        assertConverterType(finder, List.class, OgnlValueConverter.class); // List.class is not parameterized and matches default converter
+        assertConverterType(finder, methodParameterType("listOfStrings"), StringListValueConverter.class);
+        assertConverterType(finder, methodParameterType("listOfIntegers"), NumberListValueConverter.class);
+    }
+
+    private void assertConverterType(ValueConverterFinder finder, Type type, Class<? extends ValueConverter> expectedConverterType) {
+        assertEquals(expectedConverterType, finder.findConverter(type).getClass());
+    }
+
+}


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to