commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adri...@apache.org
Subject svn commit: r931014 - /commons/sandbox/convert/trunk/src/test/java/org/apache/commons/convert/TestBooleanConverters.java
Date Tue, 06 Apr 2010 04:48:23 GMT
Author: adrianc
Date: Tue Apr  6 04:48:23 2010
New Revision: 931014

URL: http://svn.apache.org/viewvc?rev=931014&view=rev
Log:
Improved test coverage on Boolean converters.

Modified:
    commons/sandbox/convert/trunk/src/test/java/org/apache/commons/convert/TestBooleanConverters.java

Modified: commons/sandbox/convert/trunk/src/test/java/org/apache/commons/convert/TestBooleanConverters.java
URL: http://svn.apache.org/viewvc/commons/sandbox/convert/trunk/src/test/java/org/apache/commons/convert/TestBooleanConverters.java?rev=931014&r1=931013&r2=931014&view=diff
==============================================================================
--- commons/sandbox/convert/trunk/src/test/java/org/apache/commons/convert/TestBooleanConverters.java
(original)
+++ commons/sandbox/convert/trunk/src/test/java/org/apache/commons/convert/TestBooleanConverters.java
Tue Apr  6 04:48:23 2010
@@ -18,7 +18,12 @@
  *******************************************************************************/
 package org.apache.commons.convert;
 
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+
 import org.apache.commons.convert.Converter;
+import org.apache.commons.convert.Converters;
 import org.apache.commons.convert.BooleanConverters;
 
 import junit.framework.TestCase;
@@ -31,20 +36,34 @@ public class TestBooleanConverters exten
 
     public static <T> void assertFromBoolean(String label, Converter<Boolean, T>
converter, T trueResult, T falseResult) throws Exception {
         assertTrue(label + " can convert", converter.canConvert(Boolean.class, trueResult.getClass()));
+        assertEquals(label + " registered", converter.getClass(), Converters.getConverter(Boolean.class,
trueResult.getClass()).getClass());
         assertEquals(label + " converted", trueResult, converter.convert(true));
         assertEquals(label + " converted", falseResult, converter.convert(false));
     }
 
     public static <S> void assertToBoolean(String label, Converter<S, Boolean>
converter, S trueSource, S falseSource) throws Exception {
         assertTrue(label + " can convert", converter.canConvert(trueSource.getClass(), Boolean.class));
+        assertEquals(label + " registered", converter.getClass(), Converters.getConverter(trueSource.getClass(),
Boolean.class).getClass());
         assertEquals(label + " converted", Boolean.TRUE, converter.convert(trueSource));
         assertEquals(label + " converted", Boolean.FALSE, converter.convert(falseSource));
     }
 
+    @SuppressWarnings("unchecked")
+    public static void assertToCollection(String label, Converter<Boolean, ? extends Collection<Boolean>>
converter, Class<? extends Collection> targetClass) throws Exception {
+        assertTrue(label + " can convert", converter.canConvert(Boolean.class, targetClass
));
+        assertEquals(label + " registered", converter.getClass(), Converters.getConverter(Boolean.class,
targetClass).getClass());
+        Collection<Boolean> result = converter.convert(Boolean.TRUE);
+        assertEquals(label + " converted", Boolean.TRUE, result.toArray()[0]);
+    }
+
     public void testBooleanConverters() throws Exception {
+        ConverterLoader loader = new BooleanConverters();
+        loader.loadConverters();
         assertFromBoolean("BooleanToInteger", new BooleanConverters.BooleanToInteger(), 1,
0);
         assertFromBoolean("BooleanToString", new BooleanConverters.BooleanToString(), "true",
"false");
         assertToBoolean("IntegerToBoolean", new BooleanConverters.IntegerToBoolean(), 1,
0);
         assertToBoolean("StringToBoolean", new BooleanConverters.StringToBoolean(), "true",
"false");
+        assertToCollection("BooleanToList", new BooleanConverters.BooleanToList(), List.class);
+        assertToCollection("BooleanToSet", new BooleanConverters.BooleanToSet(), Set.class);
     }
 }



Mime
View raw message