Skip to content
Permalink
Browse files

Improved: Lint unit tests

This makes no behavioral changes, only coding style fixes.


git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1869037 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
mthl committed Oct 27, 2019
1 parent d5e0963 commit 59efa181d2f318456be5546b432ca7f724dfe11b
Showing with 368 additions and 316 deletions.
  1. +0 −1 build.gradle
  2. +10 −7 framework/base/src/test/java/org/apache/ofbiz/base/conversion/DateTimeTests.java
  3. +3 −5 framework/base/src/test/java/org/apache/ofbiz/base/conversion/MiscTests.java
  4. +0 −4 framework/base/src/test/java/org/apache/ofbiz/base/conversion/TestBooleanConverters.java
  5. +7 −7 framework/base/src/test/java/org/apache/ofbiz/base/conversion/TestJSONConverters.java
  6. +4 −3 framework/base/src/test/java/org/apache/ofbiz/base/lang/ComparableRangeTests.java
  7. +7 −7 framework/base/src/test/java/org/apache/ofbiz/base/test/BaseUnitTests.java
  8. +27 −27 framework/base/src/test/java/org/apache/ofbiz/base/util/AssertTests.java
  9. +0 −1 framework/base/src/test/java/org/apache/ofbiz/base/util/IndentingWriterTests.java
  10. +54 −61 framework/base/src/test/java/org/apache/ofbiz/base/util/ObjectTypeTests.java
  11. +0 −1 framework/base/src/test/java/org/apache/ofbiz/base/util/ReferenceCleanerTests.java
  12. +4 −4 framework/base/src/test/java/org/apache/ofbiz/base/util/StringUtilTests.java
  13. +91 −70 framework/base/src/test/java/org/apache/ofbiz/base/util/TimeDurationTests.java
  14. +30 −21 framework/base/src/test/java/org/apache/ofbiz/base/util/UtilCodecTests.java
  15. +8 −2 framework/base/src/test/java/org/apache/ofbiz/base/util/UtilHttpTest.java
  16. +33 −26 framework/base/src/test/java/org/apache/ofbiz/base/util/UtilIOTests.java
  17. +0 −1 framework/base/src/test/java/org/apache/ofbiz/base/util/UtilMiscTests.java
  18. +10 −13 framework/base/src/test/java/org/apache/ofbiz/base/util/UtilPropertiesTests.java
  19. +13 −7 framework/base/src/test/java/org/apache/ofbiz/base/util/cache/UtilCacheTests.java
  20. +33 −24 framework/base/src/test/java/org/apache/ofbiz/base/util/collections/GenericMapTest.java
  21. +4 −5 framework/base/src/test/java/org/apache/ofbiz/base/util/collections/MapContextTest.java
  22. +7 −3 framework/common/src/test/java/org/apache/ofbiz/common/GetLocaleListTests.java
  23. +8 −6 framework/entity/src/test/java/org/apache/ofbiz/entity/EntityConditionVisitorTests.java
  24. +4 −3 framework/entity/src/test/java/org/apache/ofbiz/entity/util/EntitySaxReaderTests.java
  25. +6 −2 framework/webapp/src/test/java/org/apache/ofbiz/webapp/WebAppCacheTest.java
  26. +1 −1 framework/webapp/src/test/java/org/apache/ofbiz/webapp/control/ControlFilterTests.java
  27. +4 −4 framework/webapp/src/test/java/org/apache/ofbiz/webapp/control/RequestHandlerTests.java
@@ -308,7 +308,6 @@ checkstyle {
// ‘checkstyle’ tool present in the framework and in the official
// plugins.
tasks.checkstyleMain.maxErrors = 37830
tasks.checkstyleTest.maxErrors = 176
// Currently there are a lot of errors so we need to temporarily
// hide them to avoid polluting the terminal output.
showViolations = false
@@ -22,15 +22,14 @@
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;

import org.apache.ofbiz.base.conversion.Converter;
import org.apache.ofbiz.base.conversion.DateTimeConverters;
import org.junit.Test;

import com.ibm.icu.util.Calendar;

public class DateTimeTests {

private static <S, T> void assertConversion(String label, Converter<S, T> converter, S source, T target) throws Exception {
private 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));
}
@@ -48,7 +47,8 @@ public void testDateTimeConverters() throws Exception {
java.sql.Timestamp timestamp = new java.sql.Timestamp(longTime);
// Source class = java.util.Date
assertConversion("DateToLong", new DateTimeConverters.DateToLong(), utilDate, longTime);
assertConversion("DateToSqlDate", new DateTimeConverters.DateToSqlDate(), utilDate, new java.sql.Date(longTime));
assertConversion("DateToSqlDate", new DateTimeConverters.DateToSqlDate(), utilDate,
new java.sql.Date(longTime));
assertConversion("DateToString", new DateTimeConverters.DateToString(), utilDate, utilDate.toString());
assertConversion("DateToTimestamp", new DateTimeConverters.DateToTimestamp(), utilDate, timestamp);
// Source class = java.sql.Date
@@ -60,13 +60,16 @@ public void testDateTimeConverters() throws Exception {
assertConversion("TimestampToLong", new DateTimeConverters.DateToLong(), timestamp, longTime);
assertConversion("TimestampToDate", new DateTimeConverters.TimestampToDate(), timestamp, utilDate);
assertConversion("TimestampToSqlDate", new DateTimeConverters.TimestampToSqlDate(), timestamp, sqlDate);
assertConversion("TimestampToString", new DateTimeConverters.TimestampToString(), timestamp, timestamp.toString());
assertConversion("TimestampToString", new DateTimeConverters.TimestampToString(), timestamp,
timestamp.toString());
// Source class = java.lang.Long
assertConversion("LongToDate", new DateTimeConverters.NumberToDate(), longTime, utilDate);
assertConversion("LongToSqlDate", new DateTimeConverters.NumberToSqlDate(), longTime, sqlDate);
assertConversion("LongToSqlDate", new DateTimeConverters.NumberToSqlDate(), currentTime, sqlDate); //Test conversion to start of day
//Test conversion to start of day
assertConversion("LongToSqlDate", new DateTimeConverters.NumberToSqlDate(), currentTime, sqlDate);
assertConversion("LongToTimestamp", new DateTimeConverters.NumberToTimestamp(), longTime, timestamp);
// Source class = java.lang.String
assertConversion("StringToTimestamp", new DateTimeConverters.StringToTimestamp(), timestamp.toString(), timestamp);
assertConversion("StringToTimestamp", new DateTimeConverters.StringToTimestamp(), timestamp.toString(),
timestamp);
}
}
@@ -29,16 +29,13 @@
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 {
public static final class ConverterLoaderImpl implements ConverterLoader {
@Override
public void loadConverters() {
throw new RuntimeException();
@@ -54,7 +51,8 @@ public void testLoadContainedConvertersIgnoresException() {
assertPassThru(wanted, sourceClass, sourceClass);
}

public static <S> void assertPassThru(Object wanted, Class<S> sourceClass, Class<? super S> targetClass) throws Exception {
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);
@@ -25,10 +25,6 @@
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;

@@ -39,9 +39,10 @@ public TestJSONConverters() {

@Test
public void testJSONToMap() throws Exception {
Converter<JSON, Map<String,String>> converter =
Converter<JSON, Map<String, String>> converter =
UtilGenerics.cast(Converters.getConverter(JSON.class, Map.class));
Map<String,String> map, convertedMap;
Map<String, String> map;
Map<String, String> convertedMap;
map = new HashMap<>();
map.put("field1", "value1");
JSON json = JSON.from(map);
@@ -53,22 +54,21 @@ public void testJSONToMap() throws Exception {
@Test
public void testJSONToList() throws Exception {
Converter<JSON, List<Object>> converter = UtilGenerics.cast(Converters.getConverter(JSON.class, List.class));
List<Object> list, convertedList;
list = new ArrayList<>();
List<Object> list = new ArrayList<>();
list.add("field1");
list.add("field2");
JSON json = JSON.from(list);
Object obj = converter.convert(json);
convertedList = (obj instanceof List) ? UtilGenerics.cast(obj) : null;
List<Object> convertedList = (obj instanceof List) ? UtilGenerics.cast(obj) : null;
assertEquals("JSON to List", list, convertedList);
}

@Test
public void testMapToJSON() throws Exception {
Converter<Map<String,Object>, JSON> converter =
Converter<Map<String, Object>, JSON> converter =
UtilGenerics.cast(Converters.getConverter(Map.class, JSON.class));
JSON json;
Map<String,Object> map = new LinkedHashMap<>();
Map<String, Object> map = new LinkedHashMap<>();
map.put("field1", "value1");
map.put("field2", new BigDecimal("3.7"));
json = converter.convert(map);
@@ -27,18 +27,19 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import org.apache.ofbiz.base.lang.ComparableRange;
import org.apache.ofbiz.base.util.UtilGenerics;
import org.junit.Test;

public class ComparableRangeTests {

private static <L extends Comparable<L>, R extends Comparable<R>> void comparableRangeConstructorTest(L left, R right) {
private static <L extends Comparable<L>, R extends Comparable<R>> void comparableRangeConstructorTest(L left,
R right) {
new ComparableRange<>(left, left);
new ComparableRange<>(right, right);
}

private static <T extends Comparable<T>, B extends Comparable<B>> void comparableRangeTest(String label, B bad, T a, T b, T c, T d) {
private static <T extends Comparable<T>, B extends Comparable<B>> void comparableRangeTest(String label, B bad,
T a, T b, T c, T d) {
comparableRangeConstructorTest(bad, a);
assertTrue(label + ":a-isPoint", new ComparableRange<>(a, a).isPoint());
assertTrue(label + ":b-isPoint", new ComparableRange<>(b, b).isPoint());
@@ -48,43 +48,43 @@ public void testDebug() {
}

@Test
public void testFormatPrintableCreditCard_1() {
public void testFormatPrintableCreditCard1() {
assertEquals("test 4111111111111111 to ************111",
"************1111",
UtilFormatOut.formatPrintableCreditCard("4111111111111111"));
}

@Test
public void testFormatPrintableCreditCard_2() {
public void testFormatPrintableCreditCard2() {
assertEquals("test 4111 to 4111",
"4111",
UtilFormatOut.formatPrintableCreditCard("4111"));
}

@Test
public void testFormatPrintableCreditCard_3() {
public void testFormatPrintableCreditCard3() {
assertEquals("test null to null",
null,
UtilFormatOut.formatPrintableCreditCard(null));
}

@Test
public void testIsDouble_1() {
public void testIsDouble1() {
assertFalse(UtilValidate.isDouble("10.0", true, true, 2, 2));
}

@Test
public void testIsFloat_1() {
public void testIsFloat1() {
assertFalse(UtilValidate.isFloat("10.0", true, true, 2, 2));
}

@Test
public void testIsDouble_2() {
public void testIsDouble2() {
assertTrue(UtilValidate.isDouble("10.000", true, true, 3, 3));
}

@Test
public void testIsFloat_2() {
public void testIsFloat2() {
assertTrue(UtilValidate.isFloat("10.000", true, true, 3, 3));
}

@@ -5,9 +5,9 @@
* 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.
@@ -29,12 +29,12 @@
* Assert tests {@link org.apache.ofbiz.base.util.Assert}.
*/
public class AssertTests {
public static final String module = AssertTests.class.getName();
private static final String MODULE = AssertTests.class.getName();

@Test
public void testAssert(){
Object testObject = new Object();
private Object testObject = new Object();

@Test
public void testAssertNullOrEmpty() {
//-----------------------------------------------------------------------
try {
Assert.notNull("foo", testObject);
@@ -45,10 +45,9 @@ public void testAssert(){
Assert.notNull("foo", null);
fail("notNull - IllegalArgumentException not thrown");
} catch (IllegalArgumentException e) {
Debug.logError(e, module);
Debug.logError(e, MODULE);
}


//-----------------------------------------------------------------------
try {
Assert.notNull("foo", testObject, "bar", testObject);
@@ -59,10 +58,9 @@ public void testAssert(){
Assert.notNull("foo", testObject, "bar", null);
fail("notNull (argument list) - IllegalArgumentException not thrown");
} catch (IllegalArgumentException e) {
Debug.logError(e, module);
Debug.logError(e, MODULE);
}


//-----------------------------------------------------------------------
try {
Assert.notEmpty("foo", "foo");
@@ -73,10 +71,9 @@ public void testAssert(){
Assert.notEmpty("foo", "");
fail("notEmpty(String) - IllegalArgumentException not thrown");
} catch (IllegalArgumentException e) {
Debug.logError(e, module);
Debug.logError(e, MODULE);
}


//-----------------------------------------------------------------------
String[] strArray = {"foo", "bar"};
try {
@@ -88,17 +85,16 @@ public void testAssert(){
Assert.notEmpty("foo", new String[0]);
fail("notEmpty(Array) - IllegalArgumentException not thrown");
} catch (IllegalArgumentException e) {
Debug.logError(e, module);
Debug.logError(e, MODULE);
}


//-----------------------------------------------------------------------
List<String> strList = new ArrayList<>();
try {
Assert.notEmpty("foo", strList);
fail("notEmpty(Collection) - IllegalArgumentException not thrown");
} catch (IllegalArgumentException e) {
Debug.logError(e, module);
Debug.logError(e, MODULE);
}

strList.add("foo");
@@ -109,12 +105,12 @@ public void testAssert(){
}

//-----------------------------------------------------------------------
Map<String,String> strMap = new HashMap<>();
Map<String, String> strMap = new HashMap<>();
try {
Assert.notEmpty("foo", strMap);
fail("notEmpty(Map) - IllegalArgumentException not thrown");
} catch (IllegalArgumentException e) {
Debug.logError(e, module);
Debug.logError(e, MODULE);
}

strMap.put("foo", "foo");
@@ -123,7 +119,12 @@ public void testAssert(){
} catch (Exception e) {
fail("notEmpty(Map) threw an exception - " + e);
}
}

@Test
public void testAssertInstance() {
Map<String, String> strMap = new HashMap<>();
strMap.put("foo", "foo");
//-----------------------------------------------------------------------
try {
Assert.isInstanceOf("foo", strMap, Map.class);
@@ -134,10 +135,9 @@ public void testAssert(){
Assert.isInstanceOf("foo", strMap, AssertTests.class);
fail("isInstanceOf - IllegalArgumentException not thrown");
} catch (IllegalArgumentException e) {
Debug.logError(e, module);
Debug.logError(e, MODULE);
}


//-----------------------------------------------------------------------
try {
Assert.isInstanceOf("foo", strMap, String.class, Map.class);
@@ -148,10 +148,9 @@ public void testAssert(){
Assert.isInstanceOf("foo", strMap, String.class, AssertTests.class);
fail("isInstanceOf (argument list) - IllegalArgumentException not thrown");
} catch (IllegalArgumentException e) {
Debug.logError(e, module);
Debug.logError(e, MODULE);
}


//-----------------------------------------------------------------------
try {
Assert.isNotInstanceOf("foo", strMap, String.class);
@@ -162,10 +161,9 @@ public void testAssert(){
Assert.isNotInstanceOf("foo", strMap, Map.class);
fail("isNotInstanceOf - IllegalArgumentException not thrown");
} catch (IllegalArgumentException e) {
Debug.logError(e, module);
Debug.logError(e, MODULE);
}


//-----------------------------------------------------------------------
try {
Assert.isNotInstanceOf("foo", strMap, String.class, AssertTests.class);
@@ -176,10 +174,13 @@ public void testAssert(){
Assert.isNotInstanceOf("foo", strMap, String.class, Map.class);
fail("isNotInstanceOf (argument list) - IllegalArgumentException not thrown");
} catch (IllegalArgumentException e) {
Debug.logError(e, module);
Debug.logError(e, MODULE);
}
}


@Test
public void testAssertAssignable() {
String[] strArray = {"foo", "bar"};
//-----------------------------------------------------------------------
try {
Assert.isAssignableTo("foo", strArray, strArray.getClass());
@@ -190,8 +191,7 @@ public void testAssert(){
Assert.isAssignableTo("foo", strArray, Map[].class);
fail("isNotInstanceOf (argument list) - IllegalArgumentException not thrown");
} catch (IllegalArgumentException e) {
Debug.logError(e, module);
Debug.logError(e, MODULE);
}

}
}
@@ -23,7 +23,6 @@

import java.io.StringWriter;

import org.apache.ofbiz.base.util.IndentingWriter;
import org.junit.Test;

public class IndentingWriterTests {

0 comments on commit 59efa18

Please sign in to comment.
You can’t perform that action at this time.