Author: mthl
Date: Sat May 25 14:25:28 2019 New Revision: 1859982 URL: http://svn.apache.org/viewvc?rev=1859982&view=rev Log: Improved: Turn ‘MiscTests’ into a unit test class (OFBIZ-11067) Added: ofbiz/ofbiz-framework/trunk/framework/base/src/test/java/org/apache/ofbiz/base/conversion/MiscTests.java (with props) Removed: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/conversion/test/MiscTests.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/MiscTests.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/test/java/org/apache/ofbiz/base/conversion/MiscTests.java?rev=1859982&view=auto ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/base/src/test/java/org/apache/ofbiz/base/conversion/MiscTests.java (added) +++ ofbiz/ofbiz-framework/trunk/framework/base/src/test/java/org/apache/ofbiz/base/conversion/MiscTests.java Sat May 25 14:25:28 2019 @@ -0,0 +1,92 @@ +/* + * 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.assertSame; +import static org.junit.Assert.assertTrue; + +import java.math.BigDecimal; +import java.net.URL; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +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.apache.ofbiz.base.util.UtilMisc; +import org.junit.Test; + +public class MiscTests { + + public static class ConverterLoaderImpl implements ConverterLoader { + @Override + public void loadConverters() { + throw new RuntimeException(); + } + } + + @Test + public void testLoadContainedConvertersIgnoresException() { + Converters.loadContainedConverters(MiscTests.class); + } + + public static <S> void assertPassThru(Object wanted, Class<S> sourceClass) throws Exception { + assertPassThru(wanted, sourceClass, sourceClass); + } + + public static <S> void assertPassThru(Object wanted, Class<S> sourceClass, Class<? super S> targetClass) throws Exception { + Converter<S, ? super S> converter = Converters.getConverter(sourceClass, targetClass); + Object result = converter.convert(UtilGenerics.<S>cast(wanted)); + assertEquals("pass thru convert", wanted, result); + assertSame("pass thru exact equals", wanted, result); + assertTrue("pass thru can convert wanted", converter.canConvert(wanted.getClass(), targetClass)); + assertTrue("pass thru can convert source", converter.canConvert(sourceClass, targetClass)); + assertEquals("pass thru source class", wanted.getClass(), converter.getSourceClass()); + assertEquals("pass thru target class", targetClass, converter.getTargetClass()); + } + + @Test + public void testPassthru() throws Exception { + String string = "ofbiz"; + BigDecimal bigDecimal = new BigDecimal("1.234"); + URL url = new URL("http://ofbiz.apache.org"); + List<String> baseList = UtilMisc.toList("a", "1", "b", "2", "c", "3"); + List<String> arrayList = new ArrayList<>(); + arrayList.addAll(baseList); + Map<String, String> baseMap = UtilMisc.toMap("a", "1", "b", "2", "c", "3"); + Map<String, String> hashMap = new HashMap<>(); + hashMap.putAll(baseMap); + Object[] testObjects = new Object[] { + string, + bigDecimal, + url, + arrayList, + hashMap + }; + for (Object testObject: testObjects) { + assertPassThru(testObject, testObject.getClass()); + } + assertPassThru(arrayList, arrayList.getClass(), List.class); + assertPassThru(hashMap, hashMap.getClass(), Map.class); + } +} Propchange: ofbiz/ofbiz-framework/trunk/framework/base/src/test/java/org/apache/ofbiz/base/conversion/MiscTests.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/ofbiz-framework/trunk/framework/base/src/test/java/org/apache/ofbiz/base/conversion/MiscTests.java ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: ofbiz/ofbiz-framework/trunk/framework/base/src/test/java/org/apache/ofbiz/base/conversion/MiscTests.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=1859982&r1=1859981&r2=1859982&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/base/testdef/basetests.xml (original) +++ ofbiz/ofbiz-framework/trunk/framework/base/testdef/basetests.xml Sat May 25 14:25:28 2019 @@ -33,7 +33,6 @@ <junit-test-suite class-name="org.apache.ofbiz.base.util.collections.test.FlexibleMapAccessorTests"/> <junit-test-suite class-name="org.apache.ofbiz.base.util.test.TimeDurationTests"/> <junit-test-suite class-name="org.apache.ofbiz.base.util.cache.test.UtilCacheTests"/> - <junit-test-suite class-name="org.apache.ofbiz.base.conversion.test.MiscTests"/> <junit-test-suite class-name="org.apache.ofbiz.base.conversion.test.TestBooleanConverters"/> <junit-test-suite class-name="org.apache.ofbiz.base.conversion.test.TestJSONConverters"/> <!--junit-test-suite class-name="org.apache.ofbiz.base.util.test.UtilIOTests"/--> |
Free forum by Nabble | Edit this page |