commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adri...@apache.org
Subject svn commit: r923475 - /commons/sandbox/convert/trunk/src/test/java/org/apache/commons/convert/TestBooleanConverters.java
Date Mon, 15 Mar 2010 22:27:31 GMT
Author: adrianc
Date: Mon Mar 15 22:27:31 2010
New Revision: 923475

URL: http://svn.apache.org/viewvc?rev=923475&view=rev
Log:
Improved boolean converter test code.

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=923475&r1=923474&r2=923475&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
Mon Mar 15 22:27:31 2010
@@ -29,20 +29,22 @@ public class TestBooleanConverters exten
         super(name);
     }
 
-    public static <S, T> void assertConversion(String label, Converter<S, T>
converter, S source, T target) throws Exception {
-        assertTrue(label + " can convert", converter.canConvert(source.getClass(), target.getClass()));
-        assertEquals(label + " converted", target, converter.convert(source));
+    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 + " converted", trueResult, converter.convert(true));
+        assertEquals(label + " converted", falseResult, converter.convert(false));
+    }
+
+    public static <T> void assertToBoolean(String label, Converter<T, Boolean>
converter, T trueSource, T falseSource) throws Exception {
+        assertTrue(label + " can convert", converter.canConvert(trueSource.getClass(), Boolean.class));
+        assertEquals(label + " converted", Boolean.TRUE, converter.convert(trueSource));
+        assertEquals(label + " converted", Boolean.FALSE, converter.convert(falseSource));
     }
 
     public void testBooleanConverters() throws Exception {
-        assertConversion("BooleanToInteger", new BooleanConverters.BooleanToInteger(), true,
1);
-        assertConversion("BooleanToInteger", new BooleanConverters.BooleanToInteger(), false,
0);
-        assertConversion("BooleanToString", new BooleanConverters.BooleanToString(), true,
"true");
-        assertConversion("BooleanToString", new BooleanConverters.BooleanToString(), false,
"false");
-        assertConversion("IntegerToBoolean", new BooleanConverters.IntegerToBoolean(), 1,
true);
-        assertConversion("IntegerToBoolean", new BooleanConverters.IntegerToBoolean(), 0,
false);
-        assertConversion("StringToBoolean", new BooleanConverters.StringToBoolean(), "false",
false);
-        assertConversion("StringToBoolean", new BooleanConverters.StringToBoolean(), "notTrue",
false);
-        assertConversion("StringToBoolean", new BooleanConverters.StringToBoolean(), "true",
true);
+        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");
     }
 }



Mime
View raw message