Skip to content

Commit

Permalink
Improved: Turn ‘TestJSONConverters’ into a unit test class
Browse files Browse the repository at this point in the history
(OFBIZ-11067)


git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1860024 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
mthl committed May 25, 2019
1 parent 4418894 commit 5ac6be8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*******************************************************************************
/*
* 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
Expand All @@ -15,8 +15,10 @@
* 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.test;
*/
package org.apache.ofbiz.base.conversion;

import static org.junit.Assert.assertEquals;

import java.math.BigDecimal;
import java.util.ArrayList;
Expand All @@ -25,24 +27,20 @@
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.conversion.JSONConverters;
import org.apache.ofbiz.base.lang.JSON;
import org.apache.ofbiz.base.util.UtilGenerics;
import org.junit.Test;

import junit.framework.TestCase;

public class TestJSONConverters extends TestCase {
public TestJSONConverters(String name) {
super(name);
public class TestJSONConverters {
public TestJSONConverters() {
ConverterLoader loader = new JSONConverters();
loader.loadConverters();
}

@Test
public void testJSONToMap() throws Exception {
Converter<JSON, Map<String,String>> converter = UtilGenerics.cast(Converters.getConverter(JSON.class, Map.class));
Converter<JSON, Map<String,String>> converter =
UtilGenerics.cast(Converters.getConverter(JSON.class, Map.class));
Map<String,String> map, convertedMap;
map = new HashMap<>();
map.put("field1", "value1");
Expand All @@ -51,6 +49,7 @@ public void testJSONToMap() throws Exception {
assertEquals("JSON to Map", map, convertedMap);
}

@Test
public void testJSONToList() throws Exception {
Converter<JSON, List<Object>> converter = UtilGenerics.cast(Converters.getConverter(JSON.class, List.class));
List<Object> list, convertedList;
Expand All @@ -62,8 +61,10 @@ public void testJSONToList() throws Exception {
assertEquals("JSON to List", list, convertedList);
}

@Test
public void testMapToJSON() throws Exception {
Converter<Map<String,Object>, JSON> converter = UtilGenerics.cast(Converters.getConverter(Map.class, JSON.class));
Converter<Map<String,Object>, JSON> converter =
UtilGenerics.cast(Converters.getConverter(Map.class, JSON.class));
JSON json;
Map<String,Object> map = new LinkedHashMap<>();
map.put("field1", "value1");
Expand All @@ -72,6 +73,7 @@ public void testMapToJSON() throws Exception {
assertEquals("Map to JSON", "{\"field1\":\"value1\",\"field2\":3.7}", json.toString());
}

@Test
public void testListToJSON() throws Exception {
Converter<List<String>, JSON> converter = UtilGenerics.cast(Converters.getConverter(List.class, JSON.class));
JSON json;
Expand Down
1 change: 0 additions & 1 deletion framework/base/testdef/basetests.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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.TestJSONConverters"/>
<groovy-test-suite name="simple" location="component://base/groovyScripts/test/SimpleTests.groovy"/>
</test-group>
</test-suite>

0 comments on commit 5ac6be8

Please sign in to comment.