Improved: General refactoring and code improvements, package

org.apache.ofbiz.base.test.
(OFBIZ-9938)

Thanks Dennis Balkir for reporting and providing the patch.

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1818505 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Brohl
2017-12-17 19:00:31 +00:00
parent 90b6706b2c
commit a9cd441fc3
@@ -123,7 +123,9 @@ public abstract class GenericTestCaseBase extends TestCase {
assertEqualsListArray(msg, wanted, got);
return;
}
if (!(got instanceof Collection<?>)) fail(msg + "expected a collection, got a " + got.getClass());
if (!(got instanceof Collection<?>)) {
fail(msg + "expected a collection, got a " + got.getClass());
}
Iterator<T> leftIt = wanted.iterator();
Iterator<?> rightIt = ((Collection<?>) got).iterator();
int i = 0;
@@ -144,14 +146,24 @@ public abstract class GenericTestCaseBase extends TestCase {
public static <T> void assertEquals(String msg, Collection<T> wanted, Object got) {
if (wanted instanceof List<?> || wanted instanceof Set<?>) {
// list.equals(list) and set.equals(set), see docs for Collection.equals
if (got instanceof Set<?>) fail("Not a collection, is a set");
if (got instanceof List<?>) fail("Not a collection, is a list");
if (got instanceof Set<?>) {
fail("Not a collection, is a set");
}
if (got instanceof List<?>) {
fail("Not a collection, is a list");
}
}
if (wanted.equals(got)) {
return;
}
if (!(got instanceof Collection<?>)) {
fail(msg + "not a collection");
}
if (wanted.equals(got)) return;
if (!(got instanceof Collection<?>)) fail(msg + "not a collection");
// Need to check the reverse, wanted may not implement equals,
// which is the case for HashMap.values()
if (got.equals(wanted)) return;
if (got.equals(wanted)) {
return;
}
msg = msg == null ? "" : msg + ' ';
assertNotNull(msg + "expected a value", got);
List<T> list = new ArrayList<>(wanted);
@@ -173,7 +185,9 @@ OUTER:
}
fail(msg + "couldn't find " + right);
}
if (!list.isEmpty()) fail(msg + "not enough items: " + list);
if (!list.isEmpty()) {
fail(msg + "not enough items: " + list);
}
}
public static <T> void assertEquals(Set<T> wanted, Object got) {
@@ -181,11 +195,17 @@ OUTER:
}
public static <T> void assertEquals(String msg, Set<T> wanted, Object got) {
if (wanted.equals(got)) return;
if (!(got instanceof Set<?>)) fail(msg + "not a set");
if (wanted.equals(got)) {
return;
}
if (!(got instanceof Set<?>)) {
fail(msg + "not a set");
}
// Need to check the reverse, wanted may not implement equals,
// which is the case for HashMap.values()
if (got.equals(wanted)) return;
if (got.equals(wanted)) {
return;
}
msg = msg == null ? "" : msg + ' ';
assertNotNull(msg + "expected a value", got);
Set<T> wantedSet = new HashSet<>(wanted);
@@ -198,7 +218,9 @@ OUTER:
fail(msg + "couldn't find " + right);
}
}
if (!wantedSet.isEmpty()) fail(msg + "not enough items: " + wantedSet);
if (!wantedSet.isEmpty()) {
fail(msg + "not enough items: " + wantedSet);
}
}
private static <T> void assertEqualsArrayArray(String msg, Object wanted, Object got) {
@@ -296,7 +318,9 @@ OUTER:
public static <T> void assertEquals(String msg, Map<T, ?> wanted, Object got) {
msg = msg == null ? "" : msg + ' ';
assertNotNull(msg + "expected a value", got);
if (!(got instanceof Map<?, ?>)) fail(msg + "expected a map");
if (!(got instanceof Map<?, ?>)) {
fail(msg + "expected a map");
}
Map<?, ?> gotMap = (Map<?, ?>) got;
if (!got.equals(wanted)) {
Set<T> leftKeys = new LinkedHashSet<>(wanted.keySet());