Improved: Fixing defects reported by FindBugs, package
org.apache.ofbiz.base.test.
Thanks Dennis Balkir for reporting and providing the patch.
@@ -44,7 +44,7 @@ public abstract class GenericTestCaseBase extends TestCase {
}
public static void useAllMemory() throws Exception {
- List<long[]> dummy = new LinkedList<long[]>();
+ List<long[]> dummy = new LinkedList<>();
try {
do {
dummy.add(new long[1048576]);
@@ -154,7 +154,7 @@ public abstract class GenericTestCaseBase extends TestCase {
if (got.equals(wanted)) return;
msg = msg == null ? "" : msg + ' ';
assertNotNull(msg + "expected a value", got);
- List<T> list = new ArrayList<T>(wanted);
+ List<T> list = new ArrayList<>(wanted);
Iterator<?> rightIt = ((Collection<?>) got).iterator();
OUTER:
while (rightIt.hasNext()) {
@@ -188,7 +188,7 @@ OUTER:
if (got.equals(wanted)) return;
msg = msg == null ? "" : msg + ' ';
assertNotNull(msg + "expected a value", got);
- Set<T> wantedSet = new HashSet<T>(wanted);
+ Set<T> wantedSet = new HashSet<>(wanted);
Iterator<?> rightIt = ((Set<?>) got).iterator();
while (rightIt.hasNext()) {
Object right = rightIt.next();
@@ -299,8 +299,8 @@ OUTER:
if (!(got instanceof Map<?, ?>)) fail(msg + "expected a map");
Map<?, ?> gotMap = (Map<?, ?>) got;
if (!got.equals(wanted)) {
- Set<T> leftKeys = new LinkedHashSet<T>(wanted.keySet());
- Set<Object> rightKeys = new HashSet<Object>(gotMap.keySet());
+ Set<T> leftKeys = new LinkedHashSet<>(wanted.keySet());
+ Set<Object> rightKeys = new HashSet<>(gotMap.keySet());
for (T key: leftKeys) {
assertTrue(msg + "got key(" + key + ")", rightKeys.remove(key));
assertEquals(msg + "key(" + key + ") value", wanted.get(key), gotMap.get(key));
@@ -345,23 +345,23 @@ OUTER:
}
public static <T> List<T> list(T value) {
- List<T> list = new ArrayList<T>(1);
+ List<T> list = new ArrayList<>(1);
list.add(value);
return list;
}
public static <T> List<T> list(T... list) {
- return new ArrayList<T>(Arrays.asList(list));
+ return new ArrayList<>(Arrays.asList(list));
}
public static <T> Set<T> set(T value) {
- Set<T> set = new HashSet<T>(1);
+ Set<T> set = new HashSet<>(1);
set.add(value);
return set;
}
public static <T> Set<T> set(T... list) {
- return new HashSet<T>(Arrays.asList(list));
+ return new HashSet<>(Arrays.asList(list));
}
public static <T> Set<T> set(Iterable<T> iterable) {
@@ -369,7 +369,7 @@ OUTER:
}
public static <T> Set<T> set(Iterator<T> it) {
- Set<T> set = new HashSet<T>();
+ Set<T> set = new HashSet<>();
while (it.hasNext()) {
T item = it.next();
set.add(item);
@@ -380,7 +380,7 @@ OUTER:
@SuppressWarnings("unchecked")
public static <K, V> Map<K, V> map(Object... list) {
assertEquals("list has even number of elements", 0, list.length % 2);
- Map<K, V> map = new LinkedHashMap<K, V>();
+ Map<K, V> map = new LinkedHashMap<>();
for (int i = 0; i < list.length; i += 2) {
map.put((K) list[i], (V) list[i + 1]);
}
