aboutsummaryrefslogtreecommitdiff
path: root/guava-tests/test/com/google/common/hash/BloomFilterTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'guava-tests/test/com/google/common/hash/BloomFilterTest.java')
-rw-r--r--guava-tests/test/com/google/common/hash/BloomFilterTest.java119
1 files changed, 49 insertions, 70 deletions
diff --git a/guava-tests/test/com/google/common/hash/BloomFilterTest.java b/guava-tests/test/com/google/common/hash/BloomFilterTest.java
index 95306661d..dd9a776d2 100644
--- a/guava-tests/test/com/google/common/hash/BloomFilterTest.java
+++ b/guava-tests/test/com/google/common/hash/BloomFilterTest.java
@@ -18,6 +18,7 @@ package com.google.common.hash;
import static com.google.common.base.Charsets.UTF_8;
import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.assertThrows;
import com.google.common.base.Stopwatch;
import com.google.common.collect.ImmutableSet;
@@ -36,7 +37,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.TimeUnit;
-import java.util.stream.Stream;
import junit.framework.TestCase;
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -222,38 +222,31 @@ public class BloomFilterTest extends TestCase {
}
public void testPreconditions() {
- try {
- BloomFilter.create(Funnels.unencodedCharsFunnel(), -1);
- fail();
- } catch (IllegalArgumentException expected) {
- }
- try {
- BloomFilter.create(Funnels.unencodedCharsFunnel(), -1, 0.03);
- fail();
- } catch (IllegalArgumentException expected) {
- }
- try {
- BloomFilter.create(Funnels.unencodedCharsFunnel(), 1, 0.0);
- fail();
- } catch (IllegalArgumentException expected) {
- }
- try {
- BloomFilter.create(Funnels.unencodedCharsFunnel(), 1, 1.0);
- fail();
- } catch (IllegalArgumentException expected) {
- }
+ assertThrows(
+ IllegalArgumentException.class,
+ () -> BloomFilter.create(Funnels.unencodedCharsFunnel(), -1));
+ assertThrows(
+ IllegalArgumentException.class,
+ () -> BloomFilter.create(Funnels.unencodedCharsFunnel(), -1, 0.03));
+ assertThrows(
+ IllegalArgumentException.class,
+ () -> BloomFilter.create(Funnels.unencodedCharsFunnel(), 1, 0.0));
+ assertThrows(
+ IllegalArgumentException.class,
+ () -> BloomFilter.create(Funnels.unencodedCharsFunnel(), 1, 1.0));
}
public void testFailureWhenMoreThan255HashFunctionsAreNeeded() {
- try {
- int n = 1000;
- double p = 0.00000000000000000000000000000000000000000000000000000000000000000000000000000001;
- BloomFilter.create(Funnels.unencodedCharsFunnel(), n, p);
- fail();
- } catch (IllegalArgumentException expected) {
- }
+ int n = 1000;
+ double p = 0.00000000000000000000000000000000000000000000000000000000000000000000000000000001;
+ assertThrows(
+ IllegalArgumentException.class,
+ () -> {
+ BloomFilter.create(Funnels.unencodedCharsFunnel(), n, p);
+ });
}
+ @AndroidIncompatible // see ImmutableTableTest.testNullPointerInstance
public void testNullPointers() {
NullPointerTester tester = new NullPointerTester();
tester.testAllPublicInstanceMethods(BloomFilter.create(Funnels.unencodedCharsFunnel(), 100));
@@ -290,15 +283,16 @@ public class BloomFilterTest extends TestCase {
// and some crazy values (this used to be capped to Integer.MAX_VALUE, now it can go bigger
assertEquals(3327428144502L, BloomFilter.optimalNumOfBits(Integer.MAX_VALUE, Double.MIN_VALUE));
- try {
- BloomFilter<String> unused =
- BloomFilter.create(HashTestUtils.BAD_FUNNEL, Integer.MAX_VALUE, Double.MIN_VALUE);
- fail("we can't represent such a large BF!");
- } catch (IllegalArgumentException expected) {
- assertThat(expected)
- .hasMessageThat()
- .isEqualTo("Could not create BloomFilter of 3327428144502 bits");
- }
+ IllegalArgumentException expected =
+ assertThrows(
+ IllegalArgumentException.class,
+ () -> {
+ BloomFilter<String> unused =
+ BloomFilter.create(HashTestUtils.BAD_FUNNEL, Integer.MAX_VALUE, Double.MIN_VALUE);
+ });
+ assertThat(expected)
+ .hasMessageThat()
+ .isEqualTo("Could not create BloomFilter of 3327428144502 bits");
}
@AndroidIncompatible // OutOfMemoryError
@@ -376,21 +370,6 @@ public class BloomFilterTest extends TestCase {
.testEquals();
}
- public void testCollector() {
- BloomFilter<String> bf1 = BloomFilter.create(Funnels.unencodedCharsFunnel(), 100);
- bf1.put("1");
- bf1.put("2");
-
- assertEquals(
- bf1,
- Stream.of("1", "2")
- .collect(BloomFilter.toBloomFilter(Funnels.unencodedCharsFunnel(), 100)));
- assertEquals(
- bf1,
- Stream.of("2", "1")
- .collect(BloomFilter.toBloomFilter(Funnels.unencodedCharsFunnel(), 100)));
- }
-
public void testEquals() {
BloomFilter<String> bf1 = BloomFilter.create(Funnels.unencodedCharsFunnel(), 100);
bf1.put("1");
@@ -472,29 +451,29 @@ public class BloomFilterTest extends TestCase {
BloomFilter<Integer> bf1 = BloomFilter.create(Funnels.integerFunnel(), 1);
BloomFilter<Integer> bf2 = BloomFilter.create(Funnels.integerFunnel(), 10);
- try {
- assertFalse(bf1.isCompatible(bf2));
- bf1.putAll(bf2);
- fail();
- } catch (IllegalArgumentException expected) {
- }
+ assertFalse(bf1.isCompatible(bf2));
+ assertThrows(
+ IllegalArgumentException.class,
+ () -> {
+ bf1.putAll(bf2);
+ });
- try {
- assertFalse(bf2.isCompatible(bf1));
- bf2.putAll(bf1);
- fail();
- } catch (IllegalArgumentException expected) {
- }
+ assertFalse(bf2.isCompatible(bf1));
+ assertThrows(
+ IllegalArgumentException.class,
+ () -> {
+ bf2.putAll(bf1);
+ });
}
public void testPutAllWithSelf() {
BloomFilter<Integer> bf1 = BloomFilter.create(Funnels.integerFunnel(), 1);
- try {
- assertFalse(bf1.isCompatible(bf1));
- bf1.putAll(bf1);
- fail();
- } catch (IllegalArgumentException expected) {
- }
+ assertFalse(bf1.isCompatible(bf1));
+ assertThrows(
+ IllegalArgumentException.class,
+ () -> {
+ bf1.putAll(bf1);
+ });
}
public void testJavaSerialization() {