From 4033ff63c5533a1d1d30667c73c065cb2a3f7a0a Mon Sep 17 00:00:00 2001 From: aherbert Date: Mon, 17 Feb 2020 13:34:14 +0000 Subject: [PATCH] Test code clean-up. Make methods static if possible. Correct formatting of braces. --- .../bloomfilter/CountingBloomFilterTest.java | 100 +++++++----------- .../hasher/CommonComparatorTest.java | 4 +- .../hasher/DeepComparatorTest.java | 4 +- 3 files changed, 43 insertions(+), 65 deletions(-) diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/CountingBloomFilterTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/CountingBloomFilterTest.java index 11cdeee01..f6e95dc7e 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/CountingBloomFilterTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/CountingBloomFilterTest.java @@ -88,9 +88,8 @@ public class CountingBloomFilterTest extends AbstractBloomFilterTest { */ @Test public void ConstructorTest_Map_CountsTest() { - final Map map = new HashMap<>(); - for (int i =0;i<17;i++) - { + final Map map = new HashMap<>(); + for (int i = 0; i < 17; i++) { map.put(i, 1); } @@ -101,8 +100,7 @@ public class CountingBloomFilterTest extends AbstractBloomFilterTest { try { bf = new CountingBloomFilter(map, shape); fail("Should have thrown IllegalArgumentExceptionW"); - } catch (final IllegalArgumentException exprected) - { + } catch (final IllegalArgumentException exprected) { // expected } @@ -111,8 +109,7 @@ public class CountingBloomFilterTest extends AbstractBloomFilterTest { try { bf = new CountingBloomFilter(map, shape); fail("Should have thrown IllegalArgumentExceptionW"); - } catch (final IllegalArgumentException exprected) - { + } catch (final IllegalArgumentException exprected) { // expected } @@ -121,8 +118,7 @@ public class CountingBloomFilterTest extends AbstractBloomFilterTest { try { bf = new CountingBloomFilter(map, shape); fail("Should have thrown IllegalArgumentExceptionW"); - } catch (final IllegalArgumentException exprected) - { + } catch (final IllegalArgumentException exprected) { // expected } } @@ -152,7 +148,7 @@ public class CountingBloomFilterTest extends AbstractBloomFilterTest { final CountingBloomFilter bf = createFilter(hasher, shape); - final List lst2 = Arrays.asList(11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 ,26 ,27); + final List lst2 = Arrays.asList(11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27); final Hasher hasher2 = new StaticHasher(lst2.iterator(), shape); final BloomFilter bf2 = createFilter(hasher2, shape); @@ -164,14 +160,11 @@ public class CountingBloomFilterTest extends AbstractBloomFilterTest { final Map m = new HashMap<>(); bf.getCounts().forEach(e -> m.put(e.getKey(), e.getValue())); - for (int i=0;i<29;i++) - { - if (m.get(i) == null) - { - assertEquals("Wrong value for "+i, expected[i], 0); - } else - { - assertEquals("Wrong value for "+i, expected[i], m.get(i).intValue()); + for (int i = 0; i < 29; i++) { + if (m.get(i) == null) { + assertEquals("Wrong value for " + i, expected[i], 0); + } else { + assertEquals("Wrong value for " + i, expected[i], m.get(i).intValue()); } } } @@ -191,7 +184,7 @@ public class CountingBloomFilterTest extends AbstractBloomFilterTest { final CountingBloomFilter bf = createFilter(hasher, shape); - final List lst2 = Arrays.asList(11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 ,26 ,27); + final List lst2 = Arrays.asList(11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27); final Hasher hasher2 = new StaticHasher(lst2.iterator(), shape); final BloomFilter bf2 = new BitSetBloomFilter(hasher2, shape); @@ -203,14 +196,11 @@ public class CountingBloomFilterTest extends AbstractBloomFilterTest { final Map m = new HashMap<>(); bf.getCounts().forEach(e -> m.put(e.getKey(), e.getValue())); - for (int i=0;i<29;i++) - { - if (m.get(i) == null) - { - assertEquals("Wrong value for "+i, expected[i], 0); - } else - { - assertEquals("Wrong value for "+i, expected[i], m.get(i).intValue()); + for (int i = 0; i < 29; i++) { + if (m.get(i) == null) { + assertEquals("Wrong value for " + i, expected[i], 0); + } else { + assertEquals("Wrong value for " + i, expected[i], m.get(i).intValue()); } } } @@ -220,13 +210,12 @@ public class CountingBloomFilterTest extends AbstractBloomFilterTest { */ @Test public void mergeTest_Overflow() { - - final List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ,16 ,17); + final List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); final Hasher hasher = new StaticHasher(lst.iterator(), shape); CountingBloomFilter bf = createFilter(hasher, shape); - final Map map = new HashMap<>(); + final Map map = new HashMap<>(); bf.getCounts().forEach(e -> map.put(e.getKey(), e.getValue())); map.put(1, Integer.MAX_VALUE); @@ -242,9 +231,7 @@ public class CountingBloomFilterTest extends AbstractBloomFilterTest { try { bf.merge(bf2); fail("Should have thrown IllegalStateException"); - } - catch (final IllegalStateException expected) - { + } catch (final IllegalStateException expected) { // do nothing } } @@ -260,12 +247,12 @@ public class CountingBloomFilterTest extends AbstractBloomFilterTest { 1, 1, 1, 1, 1, 1, 1, 1, 0 }; - final List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ,16 ,17); + final List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); final Hasher hasher = new StaticHasher(lst.iterator(), shape); final CountingBloomFilter bf = createFilter(hasher, shape); - final List lst2 = Arrays.asList(11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 ,26 ,27); + final List lst2 = Arrays.asList(11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27); final Hasher hasher2 = new StaticHasher(lst2.iterator(), shape); bf.merge(hasher2); @@ -276,14 +263,11 @@ public class CountingBloomFilterTest extends AbstractBloomFilterTest { final Map m = new HashMap<>(); bf.getCounts().forEach(e -> m.put(e.getKey(), e.getValue())); - for (int i=0;i<29;i++) - { - if (m.get(i) == null) - { - assertEquals("Wrong value for "+i, expected[i], 0); - } else - { - assertEquals("Wrong value for "+i, expected[i], m.get(i).intValue()); + for (int i = 0; i < 29; i++) { + if (m.get(i) == null) { + assertEquals("Wrong value for " + i, expected[i], 0); + } else { + assertEquals("Wrong value for " + i, expected[i], m.get(i).intValue()); } } } @@ -306,17 +290,16 @@ public class CountingBloomFilterTest extends AbstractBloomFilterTest { final CountingBloomFilter bf = new CountingBloomFilter(map, shape); - final List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ,16 ,17); + final List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); final Hasher hasher = new StaticHasher(lst.iterator(), shape); final BloomFilter bf2 = new CountingBloomFilter(hasher, shape); bf.remove(bf2); assertEquals(17, bf.cardinality()); - final Map map2 = new HashMap<>(); + final Map map2 = new HashMap<>(); bf.getCounts().forEach(e -> map2.put(e.getKey(), e.getValue())); - for (int i = 11; i lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ,16 ,17); + final List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); final Hasher hasher = new StaticHasher(lst.iterator(), shape); bf.remove(hasher); assertEquals(17, bf.cardinality()); - final Map map2 = new HashMap<>(); + final Map map2 = new HashMap<>(); bf.getCounts().forEach(e -> map2.put(e.getKey(), e.getValue())); - for (int i = 11; i lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ,16 ,17); + final List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); final Hasher hasher = new StaticHasher(lst.iterator(), shape); final BitSetBloomFilter bf2 = new BitSetBloomFilter(hasher, shape); bf.remove(bf2); assertEquals(17, bf.cardinality()); - final Map map2 = new HashMap<>(); + final Map map2 = new HashMap<>(); bf.getCounts().forEach(e -> map2.put(e.getKey(), e.getValue())); - for (int i = 11; i lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ,16 ,17); + final List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); final Hasher hasher = new StaticHasher(lst.iterator(), shape); CountingBloomFilter bf = createFilter(hasher, shape); - final Map map = new HashMap<>(); + final Map map = new HashMap<>(); bf.getCounts().forEach(e -> map.put(e.getKey(), e.getValue())); map.remove(1); @@ -416,9 +396,7 @@ public class CountingBloomFilterTest extends AbstractBloomFilterTest { try { bf.remove(bf2); fail("Should have thrown IllegalStateException"); - } - catch (final IllegalStateException expected) - { + } catch (final IllegalStateException expected) { // do nothing } } diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/CommonComparatorTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/CommonComparatorTest.java index 183bc02cb..0ab7e7094 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/CommonComparatorTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/CommonComparatorTest.java @@ -35,11 +35,11 @@ import org.junit.Test; */ public class CommonComparatorTest { - private void assertAfter(final HashFunctionIdentity identity1, final HashFunctionIdentity identity2) { + private static void assertAfter(final HashFunctionIdentity identity1, final HashFunctionIdentity identity2) { assertTrue(0 < HashFunctionIdentity.COMMON_COMPARATOR.compare(identity1, identity2)); } - private void assertBefore(final HashFunctionIdentity identity1, final HashFunctionIdentity identity2) { + private static void assertBefore(final HashFunctionIdentity identity1, final HashFunctionIdentity identity2) { assertTrue(0 > HashFunctionIdentity.COMMON_COMPARATOR.compare(identity1, identity2)); } diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/DeepComparatorTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/DeepComparatorTest.java index b456930c2..934dacf68 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/DeepComparatorTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/DeepComparatorTest.java @@ -35,11 +35,11 @@ import org.junit.Test; */ public class DeepComparatorTest { - private void assertAfter(final HashFunctionIdentity identity1, final HashFunctionIdentity identity2) { + private static void assertAfter(final HashFunctionIdentity identity1, final HashFunctionIdentity identity2) { assertTrue(0 < HashFunctionIdentity.DEEP_COMPARATOR.compare(identity1, identity2)); } - private void assertBefore(final HashFunctionIdentity identity1, final HashFunctionIdentity identity2) { + private static void assertBefore(final HashFunctionIdentity identity1, final HashFunctionIdentity identity2) { assertTrue(0 > HashFunctionIdentity.DEEP_COMPARATOR.compare(identity1, identity2)); }