svn commit: r1860023 - in /ofbiz/ofbiz-framework/trunk/framework/base: src/main/java/org/apache/ofbiz/base/conversion/test/TestBooleanConverters.java src/test/java/org/apache/ofbiz/base/conversion/TestBooleanConverters.java testdef/basetests.xml

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1860023 - in /ofbiz/ofbiz-framework/trunk/framework/base: src/main/java/org/apache/ofbiz/base/conversion/test/TestBooleanConverters.java src/test/java/org/apache/ofbiz/base/conversion/TestBooleanConverters.java testdef/basetests.xml

mthl
Author: mthl
Date: Sat May 25 21:54:01 2019
New Revision: 1860023

URL: http://svn.apache.org/viewvc?rev=1860023&view=rev
Log:
Improved: Turn ‘TestBooleanConverters’ into a unit test class
(OFBIZ-11067)

Added:
    ofbiz/ofbiz-framework/trunk/framework/base/src/test/java/org/apache/ofbiz/base/conversion/TestBooleanConverters.java   (with props)
Removed:
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/conversion/test/TestBooleanConverters.java
Modified:
    ofbiz/ofbiz-framework/trunk/framework/base/testdef/basetests.xml

Added: ofbiz/ofbiz-framework/trunk/framework/base/src/test/java/org/apache/ofbiz/base/conversion/TestBooleanConverters.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/test/java/org/apache/ofbiz/base/conversion/TestBooleanConverters.java?rev=1860023&view=auto
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/test/java/org/apache/ofbiz/base/conversion/TestBooleanConverters.java (added)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/test/java/org/apache/ofbiz/base/conversion/TestBooleanConverters.java Sat May 25 21:54:01 2019
@@ -0,0 +1,76 @@
+/*
+ * 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.ofbiz.base.conversion;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.ofbiz.base.conversion.BooleanConverters;
+import org.apache.ofbiz.base.conversion.Converter;
+import org.apache.ofbiz.base.conversion.ConverterLoader;
+import org.apache.ofbiz.base.conversion.Converters;
+import org.apache.ofbiz.base.util.UtilGenerics;
+import org.junit.Test;
+
+public class TestBooleanConverters {
+
+    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));
+    }
+
+    public static <S> void assertToCollection(String label, S source) throws Exception {
+        Converter<S, ? extends Collection<S>> toList =
+                UtilGenerics.cast(Converters.getConverter(source.getClass(), List.class));
+        Collection<S> listResult = toList.convert(source);
+        assertEquals(label + " converted to List", source, listResult.toArray()[0]);
+        Converter<S, ? extends Collection<S>> toSet =
+                UtilGenerics.cast(Converters.getConverter(source.getClass(), Set.class));
+        Collection<S> setResult = toSet.convert(source);
+        assertEquals(label + " converted to Set", source, setResult.toArray()[0]);
+    }
+
+    @Test
+    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("BooleanToCollection", Boolean.TRUE);
+    }
+}

Propchange: ofbiz/ofbiz-framework/trunk/framework/base/src/test/java/org/apache/ofbiz/base/conversion/TestBooleanConverters.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ofbiz/ofbiz-framework/trunk/framework/base/src/test/java/org/apache/ofbiz/base/conversion/TestBooleanConverters.java
------------------------------------------------------------------------------
    svn:keywords = Date Rev Author URL Id

Propchange: ofbiz/ofbiz-framework/trunk/framework/base/src/test/java/org/apache/ofbiz/base/conversion/TestBooleanConverters.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: ofbiz/ofbiz-framework/trunk/framework/base/testdef/basetests.xml
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/testdef/basetests.xml?rev=1860023&r1=1860022&r2=1860023&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/testdef/basetests.xml (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/testdef/basetests.xml Sat May 25 21:54:01 2019
@@ -25,7 +25,6 @@
         <junit-test-suite class-name="org.apache.ofbiz.base.util.test.UtilObjectTests"/>
         <junit-test-suite class-name="org.apache.ofbiz.base.util.string.test.FlexibleStringExpanderTests"/>
         <junit-test-suite class-name="org.apache.ofbiz.base.util.collections.test.FlexibleMapAccessorTests"/>
-        <junit-test-suite class-name="org.apache.ofbiz.base.conversion.test.TestBooleanConverters"/>
         <junit-test-suite class-name="org.apache.ofbiz.base.conversion.test.TestJSONConverters"/>
         <groovy-test-suite name="simple" location="component://base/groovyScripts/test/SimpleTests.groovy"/>
     </test-group>