Author: mbrohl
Date: Sun Dec 17 19:00:31 2017 New Revision: 1818505 URL: http://svn.apache.org/viewvc?rev=1818505&view=rev Log: Improved: General refactoring and code improvements, package org.apache.ofbiz.base.test. (OFBIZ-9938) Thanks Dennis Balkir for reporting and providing the patch. Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/test/GenericTestCaseBase.java Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/test/GenericTestCaseBase.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/test/GenericTestCaseBase.java?rev=1818505&r1=1818504&r2=1818505&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/test/GenericTestCaseBase.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/test/GenericTestCaseBase.java Sun Dec 17 19:00:31 2017 @@ -123,7 +123,9 @@ public abstract class GenericTestCaseBas 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 GenericTestCaseBas 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()); |
Free forum by Nabble | Edit this page |