diff options
Diffstat (limited to 'guava-tests/test/com/google/common/collect/ImmutableMapTest.java')
-rw-r--r-- | guava-tests/test/com/google/common/collect/ImmutableMapTest.java | 133 |
1 files changed, 44 insertions, 89 deletions
diff --git a/guava-tests/test/com/google/common/collect/ImmutableMapTest.java b/guava-tests/test/com/google/common/collect/ImmutableMapTest.java index 2708f39..4c04803 100644 --- a/guava-tests/test/com/google/common/collect/ImmutableMapTest.java +++ b/guava-tests/test/com/google/common/collect/ImmutableMapTest.java @@ -22,25 +22,23 @@ import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import com.google.common.base.Joiner; import com.google.common.collect.ImmutableMap.Builder; -import com.google.common.collect.testing.AnEnum; import com.google.common.collect.testing.CollectionTestSuiteBuilder; import com.google.common.collect.testing.ListTestSuiteBuilder; import com.google.common.collect.testing.MapInterfaceTest; -import com.google.common.collect.testing.MapTestSuiteBuilder; import com.google.common.collect.testing.MinimalSet; +import com.google.common.collect.testing.ReserializingTestCollectionGenerator; +import com.google.common.collect.testing.ReserializingTestSetGenerator; import com.google.common.collect.testing.SampleElements.Colliders; import com.google.common.collect.testing.SampleElements.Unhashables; +import com.google.common.collect.testing.SetTestSuiteBuilder; import com.google.common.collect.testing.UnhashableObject; import com.google.common.collect.testing.features.CollectionFeature; import com.google.common.collect.testing.features.CollectionSize; -import com.google.common.collect.testing.features.MapFeature; -import com.google.common.collect.testing.google.MapGenerators.ImmutableMapCopyOfEnumMapGenerator; -import com.google.common.collect.testing.google.MapGenerators.ImmutableMapEntryListGenerator; -import com.google.common.collect.testing.google.MapGenerators.ImmutableMapGenerator; -import com.google.common.collect.testing.google.MapGenerators.ImmutableMapKeyListGenerator; +import com.google.common.collect.testing.google.MapGenerators.ImmutableMapEntrySetGenerator; +import com.google.common.collect.testing.google.MapGenerators.ImmutableMapKeySetGenerator; import com.google.common.collect.testing.google.MapGenerators.ImmutableMapUnhashableValuesGenerator; import com.google.common.collect.testing.google.MapGenerators.ImmutableMapValueListGenerator; -import com.google.common.testing.EqualsTester; +import com.google.common.collect.testing.google.MapGenerators.ImmutableMapValuesGenerator; import com.google.common.testing.NullPointerTester; import com.google.common.testing.SerializableTester; @@ -51,7 +49,6 @@ import junit.framework.TestSuite; import java.io.Serializable; import java.util.Collection; import java.util.Collections; -import java.util.EnumMap; import java.util.LinkedHashMap; import java.util.Map; import java.util.Map.Entry; @@ -70,55 +67,72 @@ public class ImmutableMapTest extends TestCase { TestSuite suite = new TestSuite(); suite.addTestSuite(ImmutableMapTest.class); - suite.addTest(MapTestSuiteBuilder.using(new ImmutableMapGenerator()) + suite.addTest(SetTestSuiteBuilder.using(new ImmutableMapKeySetGenerator()) .withFeatures( CollectionSize.ANY, - CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS, CollectionFeature.KNOWN_ORDER, - MapFeature.REJECTS_DUPLICATES_AT_CREATION, + CollectionFeature.REJECTS_DUPLICATES_AT_CREATION, CollectionFeature.ALLOWS_NULL_QUERIES) - .named("ImmutableMap") + .named("ImmutableMap.keySet") .createTestSuite()); - suite.addTest(MapTestSuiteBuilder.using(new ImmutableMapCopyOfEnumMapGenerator()) + suite.addTest(SetTestSuiteBuilder.using(new ImmutableMapEntrySetGenerator()) .withFeatures( CollectionSize.ANY, - CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS, CollectionFeature.KNOWN_ORDER, + CollectionFeature.REJECTS_DUPLICATES_AT_CREATION, CollectionFeature.ALLOWS_NULL_QUERIES) - .named("ImmutableMap.copyOf[EnumMap]") + .named("ImmutableMap.entrySet") .createTestSuite()); suite.addTest(CollectionTestSuiteBuilder.using( - new ImmutableMapUnhashableValuesGenerator()) + new ImmutableMapValuesGenerator()) .withFeatures(CollectionSize.ANY, CollectionFeature.KNOWN_ORDER, CollectionFeature.ALLOWS_NULL_QUERIES) - .named("ImmutableMap.values, unhashable") + .named("ImmutableMap.values") .createTestSuite()); - suite.addTest(ListTestSuiteBuilder.using( - new ImmutableMapKeyListGenerator()) - .named("ImmutableMap.keySet.asList") - .withFeatures(CollectionSize.ANY, - CollectionFeature.SERIALIZABLE, + suite.addTest(SetTestSuiteBuilder.using( + ReserializingTestSetGenerator.newInstance( + new ImmutableMapKeySetGenerator())) + .withFeatures( + CollectionSize.ANY, + CollectionFeature.KNOWN_ORDER, CollectionFeature.REJECTS_DUPLICATES_AT_CREATION, CollectionFeature.ALLOWS_NULL_QUERIES) + .named("ImmutableMap.keySet, reserialized") .createTestSuite()); - suite.addTest(ListTestSuiteBuilder.using( - new ImmutableMapEntryListGenerator()) - .named("ImmutableMap.entrySet.asList") - .withFeatures(CollectionSize.ANY, - CollectionFeature.SERIALIZABLE, + suite.addTest(SetTestSuiteBuilder.using( + ReserializingTestSetGenerator.newInstance( + new ImmutableMapKeySetGenerator())) + .withFeatures( + CollectionSize.ANY, + CollectionFeature.KNOWN_ORDER, CollectionFeature.REJECTS_DUPLICATES_AT_CREATION, CollectionFeature.ALLOWS_NULL_QUERIES) + .named("ImmutableMap.entrySet, reserialized") + .createTestSuite()); + + suite.addTest(CollectionTestSuiteBuilder.using( + ReserializingTestCollectionGenerator.newInstance( + new ImmutableMapValuesGenerator())) + .withFeatures(CollectionSize.ANY, CollectionFeature.KNOWN_ORDER, + CollectionFeature.ALLOWS_NULL_QUERIES) + .named("ImmutableMap.values, reserialized") + .createTestSuite()); + + suite.addTest(CollectionTestSuiteBuilder.using( + new ImmutableMapUnhashableValuesGenerator()) + .withFeatures(CollectionSize.ANY, CollectionFeature.KNOWN_ORDER, + CollectionFeature.ALLOWS_NULL_QUERIES) + .named("ImmutableMap.values, unhashable") .createTestSuite()); suite.addTest(ListTestSuiteBuilder.using( new ImmutableMapValueListGenerator()) .named("ImmutableMap.values.asList") .withFeatures(CollectionSize.ANY, - CollectionFeature.SERIALIZABLE, CollectionFeature.ALLOWS_NULL_QUERIES) .createTestSuite()); @@ -508,29 +522,8 @@ public class ImmutableMapTest extends TestCase { assertNull(map.get(null)); } - public void testAsMultimap() { - ImmutableMap<String, Integer> map = ImmutableMap.of( - "one", 1, "won", 1, "two", 2, "too", 2, "three", 3); - ImmutableSetMultimap<String, Integer> expected = ImmutableSetMultimap.of( - "one", 1, "won", 1, "two", 2, "too", 2, "three", 3); - assertEquals(expected, map.asMultimap()); - } - - public void testAsMultimapWhenEmpty() { - ImmutableMap<String, Integer> map = ImmutableMap.of(); - ImmutableSetMultimap<String, Integer> expected = ImmutableSetMultimap.of(); - assertEquals(expected, map.asMultimap()); - } - - public void testAsMultimapCaches() { - ImmutableMap<String, Integer> map = ImmutableMap.of("one", 1); - ImmutableSetMultimap<String, Integer> multimap1 = map.asMultimap(); - ImmutableSetMultimap<String, Integer> multimap2 = map.asMultimap(); - assertSame(multimap1, multimap2); - } - @GwtIncompatible("NullPointerTester") - public void testNullPointers() { + public void testNullPointers() throws Exception { NullPointerTester tester = new NullPointerTester(); tester.testAllPublicStaticMethods(ImmutableMap.class); tester.testAllPublicInstanceMethods( @@ -581,13 +574,6 @@ public class ImmutableMapTest extends TestCase { assertEquals(intMap.hashCode(), map.hashCode()); } - public void testCopyOfEnumMap() { - EnumMap<AnEnum, String> map = new EnumMap<AnEnum, String>(AnEnum.class); - map.put(AnEnum.B, "foo"); - map.put(AnEnum.C, "bar"); - assertTrue(ImmutableMap.copyOf(map) instanceof ImmutableEnumMap); - } - @GwtIncompatible("SerializableTester") public void testViewSerialization() { Map<String, Integer> map = ImmutableMap.of("one", 1, "two", 2, "three", 3); @@ -599,35 +585,4 @@ public class ImmutableMapTest extends TestCase { Lists.newArrayList(reserializedValues)); assertTrue(reserializedValues instanceof ImmutableCollection); } - - public void testEquals() { - new EqualsTester() - .addEqualityGroup(ImmutableList.of(), ImmutableList.of()) - .addEqualityGroup(ImmutableList.of(1), ImmutableList.of(1)) - .addEqualityGroup(ImmutableList.of(1, 2), ImmutableList.of(1, 2)) - .addEqualityGroup(ImmutableList.of(1, 2, 3)) - .addEqualityGroup(ImmutableList.of(1, 2, 3, 4)) - .addEqualityGroup(ImmutableList.of(1, 2, 3, 4, 5)) - .addEqualityGroup(ImmutableList.of(1, 2, 3, 4, 5, 6)) - .addEqualityGroup(ImmutableList.of(1, 2, 3, 4, 5, 6, 7)) - .addEqualityGroup(ImmutableList.of(1, 2, 3, 4, 5, 6, 7, 8)) - .addEqualityGroup(ImmutableList.of(1, 2, 3, 4, 5, 6, 7, 8, 9)) - .addEqualityGroup(ImmutableList.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) - .addEqualityGroup(ImmutableList.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)) - .addEqualityGroup(ImmutableList.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)) - .addEqualityGroup(ImmutableList.of(100, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)) - .addEqualityGroup(ImmutableList.of(1, 200, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)) - .addEqualityGroup(ImmutableList.of(1, 2, 300, 4, 5, 6, 7, 8, 9, 10, 11, 12)) - .addEqualityGroup(ImmutableList.of(1, 2, 3, 400, 5, 6, 7, 8, 9, 10, 11, 12)) - .addEqualityGroup(ImmutableList.of(1, 2, 3, 4, 500, 6, 7, 8, 9, 10, 11, 12)) - .addEqualityGroup(ImmutableList.of(1, 2, 3, 4, 5, 600, 7, 8, 9, 10, 11, 12)) - .addEqualityGroup(ImmutableList.of(1, 2, 3, 4, 5, 6, 700, 8, 9, 10, 11, 12)) - .addEqualityGroup(ImmutableList.of(1, 2, 3, 4, 5, 6, 7, 800, 9, 10, 11, 12)) - .addEqualityGroup(ImmutableList.of(1, 2, 3, 4, 5, 6, 7, 8, 900, 10, 11, 12)) - .addEqualityGroup(ImmutableList.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 1000, 11, 12)) - .addEqualityGroup(ImmutableList.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1100, 12)) - .addEqualityGroup(ImmutableList.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 1200)) - .testEquals(); - - } } |