commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adri...@apache.org
Subject svn commit: r922778 - in /commons/sandbox/convert/trunk/src: main/java/org/apache/commons/convert/BooleanConverters.java test/java/org/apache/commons/convert/TestBooleanConverters.java
Date Sun, 14 Mar 2010 07:14:17 GMT
Author: adrianc
Date: Sun Mar 14 07:14:17 2010
New Revision: 922778

URL: http://svn.apache.org/viewvc?rev=922778&view=rev
Log:
Added boolean converters tests.

Added:
    commons/sandbox/convert/trunk/src/test/java/org/apache/commons/convert/TestBooleanConverters.java
  (with props)
Modified:
    commons/sandbox/convert/trunk/src/main/java/org/apache/commons/convert/BooleanConverters.java

Modified: commons/sandbox/convert/trunk/src/main/java/org/apache/commons/convert/BooleanConverters.java
URL: http://svn.apache.org/viewvc/commons/sandbox/convert/trunk/src/main/java/org/apache/commons/convert/BooleanConverters.java?rev=922778&r1=922777&r2=922778&view=diff
==============================================================================
--- commons/sandbox/convert/trunk/src/main/java/org/apache/commons/convert/BooleanConverters.java
(original)
+++ commons/sandbox/convert/trunk/src/main/java/org/apache/commons/convert/BooleanConverters.java
Sun Mar 14 07:14:17 2010
@@ -48,7 +48,7 @@ public class BooleanConverters implement
         }
 
         public String convert(Boolean obj) throws ConversionException {
-            return obj.booleanValue() ? "true" : "false";
+            return obj.toString();
         }
     }
 

Added: 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=922778&view=auto
==============================================================================
--- commons/sandbox/convert/trunk/src/test/java/org/apache/commons/convert/TestBooleanConverters.java
(added)
+++ commons/sandbox/convert/trunk/src/test/java/org/apache/commons/convert/TestBooleanConverters.java
Sun Mar 14 07:14:17 2010
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *******************************************************************************/
+package org.apache.commons.convert;
+
+import org.apache.commons.convert.Converter;
+import org.apache.commons.convert.BooleanConverters;
+
+import junit.framework.TestCase;
+
+public class TestBooleanConverters extends TestCase {
+
+    public TestBooleanConverters(String name) {
+        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 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);
+    }
+}

Propchange: commons/sandbox/convert/trunk/src/test/java/org/apache/commons/convert/TestBooleanConverters.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/convert/trunk/src/test/java/org/apache/commons/convert/TestBooleanConverters.java
------------------------------------------------------------------------------
    svn:keywords = Date Rev Author URL Id

Propchange: commons/sandbox/convert/trunk/src/test/java/org/apache/commons/convert/TestBooleanConverters.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message