From a9cd441fc38c6f626e78259b402e6d0170019d53 Mon Sep 17 00:00:00 2001 From: Michael Brohl Date: Sun, 17 Dec 2017 19:00:31 +0000 Subject: [PATCH] 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 --- .../ofbiz/base/test/GenericTestCaseBase.java | 48 ++++++++++++++----- 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/test/GenericTestCaseBase.java b/framework/base/src/main/java/org/apache/ofbiz/base/test/GenericTestCaseBase.java index eeab3ec106..f55a3667fb 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/test/GenericTestCaseBase.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/test/GenericTestCaseBase.java @@ -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 leftIt = wanted.iterator(); Iterator rightIt = ((Collection) got).iterator(); int i = 0; @@ -144,14 +146,24 @@ public abstract class GenericTestCaseBase extends TestCase { public static void assertEquals(String msg, Collection 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 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 void assertEquals(Set wanted, Object got) { @@ -181,11 +195,17 @@ OUTER: } public static void assertEquals(String msg, Set 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 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 void assertEqualsArrayArray(String msg, Object wanted, Object got) { @@ -296,7 +318,9 @@ OUTER: public static void assertEquals(String msg, Map 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 leftKeys = new LinkedHashSet<>(wanted.keySet());