aboutsummaryrefslogtreecommitdiffstats
path: root/guava-tests/test/com/google/common/collect/ImmutableSetTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'guava-tests/test/com/google/common/collect/ImmutableSetTest.java')
-rw-r--r--guava-tests/test/com/google/common/collect/ImmutableSetTest.java103
1 files changed, 34 insertions, 69 deletions
diff --git a/guava-tests/test/com/google/common/collect/ImmutableSetTest.java b/guava-tests/test/com/google/common/collect/ImmutableSetTest.java
index dba83a5..6ed82ec 100644
--- a/guava-tests/test/com/google/common/collect/ImmutableSetTest.java
+++ b/guava-tests/test/com/google/common/collect/ImmutableSetTest.java
@@ -16,23 +16,13 @@
package com.google.common.collect;
-import static org.truth0.Truth.ASSERT;
+import static org.junit.contrib.truth.Truth.ASSERT;
import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.GwtIncompatible;
import com.google.common.collect.ImmutableSet.Builder;
-import com.google.common.collect.testing.ListTestSuiteBuilder;
-import com.google.common.collect.testing.SetTestSuiteBuilder;
-import com.google.common.collect.testing.features.CollectionFeature;
-import com.google.common.collect.testing.features.CollectionSize;
-import com.google.common.collect.testing.google.SetGenerators.DegeneratedImmutableSetGenerator;
-import com.google.common.collect.testing.google.SetGenerators.ImmutableSetAsListGenerator;
-import com.google.common.collect.testing.google.SetGenerators.ImmutableSetCopyOfGenerator;
-import com.google.common.collect.testing.google.SetGenerators.ImmutableSetWithBadHashesGenerator;
-import com.google.common.testing.EqualsTester;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
+import com.google.common.testing.NullPointerTester;
+import com.google.common.testing.SerializableTester;
import java.util.Collection;
import java.util.Collections;
@@ -49,44 +39,6 @@ import java.util.Set;
@GwtCompatible(emulated = true)
public class ImmutableSetTest extends AbstractImmutableSetTest {
- @GwtIncompatible("suite")
- public static Test suite() {
- TestSuite suite = new TestSuite();
-
- suite.addTest(SetTestSuiteBuilder.using(new ImmutableSetCopyOfGenerator())
- .named(ImmutableSetTest.class.getName())
- .withFeatures(CollectionSize.ANY, CollectionFeature.KNOWN_ORDER,
- CollectionFeature.SERIALIZABLE,
- CollectionFeature.ALLOWS_NULL_QUERIES)
- .createTestSuite());
-
- suite.addTest(SetTestSuiteBuilder.using(
- new ImmutableSetWithBadHashesGenerator())
- .named(ImmutableSetTest.class.getName() + ", with bad hashes")
- .withFeatures(CollectionSize.ANY, CollectionFeature.KNOWN_ORDER,
- CollectionFeature.ALLOWS_NULL_QUERIES)
- .createTestSuite());
-
- suite.addTest(SetTestSuiteBuilder.using(
- new DegeneratedImmutableSetGenerator())
- .named(ImmutableSetTest.class.getName() + ", degenerate")
- .withFeatures(CollectionSize.ONE, CollectionFeature.KNOWN_ORDER,
- CollectionFeature.ALLOWS_NULL_QUERIES)
- .createTestSuite());
-
- suite.addTest(ListTestSuiteBuilder.using(new ImmutableSetAsListGenerator())
- .named("ImmutableSet.asList")
- .withFeatures(CollectionSize.ANY,
- CollectionFeature.REJECTS_DUPLICATES_AT_CREATION,
- CollectionFeature.SERIALIZABLE,
- CollectionFeature.ALLOWS_NULL_QUERIES)
- .createTestSuite());
-
- suite.addTestSuite(ImmutableSetTest.class);
-
- return suite;
- }
-
@Override protected Set<String> of() {
return ImmutableSet.of();
}
@@ -153,7 +105,7 @@ public class ImmutableSetTest extends AbstractImmutableSetTest {
// now we'll get the varargs overload
ImmutableSet<String> set = ImmutableSet.of(
"a", "b", "c", "c", "c", "c", "b", "b", "a", "a", "c", "c", "c", "a");
- ASSERT.that(set).has().allOf("a", "b", "c").inOrder();
+ ASSERT.that(set).hasContentsInOrder("a", "b", "c");
}
public void testCreation_arrayOfArray() {
@@ -162,13 +114,19 @@ public class ImmutableSetTest extends AbstractImmutableSetTest {
assertEquals(Collections.singleton(array), set);
}
+ @GwtIncompatible("NullPointerTester")
+ public void testNullPointers() throws Exception {
+ NullPointerTester tester = new NullPointerTester();
+ tester.testAllPublicStaticMethods(ImmutableSet.class);
+ }
+
@GwtIncompatible("ImmutableSet.chooseTableSize")
public void testChooseTableSize() {
assertEquals(8, ImmutableSet.chooseTableSize(3));
- assertEquals(8, ImmutableSet.chooseTableSize(4));
+ assertEquals(16, ImmutableSet.chooseTableSize(4));
- assertEquals(1 << 29, ImmutableSet.chooseTableSize(1 << 28));
- assertEquals(1 << 29, ImmutableSet.chooseTableSize(1 << 29 - 1));
+ assertEquals(1 << 30, ImmutableSet.chooseTableSize(1 << 28));
+ assertEquals(1 << 30, ImmutableSet.chooseTableSize(1 << 29 - 1));
// Now we hit the cap
assertEquals(1 << 30, ImmutableSet.chooseTableSize(1 << 29));
@@ -184,12 +142,12 @@ public class ImmutableSetTest extends AbstractImmutableSetTest {
@GwtIncompatible("RegularImmutableSet.table not in emulation")
public void testResizeTable() {
- verifyTableSize(100, 2, 4);
- verifyTableSize(100, 5, 8);
- verifyTableSize(100, 33, 64);
- verifyTableSize(17, 17, 32);
- verifyTableSize(17, 16, 32);
- verifyTableSize(17, 15, 32);
+ verifyTableSize(100, 2, 8);
+ verifyTableSize(100, 5, 16);
+ verifyTableSize(100, 33, 256);
+ verifyTableSize(17, 17, 64);
+ verifyTableSize(17, 16, 64);
+ verifyTableSize(17, 15, 64);
}
@GwtIncompatible("RegularImmutableSet.table not in emulation")
@@ -215,6 +173,21 @@ public class ImmutableSetTest extends AbstractImmutableSetTest {
verifyThreadSafe();
}
+ public void testAsList() {
+ ImmutableSet<String> set = ImmutableSet.of("a", "b", "c", "d", "e");
+ ImmutableList<String> list = set.asList();
+ assertEquals(ImmutableList.of("a", "b", "c", "d", "e"), list);
+ }
+
+ @GwtIncompatible("SerializableTester, ImmutableAsList")
+ public void testAsListReturnTypeAndSerialization() {
+ ImmutableSet<String> set = ImmutableSet.of("a", "b", "c", "d", "e");
+ ImmutableList<String> list = set.asList();
+ assertTrue(list instanceof ImmutableAsList);
+ ImmutableList<String> copy = SerializableTester.reserializeAndAssert(list);
+ assertTrue(copy instanceof ImmutableAsList);
+ }
+
@Override <E extends Comparable<E>> Builder<E> builder() {
return ImmutableSet.builder();
}
@@ -222,12 +195,4 @@ public class ImmutableSetTest extends AbstractImmutableSetTest {
@Override int getComplexBuilderSetLastElement() {
return LAST_COLOR_ADDED;
}
-
- public void testEquals() {
- new EqualsTester()
- .addEqualityGroup(ImmutableSet.of(), ImmutableSet.of())
- .addEqualityGroup(ImmutableSet.of(1), ImmutableSet.of(1), ImmutableSet.of(1, 1))
- .addEqualityGroup(ImmutableSet.of(1, 2, 1), ImmutableSet.of(2, 1, 1))
- .testEquals();
- }
}