Author: julien(a)jboss.com
Date: 2008-01-16 07:18:04 -0500 (Wed, 16 Jan 2008)
New Revision: 9522
Modified:
modules/common/trunk/common/src/main/java/org/jboss/portal/common/util/ParameterMap.java
modules/common/trunk/common/src/main/java/org/jboss/portal/common/util/TypedMap.java
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/ParameterMapTestCase.java
Log:
- updated ParameterMap test case to include test case that were in portlet module
- minor update of ParameterMap access mode
Modified:
modules/common/trunk/common/src/main/java/org/jboss/portal/common/util/ParameterMap.java
===================================================================
---
modules/common/trunk/common/src/main/java/org/jboss/portal/common/util/ParameterMap.java 2008-01-16
03:11:23 UTC (rev 9521)
+++
modules/common/trunk/common/src/main/java/org/jboss/portal/common/util/ParameterMap.java 2008-01-16
12:18:04 UTC (rev 9522)
@@ -29,7 +29,8 @@
import java.io.Serializable;
/**
- * A decorator that enforce the map content to be <String,String[]>
+ * A decorator that enforce the map content to be <String,String[]>. It also
provides capabilities for
+ * making a copy of the value either on a read or on a write.
*
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 6671 $
@@ -40,48 +41,10 @@
/** . */
private static final KeyConverter keyConv = new KeyConverter();
- /** . */
- private static final ValueConverter valueConv1 = new ValueConverter(false, false);
-
- /** . */
- private static final ValueConverter valueConv2 = new ValueConverter(false, true);
-
- /** . */
- private static final ValueConverter valueConv3 = new ValueConverter(true, false);
-
- /** . */
- private static final ValueConverter valueConv4 = new ValueConverter(true, true);
-
- private static ValueConverter getValueConverter(boolean cloneInternalValue, boolean
cloneExternalValue)
- {
- if (cloneInternalValue)
- {
- if (cloneExternalValue)
- {
- return valueConv4;
- }
- else
- {
- return valueConv3;
- }
- }
- else
- {
- if (cloneExternalValue)
- {
- return valueConv2;
- }
- else
- {
- return valueConv1;
- }
- }
- }
-
/**
* Copy the parameter map.
*
- * @param parameterMap the parameter map to copy
+ * @param map the parameter map to copy
* @return a parameter map initialized from the argument map
* @throws NullPointerException if the map contains a null key or a null value
* @throws IllegalArgumentException if the map is null or it contains a value with a
zero length array or a null
@@ -89,9 +52,9 @@
* @throws ClassCastException if the map contains a key that is not a string or
a value that is not a string
* array
*/
- public static ParameterMap clone(Map<String,String[]> parameterMap) throws
NullPointerException, ClassCastException, IllegalArgumentException
+ public static ParameterMap clone(Map<String, String[]> map) throws
NullPointerException, ClassCastException, IllegalArgumentException
{
- if (parameterMap == null)
+ if (map == null)
{
throw new IllegalArgumentException("No null map accepted");
}
@@ -100,7 +63,7 @@
ParameterMap pm = new ParameterMap();
//
- pm.replace(parameterMap);
+ pm.replace(map);
//
return pm;
@@ -125,148 +88,81 @@
}
}
- /** . */
- private final boolean cloneInternalValue;
+ /**
+ * Safely wrap the map as a portlet parameters object. If the map is already a
parameter map object, just return
+ * that object otherwise return a wrapper around the map.
+ *
+ * @param map the map
+ * @return the portlet parameters
+ */
+ public static ParameterMap wrap(Map<String, String[]> map, AccessMode
accessPolicy)
+ {
+ if (map instanceof ParameterMap)
+ {
+ return new ParameterMap((ParameterMap)map, accessPolicy);
+ }
+ else
+ {
+ return new ParameterMap(map, accessPolicy);
+ }
+ }
/** . */
- private final boolean cloneExternalValue;
+ private final AccessMode accessMode;
- public ParameterMap(boolean cloneInternalValue, boolean cloneExternalValue)
+ /**
+ * Reuse the same underlying map than the provided parameter map but it allows to have
an alternative configuration
+ * of the access. This is not a copy constructor.
+ */
+ public ParameterMap(ParameterMap map, AccessMode accessMode)
{
- this(new HashMap<String, String[]>(), cloneInternalValue,
cloneExternalValue);
+ super(map);
+
+ //
+ this.accessMode = accessMode;
}
+ public ParameterMap(AccessMode accessMode)
+ {
+ this(new HashMap<String, String[]>(), accessMode);
+ }
+
public ParameterMap(MapAccessor<String, String[]> accessor)
{
- this(accessor, false, false);
+ this(accessor, AccessMode.A);
}
public ParameterMap(Map<String, String[]> delegate)
{
- this(delegate, false, false);
+ this(delegate, AccessMode.A);
}
public ParameterMap()
{
- this(false, false);
+ this(AccessMode.A);
}
- public ParameterMap(MapAccessor<String, String[]> accessor, boolean
cloneInternalValue, boolean cloneExternalValue)
+ public ParameterMap(MapAccessor<String, String[]> accessor, AccessMode
accessMode)
{
- super(accessor, keyConv, getValueConverter(cloneInternalValue,
cloneExternalValue));
+ super(accessor, keyConv, accessMode.converter);
//
- this.cloneInternalValue = cloneInternalValue;
- this.cloneExternalValue = cloneExternalValue;
+ this.accessMode = accessMode;
}
- public ParameterMap(Map<String, String[]> delegate, boolean cloneInternalValue,
boolean cloneExternalValue)
+ public ParameterMap(Map<String, String[]> delegate, AccessMode accessMode)
{
- super(delegate, keyConv, getValueConverter(cloneInternalValue,
cloneExternalValue));
+ super(delegate, keyConv, accessMode.converter);
//
- this.cloneInternalValue = cloneInternalValue;
- this.cloneExternalValue = cloneExternalValue;
+ this.accessMode = accessMode;
}
- /**
- * Return true if values returned by the map are cloned.
- *
- * @return true if returned values are cloned
- */
- public boolean isCloneInternalValue()
+ public AccessMode getAccessMode()
{
- return cloneInternalValue;
+ return accessMode;
}
- public boolean isCloneExternalValue()
- {
- return cloneExternalValue;
- }
-
- private static class KeyConverter extends Converter<String, String>
- {
- protected String getInternal(String external) throws IllegalArgumentException,
ClassCastException
- {
- return external;
- }
- protected String getExternal(String internal)
- {
- return internal;
- }
- protected boolean equals(String left, String right)
- {
- return left.equals(right);
- }
- }
-
- private static class ValueConverter extends Converter<String[], String[]>
- {
-
- /** . */
- private final boolean cloneInternalValue;
-
- /** . */
- private final boolean cloneExternalValue;
-
- private ValueConverter(boolean cloneInternalValue, boolean cloneExternalValue)
- {
- this.cloneInternalValue = cloneInternalValue;
- this.cloneExternalValue = cloneExternalValue;
- }
-
- /**
- * Only check are made to the value. The only valid values accepted
- * are string arrays with non zero length and containing non null
- * values.
- *
- * @param external
- * @return
- * @throws NullPointerException if the value is null
- * @throws ClassCastException if the value type is not an array of string
- * @throws IllegalArgumentException if the array length is zero or one of the array
value is null
- */
- protected String[] getInternal(String[] external) throws IllegalArgumentException,
ClassCastException, NullPointerException
- {
- if (external.length == 0)
- {
- throw new IllegalArgumentException("Array must not be zero
length");
- }
-
- //
- for (int i = external.length - 1;i >= 0;i--)
- {
- if (external[i] == null)
- {
- throw new IllegalArgumentException("No null entries allowed in
String[]");
- }
- }
-
- //
- if (cloneExternalValue)
- {
- external = external.clone();
- }
-
- //
- return external;
- }
-
- protected String[] getExternal(String[] internal)
- {
- if (cloneInternalValue)
- {
- internal = internal.clone();
- }
- return internal;
- }
-
- protected boolean equals(String[] left, String[] right)
- {
- return Arrays.equals(left, right);
- }
- }
-
/**
* Return the parameter value or null if it does not exist.
*
@@ -379,4 +275,133 @@
buffer.append(']');
return buffer.toString();
}
+
+ private static class KeyConverter extends Converter<String, String>
+ {
+ protected String getInternal(String external) throws IllegalArgumentException,
ClassCastException
+ {
+ return external;
+ }
+ protected String getExternal(String internal)
+ {
+ return internal;
+ }
+ protected boolean equals(String left, String right)
+ {
+ return left.equals(right);
+ }
+ }
+
+ /**
+ * Defines how the state of the values are managed.
+ */
+ public static class AccessMode
+ {
+
+ public static AccessMode get(boolean copyValueOnRead, boolean copyValueOnWrite)
+ {
+ return copyValueOnRead ? copyValueOnWrite ? D : C : copyValueOnWrite ? B : A;
+ }
+
+ /** . */
+ private static final AccessMode A = new AccessMode(false, false);
+
+ /** . */
+ private static final AccessMode B = new AccessMode(false, true);
+
+ /** . */
+ private static final AccessMode C = new AccessMode(true, false);
+
+ /** . */
+ private static final AccessMode D = new AccessMode(true, true);
+
+ /** . */
+ private final boolean copyValueOnRead;
+
+ /** . */
+ private final boolean copyValueOnWrite;
+
+ /** . */
+ private final ValueConverter converter;
+
+ private AccessMode(boolean copyValueOnRead, boolean copyOnWrite)
+ {
+ this.copyValueOnRead = copyValueOnRead;
+ this.copyValueOnWrite = copyOnWrite;
+ this.converter = new ValueConverter(this);
+ }
+
+ public boolean getCopyValueOnRead()
+ {
+ return copyValueOnRead;
+ }
+
+ public boolean getCopyValueOnWrite()
+ {
+ return copyValueOnWrite;
+ }
+ }
+
+ private static class ValueConverter extends Converter<String[], String[]>
+ {
+
+ /** . */
+ private final AccessMode accessMode;
+
+ private ValueConverter(AccessMode accessMode)
+ {
+ this.accessMode = accessMode;
+ }
+
+ /**
+ * Only check are made to the value. The only valid values accepted
+ * are string arrays with non zero length and containing non null
+ * values.
+ *
+ * @param external
+ * @return
+ * @throws NullPointerException if the value is null
+ * @throws ClassCastException if the value type is not an array of string
+ * @throws IllegalArgumentException if the array length is zero or one of the array
value is null
+ */
+ protected String[] getInternal(String[] external) throws IllegalArgumentException,
ClassCastException, NullPointerException
+ {
+ if (external.length == 0)
+ {
+ throw new IllegalArgumentException("Array must not be zero
length");
+ }
+
+ //
+ for (int i = external.length - 1;i >= 0;i--)
+ {
+ if (external[i] == null)
+ {
+ throw new IllegalArgumentException("No null entries allowed in
String[]");
+ }
+ }
+
+ //
+ if (accessMode.copyValueOnWrite)
+ {
+ external = external.clone();
+ }
+
+ //
+ return external;
+ }
+
+ protected String[] getExternal(String[] internal)
+ {
+ if (accessMode.copyValueOnRead)
+ {
+ internal = internal.clone();
+ }
+ return internal;
+ }
+
+ protected boolean equals(String[] left, String[] right)
+ {
+ return Arrays.equals(left, right);
+ }
+ }
}
Modified:
modules/common/trunk/common/src/main/java/org/jboss/portal/common/util/TypedMap.java
===================================================================
---
modules/common/trunk/common/src/main/java/org/jboss/portal/common/util/TypedMap.java 2008-01-16
03:11:23 UTC (rev 9521)
+++
modules/common/trunk/common/src/main/java/org/jboss/portal/common/util/TypedMap.java 2008-01-16
12:18:04 UTC (rev 9522)
@@ -123,6 +123,18 @@
/** The value converter. */
private final Converter<EV, IV> valueConverter;
+ /**
+ * Constructor that will reuse the same attributes than the provided map. This is not
a copy constructor.
+ *
+ * @param that the other map
+ */
+ public TypedMap(TypedMap<EK, EV, IK, IV> that)
+ {
+ this.accessor = that.accessor;
+ this.keyConverter = that.keyConverter;
+ this.valueConverter = that.valueConverter;
+ }
+
public TypedMap(MapAccessor<IK, IV> accessor, Converter<EK, IK>
keyConverter, Converter<EV, IV> valueConverter)
{
if (accessor == null)
@@ -554,7 +566,7 @@
public boolean add(EV ev)
{
- throw new NotYetImplemented("TypedEntrySet.add(Object o)");
+ throw new UnsupportedOperationException();
}
public boolean contains(Object o)
@@ -562,39 +574,39 @@
throw new NotYetImplemented("TypedEntrySet.contains(Object o)");
}
- public boolean remove(Object o)
+ public boolean containsAll(Collection<?> objects)
{
- throw new NotYetImplemented("TypedEntrySet.remove(Object o)");
+ throw new NotYetImplemented("TypedEntrySet.containsAll(Collection
c)");
}
- public boolean addAll(Collection<? extends EV> evs)
+ public <T> T[] toArray(T[] ts)
{
- throw new NotYetImplemented("TypedEntrySet.addAll(Collection c)");
+ throw new NotYetImplemented("TypedEntrySet.toArray(Object a[])");
}
- public boolean containsAll(Collection<?> objects)
+ public Iterator<EV> iterator()
{
- throw new NotYetImplemented("TypedEntrySet.containsAll(Collection
c)");
+ return new ValueIterator();
}
- public boolean removeAll(Collection<?> objects)
+ public boolean remove(Object o)
{
- throw new NotYetImplemented("TypedEntrySet.removeAll(Collection c)");
+ throw new UnsupportedOperationException();
}
- public boolean retainAll(Collection<?> objects)
+ public boolean addAll(Collection<? extends EV> evs)
{
- throw new NotYetImplemented("TypedEntrySet.retainAll(Collection c)");
+ throw new UnsupportedOperationException();
}
- public <T> T[] toArray(T[] ts)
+ public boolean removeAll(Collection<?> objects)
{
- throw new NotYetImplemented("TypedEntrySet.toArray(Object a[])");
+ throw new UnsupportedOperationException();
}
- public Iterator<EV> iterator()
+ public boolean retainAll(Collection<?> objects)
{
- return new ValueIterator();
+ throw new UnsupportedOperationException();
}
public class ValueIterator implements Iterator<EV>
Modified:
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/ParameterMapTestCase.java
===================================================================
---
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/ParameterMapTestCase.java 2008-01-16
03:11:23 UTC (rev 9521)
+++
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/ParameterMapTestCase.java 2008-01-16
12:18:04 UTC (rev 9522)
@@ -24,11 +24,15 @@
import junit.framework.TestCase;
import org.jboss.portal.common.util.ParameterMap;
+import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.junit.ExtendedAssert;
import java.util.HashMap;
import java.util.Set;
import java.util.Iterator;
import java.util.Map;
+import java.util.Arrays;
+import java.util.List;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -37,16 +41,38 @@
public class ParameterMapTestCase extends TestCase
{
+ /** . */
+ private ParameterMap param;
+
+ public ParameterMapTestCase()
+ {
+ }
+
+ public ParameterMapTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void setUp()
+ {
+ param = new ParameterMap();
+ }
+
+ public void tearDown()
+ {
+ param = null;
+ }
+
public void testPut()
{
- ParameterMap pm = new ParameterMap(new HashMap());
+ ParameterMap pm = new ParameterMap(new HashMap<String, String[]>());
pm.put("foo", new String[]{"bar"});
// ExtendedAssert.assertEquals(new String[]{"bar"},
(Object[])pm.get("foo"));
}
public void testEntry()
{
- ParameterMap pm = new ParameterMap(new HashMap());
+ ParameterMap pm = new ParameterMap(new HashMap<String, String[]>());
pm.put("foo", new String[]{"bar"});
Set entries = pm.entrySet();
assertNotNull(entries);
@@ -61,7 +87,7 @@
public void testPutThrowsException()
{
- ParameterMap pm = new ParameterMap(new HashMap());
+ ParameterMap pm = new ParameterMap(new HashMap<String, String[]>());
try
{
((Map)pm).put(new Object(), new String[]{"bar"});
@@ -98,7 +124,7 @@
public void testEntrySetValueThrowsException()
{
- ParameterMap pm = new ParameterMap(new HashMap());
+ ParameterMap pm = new ParameterMap(new HashMap<String, String[]>());
pm.put("foo", new String[]{"bar"});
Set entries = pm.entrySet();
assertNotNull(entries);
@@ -140,4 +166,348 @@
{
}
}
+
+ public void testNoCopyOnRead()
+ {
+ Map<String, String[]> internal = new HashMap<String, String[]>();
+ String[] internalValue = {"bar"};
+ internal.put("foo", internalValue);
+
+ //
+ ParameterMap map = new ParameterMap(internal, ParameterMap.AccessMode.get(false,
false));
+
+ //
+ String[] externalValue = map.get("foo");
+ assertNotNull(externalValue);
+ assertEquals(1, externalValue.length);
+ assertEquals("bar", externalValue[0]);
+ internalValue[0] = null;
+ assertEquals(null, externalValue[0]);
+ }
+
+ public void testCopyOnRead()
+ {
+ Map<String, String[]> internal = new HashMap<String, String[]>();
+ String[] internalValue = {"bar"};
+ internal.put("foo", internalValue);
+
+ //
+ ParameterMap map = new ParameterMap(internal, ParameterMap.AccessMode.get(true,
false));
+
+ //
+ String[] externalValue = map.get("foo");
+ assertNotNull(externalValue);
+ assertEquals(1, externalValue.length);
+ assertEquals("bar", externalValue[0]);
+ internalValue[0] = null;
+ assertEquals("bar", externalValue[0]);
+ }
+
+ public void testNoCopyOnWrite()
+ {
+ Map<String, String[]> internal = new HashMap<String, String[]>();
+
+ //
+ ParameterMap map = new ParameterMap(internal, ParameterMap.AccessMode.get(false,
false));
+
+ //
+ String[] externalValue = new String[]{"bar"};
+ map.put("foo", externalValue);
+
+ //
+ String[] internalValue = internal.get("foo");
+ assertNotNull(internalValue);
+ assertEquals(1, internalValue.length);
+ assertEquals("bar", internalValue[0]);
+ externalValue[0] = null;
+ assertEquals(null, internalValue[0]);
+ }
+
+ public void testCopyOnWrite()
+ {
+ Map<String, String[]> internal = new HashMap<String, String[]>();
+
+ //
+ ParameterMap map = new ParameterMap(internal, ParameterMap.AccessMode.get(false,
true));
+
+ //
+ String[] externalValue = new String[]{"bar"};
+ map.put("foo", externalValue);
+
+ //
+ String[] internalValue = internal.get("foo");
+ assertNotNull(internalValue);
+ assertEquals(1, internalValue.length);
+ assertEquals("bar", internalValue[0]);
+ externalValue[0] = null;
+ assertEquals("bar", internalValue[0]);
+ }
+
+ public void testGetWithNullName()
+ {
+ try
+ {
+ param.getValue(null);
+ fail("Expected IllegalArgumentException");
+ }
+ catch (NullPointerException e)
+ {
+ }
+ }
+
+ public void testSet()
+ {
+ param.setValue("a", "b");
+ assertEquals(param.getValue("a"), "b");
+ }
+
+ public void testSetWithNullName()
+ {
+ try
+ {
+ param.setValue(null, "b");
+ fail("Expected IllegalArgumentException");
+ }
+ catch (NullPointerException e)
+ {
+ }
+ }
+
+ public void testSetWithNullValue()
+ {
+ try
+ {
+ param.setValue("a", null);
+ fail("Expected IllegalArgumentException");
+ }
+ catch (IllegalArgumentException e)
+ {
+ }
+ }
+
+ public void testRemoveWithNullName()
+ {
+ try
+ {
+ param.remove(null);
+ fail("Expected IllegalArgumentException");
+ }
+ catch (NullPointerException e)
+ {
+ }
+ }
+
+ public void testRemove()
+ {
+ param.setValue("a", "b");
+ param.remove("a");
+ assertEquals(param.getValue("a"), null);
+ }
+
+ public void testSetValues()
+ {
+ param.setValues("a", new String[]{"b", "c"});
+ assertTrue(Arrays.equals(param.getValues("a"), new String[]{
+ "b", "c"}));
+ assertEquals(param.getValue("a"), "b");
+ }
+
+ public void testSetValuesWithNullName()
+ {
+ try
+ {
+ param.setValues(null, new String[]{"a"});
+ fail("Expected IllegalArgumentException");
+ }
+ catch (NullPointerException e)
+ {
+ }
+ }
+
+ public void testSetValuesWithNullValues()
+ {
+ try
+ {
+ param.setValues("a", null);
+ fail("Expected IllegalArgumentException");
+ }
+ catch (NullPointerException e)
+ {
+ }
+ }
+
+ public void testSetValuesWithZeroLengthValues()
+ {
+ try
+ {
+ param.setValues("a", new String[0]);
+ fail("Expected IllegalArgumentException");
+ }
+ catch (IllegalArgumentException e)
+ {
+ }
+ }
+
+ public void testSetValuesWithOneNullValue()
+ {
+ try
+ {
+ param.setValues("a", new String[]{"a", null});
+ fail("Expected IllegalArgumentException");
+ }
+ catch (IllegalArgumentException e)
+ {
+ }
+ }
+
+ public void testReplaceWithParameters()
+ {
+ ParameterMap other = new ParameterMap();
+ other.setValue("a", "b");
+ other.setValues("c", new String[]{"d", "e"});
+ param.replace(other);
+ assertEquals("b", param.getValue("a"));
+ assertTrue(Arrays.equals(param.getValues("c"), new
String[]{"d", "e"}));
+ }
+
+ public void testCopyConstructorWithNullParameters()
+ {
+ try
+ {
+ ParameterMap.clone(null);
+ fail("Expected IllegalArgumentException");
+ }
+ catch (IllegalArgumentException e)
+ {
+ }
+ }
+
+ public void testCopyConstructorWithNullMap()
+ {
+ try
+ {
+ ParameterMap.clone(null);
+ fail("Expected IllegalArgumentException");
+ }
+ catch (IllegalArgumentException e)
+ {
+ }
+ }
+
+ public void testReplaceWithNullMap()
+ {
+ try
+ {
+ param.replace(null);
+ fail("Expected NullPointerException");
+ }
+ catch (NullPointerException e)
+ {
+ }
+ }
+
+ public void testReplaceWithInvalidMap()
+ {
+ List<Map<String, String[]>> maps = buildInvalidMaps();
+ Class[] exceptionClasses = buildExceptionClasses();
+ for (int i = 0;i < maps.size();i++)
+ {
+ try
+ {
+ Map<String, String[]> map = maps.get(i);
+ param.replace(map);
+ fail("Expected IllegalArgumentException with map=" + map);
+ }
+ catch (Exception e)
+ {
+ assertTrue(exceptionClasses[i].isAssignableFrom(e.getClass()));
+ }
+ }
+ }
+
+ public void testReplace()
+ {
+ param.setValue("a", "b");
+ param.setValues("c", new String[]{"d", "e"});
+ param.setValue("f", "g");
+ Map<String, String[]> map = new HashMap<String, String[]>();
+ map.put("a", new String[]{"_b"});
+ map.put("c", new String[]{"_d", "_e"});
+ map.put("h", new String[]{"_i"});
+ param.replace(map);
+ assertEquals(3, param.size());
+ ExtendedAssert.assertEquals(param.getValues("a"), new
String[]{"_b"});
+ ExtendedAssert.assertEquals(param.getValues("c"), new
String[]{"_d", "_e"});
+ ExtendedAssert.assertEquals(param.getValues("h"), new
String[]{"_i"});
+ }
+
+ public void testAppendWithInvalidMap()
+ {
+ List<Map<String, String[]>> maps = buildInvalidMaps();
+ Class[] exceptionClasses = buildExceptionClasses();
+ for (int i = 0; i < maps.size();i++)
+ {
+ try
+ {
+ Map<String, String[]> map = maps.get(i);
+ param.append(map);
+ fail("Expected IllegalArgumentException with map=" + map);
+ }
+ catch (Exception e)
+ {
+ if (!exceptionClasses[i].isAssignableFrom(e.getClass()))
+ {
+ fail("Exception class " + exceptionClasses[i].getName() + "
(index=" + i + ") should be assignable from caught exception " +
e.getClass());
+ }
+ }
+ }
+ }
+
+ public void testAppend()
+ {
+ param.setValue("a", "b");
+ param.setValues("c", new String[]{"d", "e"});
+ param.setValue("f", "g");
+ Map<String, String[]> map = new HashMap<String, String[]>();
+ map.put("a", new String[]{"_b"});
+ map.put("c", new String[]{"_d", "_e"});
+ map.put("h", new String[]{"_i"});
+ param.append(map);
+ assertEquals(4, param.size());
+ ExtendedAssert.assertEquals(param.getValues("a"), new
String[]{"b", "_b"});
+ ExtendedAssert.assertEquals(param.getValues("c"), new
String[]{"d", "e", "_d", "_e"});
+ ExtendedAssert.assertEquals(param.getValues("f"), new
String[]{"g"});
+ ExtendedAssert.assertEquals(param.getValues("h"), new
String[]{"_i"});
+ }
+
+ public void testClear()
+ {
+ param.setValue("a", "b");
+ param.clear();
+ assertNull(param.getValue("a"));
+ }
+
+ public Class[] buildExceptionClasses()
+ {
+ return new Class[]
+ {
+ NullPointerException.class,
+ IllegalArgumentException.class,
+ IllegalArgumentException.class,
+ ClassCastException.class
+ };
+ }
+
+ public List<Map<String, String[]>> buildInvalidMaps()
+ {
+ Map<String, String[]> map1 = new HashMap<String, String[]>();
+ map1.put("a", null);
+ Map<String, String[]> map2 = new HashMap<String, String[]>();
+ map2.put("a", new String[0]);
+ Map<String, String[]> map3 = new HashMap<String, String[]>();
+ map3.put("a", new String[]{null});
+ Map map4 = new HashMap();
+ map4.put("a", new Object());
+ return Tools.toList(map1, map2, map3, (Map<String, String[]>)map4);
+ }
}