Author: julien(a)jboss.com
Date: 2008-04-16 12:47:31 -0400 (Wed, 16 Apr 2008)
New Revision: 10608
Modified:
modules/common/trunk/common/src/main/java/org/jboss/portal/common/util/AbstractTypedMap.java
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/util/typedmap/StringToIntegerMap.java
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/util/typedmap/TypedMapEntrySetTestCase.java
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/util/typedmap/TypedMapTestCase.java
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/util/typedmap/TypedMapValuesTestCase.java
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/util/typedmap/ValueConverter.java
Log:
- improved implementation of AbstractTypedMap
- AbstractTypedMap now can accept null values, depending on the value converter
Modified:
modules/common/trunk/common/src/main/java/org/jboss/portal/common/util/AbstractTypedMap.java
===================================================================
---
modules/common/trunk/common/src/main/java/org/jboss/portal/common/util/AbstractTypedMap.java 2008-04-16
14:12:51 UTC (rev 10607)
+++
modules/common/trunk/common/src/main/java/org/jboss/portal/common/util/AbstractTypedMap.java 2008-04-16
16:47:31 UTC (rev 10608)
@@ -56,90 +56,71 @@
}
/**
- * A transformer that specialize the behavior upon failures.
+ * Defines a converter that converts an internal value to an external value and vice
versa.
+ * Null values will not passed as arguments to the methods and if a conversion method
returns
+ * a null value it will be considered as a conversion failure although the
implementations should
+ * not rely and this behavior and rather rely on a adapted exception.
*/
- private abstract static class Unwrapper<Out, In> extends Transformer<Out,
In>
+ public abstract static class Converter<E, I>
{
- /**
- * @throws NullPointerException if the in argument is null
- * @throws IllegalArgumentException if the converted in argument is null
- */
- protected final Out transform(In in) throws NullPointerException,
IllegalArgumentException
+
+ private final Transformer<I, E> keyUnwrapper = new Transformer<I, E>()
{
- if (in == null)
+ protected I transform(E e)
{
- throw new NullPointerException("No null input accepted");
- }
+ if (e == null)
+ {
+ throw new NullPointerException("No null input accepted");
+ }
- //
- Out out = convert(in);
+ //
+ I i = getInternal(e);
- //
- if (out == null)
- {
- throw new IllegalArgumentException("The provided input " + out +
" was converted to a null output");
+ //
+ if (i == null)
+ {
+ throw new IllegalArgumentException("The provided input " + i +
" was converted to a null output");
+ }
+
+ //
+ return i;
}
+ };
- //
- return out;
- }
-
- protected abstract Out convert(In in);
-
- }
-
- /**
- * An transformer that specialize the behavior upon failures.
- */
- private abstract static class Wrapper<Out, In> extends Transformer<Out,
In>
- {
- /**
- * @throws IllegalStateException if the in argument is null or its conversion is
null
- * @throws IllegalArgumentException if the converted in argument is null
- */
- protected final Out transform(In in)
+ private final Transformer<E, I> keyWrapper = new Transformer<E, I>()
{
- if (in == null)
+ protected E transform(I i)
{
- throw new IllegalStateException("No null input accepted");
- }
+ if (i == null)
+ {
+ throw new IllegalStateException("No null input accepted");
+ }
- //
- Out out = convert(in);
+ //
+ E e = getExternal(i);
- //
- if (out == null)
- {
- throw new IllegalStateException("The provided input " + out +
" was converted to a null output");
+ //
+ if (e == null)
+ {
+ throw new IllegalStateException("The provided input " + e +
" was converted to a null output");
+ }
+
+ //
+ return e;
}
+ };
- //
- return out;
- }
-
- protected abstract Out convert(In in);
- }
-
- /**
- * Defines a converter that converts an internal value to an external value and vice
versa.
- * Null values will not passed as arguments to the methods and if a conversion method
returns
- * a null value it will be considered as a conversion failure although the
implementations should
- * not rely and this behavior and rather rely on a adapted exception.
- */
- public abstract static class Converter<E, I>
- {
-
- private final Unwrapper<I, E> unwrapper = new Unwrapper<I, E>()
+ private final Transformer<I, E> valueUnwrapper = new Transformer<I,
E>()
{
- protected I convert(E e)
+ protected I transform(E e)
{
return getInternal(e);
}
};
- private final Wrapper<E, I> wrapper = new Wrapper<E, I>()
+ private final Transformer<E, I> valueWrapper = new Transformer<E, I>()
{
- protected E convert(I i)
+ protected E transform(I i)
{
return getExternal(i);
}
@@ -215,7 +196,7 @@
public final boolean containsKey(Object key)
{
EK ek = (EK)key;
- IK ik = getKeyConverter().unwrapper.transform(ek);
+ IK ik = getKeyConverter().keyUnwrapper.transform(ek);
return getDelegate().containsKey(ik);
}
@@ -230,8 +211,8 @@
public final EV put(EK ek, EV ev)
{
- IK ik = getKeyConverter().unwrapper.transform(ek);
- IV iv = getValueConverter().unwrapper.transform(ev);
+ IK ik = getKeyConverter().keyUnwrapper.transform(ek);
+ IV iv = getValueConverter().valueUnwrapper.transform(ev);
Map<IK, IV> map = getDelegate();
//
@@ -247,7 +228,7 @@
boolean rollback = true;
try
{
- ev = getValueConverter().wrapper.transform(iv);
+ ev = getValueConverter().valueWrapper.transform(iv);
rollback = false;
}
finally
@@ -266,12 +247,12 @@
public final EV get(Object key)
{
EK ek = (EK)key;
- IK ik = getKeyConverter().unwrapper.transform(ek);
+ IK ik = getKeyConverter().keyUnwrapper.transform(ek);
IV iv = getDelegate().get(ik);
EV ev = null;
if (iv != null)
{
- ev = getValueConverter().wrapper.transform(iv);
+ ev = getValueConverter().valueWrapper.transform(iv);
}
return ev;
}
@@ -279,7 +260,7 @@
public final EV remove(Object key)
{
EK ek = (EK)key;
- IK ik = getKeyConverter().unwrapper.transform(ek);
+ IK ik = getKeyConverter().keyUnwrapper.transform(ek);
Map<IK, IV> map = getDelegate();
IV iv = map.remove(ik);
EV ev = null;
@@ -288,7 +269,7 @@
boolean rollback = true;
try
{
- ev = getValueConverter().wrapper.transform(iv);
+ ev = getValueConverter().valueWrapper.transform(iv);
rollback = false;
}
finally
@@ -305,7 +286,7 @@
public final boolean containsValue(Object value)
{
EV ev = (EV)value;
- IV iv = getValueConverter().unwrapper.transform(ev);
+ IV iv = getValueConverter().valueUnwrapper.transform(ev);
return getDelegate().containsValue(iv);
}
@@ -362,10 +343,10 @@
try
{
// Unwrap key, mostly for checking its type is correct
- IK ik = getKeyConverter().unwrapper.transform(thatKey);
+ IK ik = getKeyConverter().keyUnwrapper.transform(thatKey);
// Unwrap value
- IV iv = getValueConverter().unwrapper.transform(thatValue);
+ IV iv = getValueConverter().valueUnwrapper.transform(thatValue);
// Get the internal value
IV internalValue = delegate.get(ik);
@@ -415,8 +396,8 @@
Map<IK, IV> u = new HashMap<IK, IV>(t.size());
for (Entry<? extends EK, ? extends EV> entry : t.entrySet())
{
- IK ik = getKeyConverter().unwrapper.transform(entry.getKey());
- IV iv = getValueConverter().unwrapper.transform(entry.getValue());
+ IK ik = getKeyConverter().keyUnwrapper.transform(entry.getKey());
+ IV iv = getValueConverter().valueUnwrapper.transform(entry.getValue());
u.put(ik, iv);
}
return u;
@@ -442,8 +423,8 @@
{
for (Entry<IK, IV> entry : getDelegate().entrySet())
{
- getKeyConverter().wrapper.transform(entry.getKey());
- getValueConverter().wrapper.transform(entry.getValue());
+ getKeyConverter().keyWrapper.transform(entry.getKey());
+ getValueConverter().valueWrapper.transform(entry.getValue());
}
}
@@ -454,12 +435,12 @@
private final Collection<I> delegate;
/** . */
- private final Unwrapper<I, E> unwrapper;
+ private final Transformer<I, E> unwrapper;
/** . */
- private final Wrapper<E, I> wrapper;
+ private final Transformer<E, I> wrapper;
- private TypedCollection(Collection<I> delegate, Unwrapper<I, E>
unwrapper, Wrapper<E, I> wrapper)
+ private TypedCollection(Collection<I> delegate, Transformer<I, E>
unwrapper, Transformer<E, I> wrapper)
{
this.delegate = delegate;
this.unwrapper = unwrapper;
@@ -627,17 +608,17 @@
protected Transformer<EK, IK> getKeyWrapper()
{
- return getKeyConverter().wrapper;
+ return getKeyConverter().keyWrapper;
}
protected Transformer<EV, IV> getValueWrapper()
{
- return getValueConverter().wrapper;
+ return getValueConverter().valueWrapper;
}
protected Transformer<IV, EV> getValueUnwrapper()
{
- return getValueConverter().unwrapper;
+ return getValueConverter().valueUnwrapper;
}
}
@@ -650,31 +631,31 @@
protected Transformer<IK, EK> getKeyWrapper()
{
- return getKeyConverter().unwrapper;
+ return getKeyConverter().keyUnwrapper;
}
protected Transformer<IV, EV> getValueWrapper()
{
- return getValueConverter().unwrapper;
+ return getValueConverter().valueUnwrapper;
}
protected Transformer<EV, IV> getValueUnwrapper()
{
- return getValueConverter().wrapper;
+ return getValueConverter().valueWrapper;
}
}
- private class EntryWrapper extends Wrapper<Map.Entry<EK, EV>,
Map.Entry<IK, IV>>
+ private class EntryWrapper extends Transformer<Map.Entry<EK, EV>,
Map.Entry<IK, IV>>
{
- protected Entry<EK, EV> convert(Entry<IK, IV> externalEntry)
+ protected Entry<EK, EV> transform(Entry<IK, IV> externalEntry)
{
return new ExternalEntry(externalEntry);
}
}
- private class EntryUnwrapper extends Unwrapper<Map.Entry<IK, IV>,
Map.Entry<EK, EV>>
+ private class EntryUnwrapper extends Transformer<Map.Entry<IK, IV>,
Map.Entry<EK, EV>>
{
- protected Entry<IK, IV> convert(Entry<EK, EV> internalEntry)
+ protected Entry<IK, IV> transform(Entry<EK, EV> internalEntry)
{
return new InternalEntry(internalEntry);
}
@@ -684,7 +665,7 @@
{
public KeySet()
{
- super(getDelegate().keySet(), getKeyConverter().unwrapper,
getKeyConverter().wrapper);
+ super(getDelegate().keySet(), getKeyConverter().keyUnwrapper,
getKeyConverter().keyWrapper);
}
public boolean equals(Object obj)
@@ -755,7 +736,7 @@
{
public ValueCollection()
{
- super(getDelegate().values(), getValueConverter().unwrapper,
getValueConverter().wrapper);
+ super(getDelegate().values(), getValueConverter().valueUnwrapper,
getValueConverter().valueWrapper);
}
}
Modified:
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/util/typedmap/StringToIntegerMap.java
===================================================================
---
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/util/typedmap/StringToIntegerMap.java 2008-04-16
14:12:51 UTC (rev 10607)
+++
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/util/typedmap/StringToIntegerMap.java 2008-04-16
16:47:31 UTC (rev 10608)
@@ -37,4 +37,9 @@
{
super(map, new KeyConverter(), new ValueConverter());
}
+
+ public void setAcceptNull(boolean acceptNull)
+ {
+ ((ValueConverter)getValueConverter()).acceptNull = acceptNull;
+ }
}
Modified:
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/util/typedmap/TypedMapEntrySetTestCase.java
===================================================================
---
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/util/typedmap/TypedMapEntrySetTestCase.java 2008-04-16
14:12:51 UTC (rev 10607)
+++
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/util/typedmap/TypedMapEntrySetTestCase.java 2008-04-16
16:47:31 UTC (rev 10608)
@@ -195,7 +195,7 @@
}
try
{
- entries.containsAll(Tools.toList(new ExternalEntry("zero",
"0"), null));
+ entries.containsAll(Tools.toList((ExternalEntry)null));
fail();
}
catch (NullPointerException e)
@@ -204,7 +204,7 @@
}
try
{
- entries.containsAll(Tools.toList(new ExternalEntry(null, "0"),
null));
+ entries.containsAll(Tools.toList(new ExternalEntry(null, "0")));
fail();
}
catch (NullPointerException e)
@@ -213,13 +213,18 @@
}
try
{
- entries.containsAll(Tools.toList(new ExternalEntry("zero", null),
null));
+ entries.containsAll(Tools.toList(new ExternalEntry("zero", null)));
fail();
}
catch (NullPointerException e)
{
assertEquals(expected, delegate);
}
+
+ //
+ map.setAcceptNull(true);
+ delegate.put(0L, null);
+ assertTrue(entries.containsAll(Tools.toList(new ExternalEntry("zero",
null))));
}
//
@@ -346,17 +351,18 @@
public void testContainsArgumentConvertedToNull()
{
+ // blih
+// try
+// {
+// entries.contains(new ExternalEntry("one", "" +
ValueConverter.NULL));
+// fail();
+// }
+// catch (IllegalArgumentException e)
+// {
+// assertEquals(expected, delegate);
+// }
try
{
- entries.contains(new ExternalEntry("one", "" +
ValueConverter.NULL));
- fail();
- }
- catch (IllegalArgumentException e)
- {
- assertEquals(expected, delegate);
- }
- try
- {
entries.contains(new ExternalEntry(KeyConverter.NULL, "1"));
fail();
}
@@ -377,15 +383,16 @@
{
assertEquals(expected, delegate);
}
- try
- {
- entries.containsAll(Tools.toList(new ExternalEntry("zero",
"0"), new ExternalEntry("one", "" + ValueConverter.NULL)));
- fail();
- }
- catch (IllegalArgumentException e)
- {
- assertEquals(expected, delegate);
- }
+ // blih
+// try
+// {
+// entries.containsAll(Tools.toList(new ExternalEntry("zero",
"0"), new ExternalEntry("one", "" + ValueConverter.NULL)));
+// fail();
+// }
+// catch (IllegalArgumentException e)
+// {
+// assertEquals(expected, delegate);
+// }
}
//
@@ -605,16 +612,16 @@
assertEquals(expected, delegate);
}
- //
- try
- {
- entry.setValue("" + ValueConverter.NULL);
- fail();
- }
- catch (IllegalArgumentException e)
- {
- assertEquals(expected, delegate);
- }
+ // blih
+// try
+// {
+// entry.setValue("" + ValueConverter.NULL);
+// fail();
+// }
+// catch (IllegalArgumentException e)
+// {
+// assertEquals(expected, delegate);
+// }
//
try
@@ -628,16 +635,24 @@
}
//
- delegate.put((long)0, ValueConverter.NULL);
- try
- {
- entry.getValue();
- fail();
- }
- catch (IllegalStateException e)
- {
- }
+ map.setAcceptNull(true);
+ assertEquals("1", entry.setValue(null));
+ Map<Long, Integer> copy = new HashMap<Long, Integer>(expected);
+ copy.put(0L, null);
+ assertEquals(copy, delegate);
+ assertEquals(null, entry.setValue("1"));
+ // blih
+// delegate.put((long)0, ValueConverter.NULL);
+// try
+// {
+// entry.getValue();
+// fail();
+// }
+// catch (IllegalStateException e)
+// {
+// }
+
//
delegate.put((long)0, ValueConverter.IAE);
try
Modified:
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/util/typedmap/TypedMapTestCase.java
===================================================================
---
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/util/typedmap/TypedMapTestCase.java 2008-04-16
14:12:51 UTC (rev 10607)
+++
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/util/typedmap/TypedMapTestCase.java 2008-04-16
16:47:31 UTC (rev 10608)
@@ -30,6 +30,7 @@
import java.util.Set;
import org.jboss.portal.common.util.CollectionBuilder;
+import org.jboss.portal.common.util.MapBuilder;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -157,7 +158,7 @@
}
catch (CustomRuntimeException e)
{
- assertEquals(ValueConverter.UNCHECKED, delegate.get((long)0));
+ assertEquals(ValueConverter.UNCHECKED, (int)delegate.get((long)0));
}
}
@@ -171,7 +172,7 @@
}
catch (CustomRuntimeException e)
{
- assertEquals(ValueConverter.UNCHECKED, delegate.get((long)0));
+ assertEquals(ValueConverter.UNCHECKED, (int)delegate.get((long)0));
}
}
@@ -185,7 +186,7 @@
}
catch (CustomRuntimeException e)
{
- assertEquals(ValueConverter.UNCHECKED, delegate.get((long)0));
+ assertEquals(ValueConverter.UNCHECKED, (int)delegate.get((long)0));
}
}
@@ -367,6 +368,11 @@
{
assertTrue(delegate.size() == 0);
}
+
+ //
+ map.setAcceptNull(true);
+ map.put("zero", null);
+ assertEquals(MapBuilder.hashMap(0L, (Integer)null).get(), delegate);
}
public void testContainsValueNullValueArgument()
@@ -380,6 +386,12 @@
{
assertTrue(delegate.size() == 0);
}
+
+ //
+ map.setAcceptNull(true);
+ assertFalse(map.containsValue(null));
+ delegate.put((0L), null);
+ assertTrue(map.containsValue(null));
}
//
@@ -438,31 +450,33 @@
//
- public void testPutValueArgumentConvertedToNull()
- {
- try
- {
- map.put("zero", "" + ValueConverter.NULL);
- fail();
- }
- catch (IllegalArgumentException e)
- {
- assertFalse(delegate.containsKey((long)0));
- }
- }
+ // blih
+// public void testPutValueArgumentConvertedToNull()
+// {
+// try
+// {
+// map.put("zero", "" + ValueConverter.NULL);
+// fail();
+// }
+// catch (IllegalArgumentException e)
+// {
+// assertFalse(delegate.containsKey((long)0));
+// }
+// }
- public void testContainsValueValueArgumentConvertedToNull()
- {
- try
- {
- map.containsValue("" + ValueConverter.NULL);
- fail();
- }
- catch (IllegalArgumentException e)
- {
- assertTrue(delegate.size() == 0);
- }
- }
+ // blih
+// public void testContainsValueValueArgumentConvertedToNull()
+// {
+// try
+// {
+// map.containsValue("" + ValueConverter.NULL);
+// fail();
+// }
+// catch (IllegalArgumentException e)
+// {
+// assertTrue(delegate.size() == 0);
+// }
+// }
//
@@ -548,47 +562,50 @@
//
- public void testGetInternalValueConvertedToNull()
- {
- delegate.put((long)0, ValueConverter.NULL);
- try
- {
- map.get("zero");
- fail();
- }
- catch (IllegalStateException e)
- {
- assertEquals(ValueConverter.NULL, delegate.get((long)0));
- }
- }
+ // blih
+// public void testGetInternalValueConvertedToNull()
+// {
+// delegate.put((long)0, ValueConverter.NULL);
+// try
+// {
+// map.get("zero");
+// fail();
+// }
+// catch (IllegalStateException e)
+// {
+// assertEquals(ValueConverter.NULL, delegate.get((long)0));
+// }
+// }
- public void testPutInternalValueConvertedToNull()
- {
- delegate.put((long)0, ValueConverter.NULL);
- try
- {
- map.put("zero", "0");
- fail();
- }
- catch (IllegalStateException e)
- {
- assertEquals(ValueConverter.NULL, delegate.get((long)0));
- }
- }
+ // blih
+// public void testPutInternalValueConvertedToNull()
+// {
+// delegate.put((long)0, ValueConverter.NULL);
+// try
+// {
+// map.put("zero", "0");
+// fail();
+// }
+// catch (IllegalStateException e)
+// {
+// assertEquals(ValueConverter.NULL, delegate.get((long)0));
+// }
+// }
- public void testRemoveInternalValueConvertedToNull()
- {
- delegate.put((long)0, ValueConverter.NULL);
- try
- {
- map.remove("zero");
- fail();
- }
- catch (IllegalStateException e)
- {
- assertEquals(ValueConverter.NULL, delegate.get((long)0));
- }
- }
+ // blih
+// public void testRemoveInternalValueConvertedToNull()
+// {
+// delegate.put((long)0, ValueConverter.NULL);
+// try
+// {
+// map.remove("zero");
+// fail();
+// }
+// catch (IllegalStateException e)
+// {
+// assertEquals(ValueConverter.NULL, delegate.get((long)0));
+// }
+// }
Modified:
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/util/typedmap/TypedMapValuesTestCase.java
===================================================================
---
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/util/typedmap/TypedMapValuesTestCase.java 2008-04-16
14:12:51 UTC (rev 10607)
+++
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/util/typedmap/TypedMapValuesTestCase.java 2008-04-16
16:47:31 UTC (rev 10608)
@@ -29,8 +29,10 @@
import java.util.Set;
import java.util.Iterator;
import java.util.Collection;
+import java.util.ArrayList;
import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.util.MapBuilder;
import org.jboss.portal.common.NotYetImplemented;
/**
@@ -241,6 +243,13 @@
{
assertEquals(expected, delegate);
}
+
+ //
+ map.setAcceptNull(true);
+ delegate.put(0L, null);
+ delegate.put(1L, null);
+ assertTrue(values.remove(null));
+ assertEquals(MapBuilder.hashMap(delegate.keySet().iterator().next(),
(Integer)null).get(), delegate);
}
public void testContainsNullArgument()
@@ -254,6 +263,11 @@
{
assertEquals(expected, delegate);
}
+
+ //
+ map.setAcceptNull(true);
+ delegate.put(0L, null);
+ assertTrue(values.contains(null));
}
public void testRemoveAllNullArgument()
@@ -267,6 +281,8 @@
{
assertEquals(expected, delegate);
}
+
+ //
try
{
values.removeAll(Tools.toList("0", null));
@@ -276,6 +292,15 @@
{
assertEquals(expected, delegate);
}
+
+ //
+ map.setAcceptNull(true);
+ delegate.put(0L, 0);
+ delegate.put(1L, null);
+ delegate.put(2L, null);
+ delegate.put(3L, 3);
+ assertTrue(values.removeAll(Tools.toList("0", null)));
+ assertEquals(MapBuilder.hashMap(3L, 3).get(), delegate);
}
public void testRetainAllNullArgument()
@@ -289,6 +314,8 @@
{
assertEquals(expected, delegate);
}
+
+ //
try
{
values.retainAll(Tools.toList("0", null));
@@ -298,6 +325,15 @@
{
assertEquals(expected, delegate);
}
+
+ //
+ delegate.put(0L, 0);
+ delegate.put(1L, null);
+ delegate.put(2L, null);
+ delegate.put(3L, 3);
+ map.setAcceptNull(true);
+ assertTrue(values.retainAll(Tools.toList("0", null)));
+ assertEquals(MapBuilder.hashMap(0L, 0).put(1L, null).put(2L, null).get(),
delegate);
}
public void testContainsAllNullArgument()
@@ -311,6 +347,8 @@
{
assertEquals(expected, delegate);
}
+
+ //
try
{
values.containsAll(Tools.toList("0", null));
@@ -320,6 +358,12 @@
{
assertEquals(expected, delegate);
}
+
+ //
+ map.setAcceptNull(true);
+ delegate.put(0L, 0);
+ delegate.put(1L, null);
+ assertTrue(values.containsAll(Tools.toList("0", null)));
}
//
@@ -525,19 +569,27 @@
//
+ // blih
+/*
public void testRemoveArgumentConvertedToNull()
{
try
{
- values.remove("" + ValueConverter.NULL);
+ values.remove(ValueConverter.NULL);
fail();
}
- catch (IllegalArgumentException e)
+ catch (NullPointerException e)
{
assertEquals(expected, delegate);
}
+
+ //
+ map.setAcceptNull(true);
}
+*/
+ // blih
+/*
public void testContainsArgumentConvertedToNull()
{
try
@@ -550,6 +602,7 @@
assertEquals(expected, delegate);
}
}
+*/
public void testRemoveAllArgumentConvertedToNull()
{
@@ -564,31 +617,33 @@
}
}
- public void testRetainAllArgumentConvertedToNull()
- {
- try
- {
- values.retainAll(Tools.toList("0", ""+
ValueConverter.NULL));
- fail();
- }
- catch (IllegalArgumentException e)
- {
- assertEquals(expected, delegate);
- }
- }
+ // blih
+// public void testRetainAllArgumentConvertedToNull()
+// {
+// try
+// {
+// values.retainAll(Tools.toList("0", ""+
ValueConverter.NULL));
+// fail();
+// }
+// catch (IllegalArgumentException e)
+// {
+// assertEquals(expected, delegate);
+// }
+// }
- public void testContainsAllArgumentConvertedToNull()
- {
- try
- {
- values.containsAll(Tools.toList("0", "" +
ValueConverter.NULL));
- fail();
- }
- catch (IllegalArgumentException e)
- {
- assertEquals(expected, delegate);
- }
- }
+ // blih
+// public void testContainsAllArgumentConvertedToNull()
+// {
+// try
+// {
+// values.containsAll(Tools.toList("0", "" +
ValueConverter.NULL));
+// fail();
+// }
+// catch (IllegalArgumentException e)
+// {
+// assertEquals(expected, delegate);
+// }
+// }
//
Modified:
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/util/typedmap/ValueConverter.java
===================================================================
---
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/util/typedmap/ValueConverter.java 2008-04-16
14:12:51 UTC (rev 10607)
+++
modules/common/trunk/common/src/test/java/org/jboss/portal/test/common/util/typedmap/ValueConverter.java 2008-04-16
16:47:31 UTC (rev 10608)
@@ -32,18 +32,35 @@
public class ValueConverter extends AbstractTypedMap.Converter<String, Integer>
{
- public static final Integer NULL = 10;
- public static final Integer UNCHECKED = 11;
- public static final Integer IAE = 12;
- public static final Integer CCE = 13;
+ public static final Integer NULL = null;
+ public static final int UNCHECKED = 11;
+ public static final int IAE = 12;
+ public static final int CCE = 13;
+ /** . */
+ boolean acceptNull;
+ public ValueConverter()
+ {
+ this.acceptNull = false;
+ }
+
protected Integer getInternal(String external) throws IllegalArgumentException,
ClassCastException
{
- Assert.assertNotNull(external);
+ if (external == null)
+ {
+ if (acceptNull)
+ {
+ return null;
+ }
+ else
+ {
+ throw new NullPointerException();
+ }
+ }
//
- int i;
+ Integer i;
try
{
i = new Integer(external);
@@ -56,10 +73,12 @@
}
//
- if (NULL == i)
+ if (i == null)
{
return null;
}
+
+ //
if (UNCHECKED == i)
{
throw new CustomRuntimeException();
@@ -79,22 +98,28 @@
protected String getExternal(Integer internal)
{
- Assert.assertNotNull(internal);
+ if (internal == null)
+ {
+ if (acceptNull)
+ {
+ return null;
+ }
+ else
+ {
+ throw new IllegalStateException();
+ }
+ }
//
- if (NULL.equals(internal))
+ if (UNCHECKED == internal)
{
- return null;
- }
- if (UNCHECKED.equals(internal))
- {
throw new CustomRuntimeException();
}
- if (IAE.equals(internal))
+ if (IAE == internal)
{
throw new IllegalArgumentException();
}
- if (CCE.equals(internal))
+ if (CCE == internal)
{
throw new ClassCastException();
}