diff options
Diffstat (limited to 'guava-tests/test/com/google/common/collect/EnumBiMapTest.java')
-rw-r--r-- | guava-tests/test/com/google/common/collect/EnumBiMapTest.java | 166 |
1 files changed, 13 insertions, 153 deletions
diff --git a/guava-tests/test/com/google/common/collect/EnumBiMapTest.java b/guava-tests/test/com/google/common/collect/EnumBiMapTest.java index c972606..c592f79 100644 --- a/guava-tests/test/com/google/common/collect/EnumBiMapTest.java +++ b/guava-tests/test/com/google/common/collect/EnumBiMapTest.java @@ -16,31 +16,16 @@ package com.google.common.collect; -import static com.google.common.collect.testing.Helpers.orderEntriesByKey; -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.testing.Helpers; -import com.google.common.collect.testing.SampleElements; -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.BiMapTestSuiteBuilder; -import com.google.common.collect.testing.google.TestBiMapGenerator; -import com.google.common.testing.EqualsTester; -import com.google.common.testing.NullPointerTester; import com.google.common.testing.SerializableTester; -import junit.framework.Test; import junit.framework.TestCase; -import junit.framework.TestSuite; import java.util.Collections; -import java.util.Iterator; -import java.util.List; import java.util.Map; -import java.util.Map.Entry; import java.util.Set; /** @@ -51,66 +36,8 @@ import java.util.Set; */ @GwtCompatible(emulated = true) public class EnumBiMapTest extends TestCase { - private enum Currency { DOLLAR, FRANC, PESO, POUND, YEN } - private enum Country { CANADA, CHILE, JAPAN, SWITZERLAND, UK } - - public static final class EnumBiMapGenerator implements TestBiMapGenerator<Country, Currency> { - @SuppressWarnings("unchecked") - @Override - public BiMap<Country, Currency> create(Object... entries) { - BiMap<Country, Currency> result = EnumBiMap.create(Country.class, Currency.class); - for (Object object : entries) { - Entry<Country, Currency> entry = (Entry<Country, Currency>) object; - result.put(entry.getKey(), entry.getValue()); - } - return result; - } - - @Override - public SampleElements<Entry<Country, Currency>> samples() { - return new SampleElements<Entry<Country, Currency>>( - Helpers.mapEntry(Country.CANADA, Currency.DOLLAR), - Helpers.mapEntry(Country.CHILE, Currency.PESO), - Helpers.mapEntry(Country.UK, Currency.POUND), - Helpers.mapEntry(Country.JAPAN, Currency.YEN), - Helpers.mapEntry(Country.SWITZERLAND, Currency.FRANC)); - } - - @SuppressWarnings("unchecked") - @Override - public Entry<Country, Currency>[] createArray(int length) { - return new Entry[length]; - } - - @Override - public Iterable<Entry<Country, Currency>> order(List<Entry<Country, Currency>> insertionOrder) { - return orderEntriesByKey(insertionOrder); - } - - @Override - public Country[] createKeyArray(int length) { - return new Country[length]; - } - - @Override - public Currency[] createValueArray(int length) { - return new Currency[length]; - } - } - - @GwtIncompatible("suite") - public static Test suite() { - TestSuite suite = new TestSuite(); - suite.addTest(BiMapTestSuiteBuilder.using(new EnumBiMapGenerator()) - .named("EnumBiMap") - .withFeatures(CollectionSize.ANY, - CollectionFeature.SERIALIZABLE, - MapFeature.GENERAL_PURPOSE, - CollectionFeature.KNOWN_ORDER) - .createTestSuite()); - suite.addTestSuite(EnumBiMapTest.class); - return suite; - } + private enum Currency { DOLLAR, FRANC, PESO } + private enum Country { CANADA, CHILE, SWITZERLAND } public void testCreate() { EnumBiMap<Currency, Country> bimap = @@ -185,57 +112,20 @@ public class EnumBiMapTest extends TestCase { assertEquals(Country.class, bimap.valueType()); } - public void testIterationOrder() { - // The enum orderings are alphabetical, leading to the bimap and its inverse - // having inconsistent iteration orderings. + @GwtIncompatible("SerializationTester") + public void testSerialization() { Map<Currency, Country> map = ImmutableMap.of( Currency.DOLLAR, Country.CANADA, Currency.PESO, Country.CHILE, Currency.FRANC, Country.SWITZERLAND); EnumBiMap<Currency, Country> bimap = EnumBiMap.create(map); - // forward map ordered by currency - ASSERT.that(bimap.keySet()) - .has().allOf(Currency.DOLLAR, Currency.FRANC, Currency.PESO).inOrder(); - // forward map ordered by currency (even for country values) - ASSERT.that(bimap.values()) - .has().allOf(Country.CANADA, Country.SWITZERLAND, Country.CHILE).inOrder(); - // backward map ordered by country - ASSERT.that(bimap.inverse().keySet()) - .has().allOf(Country.CANADA, Country.CHILE, Country.SWITZERLAND).inOrder(); - // backward map ordered by country (even for currency values) - ASSERT.that(bimap.inverse().values()) - .has().allOf(Currency.DOLLAR, Currency.PESO, Currency.FRANC).inOrder(); + BiMap<Currency, Country> copy = + SerializableTester.reserializeAndAssert(bimap); + assertEquals(bimap.inverse(), copy.inverse()); } - public void testKeySetIteratorRemove() { - // The enum orderings are alphabetical, leading to the bimap and its inverse - // having inconsistent iteration orderings. - Map<Currency, Country> map = ImmutableMap.of( - Currency.DOLLAR, Country.CANADA, - Currency.PESO, Country.CHILE, - Currency.FRANC, Country.SWITZERLAND); - EnumBiMap<Currency, Country> bimap = EnumBiMap.create(map); - - Iterator<Currency> iter = bimap.keySet().iterator(); - assertEquals(Currency.DOLLAR, iter.next()); - iter.remove(); - - // forward map ordered by currency - ASSERT.that(bimap.keySet()) - .has().allOf(Currency.FRANC, Currency.PESO).inOrder(); - // forward map ordered by currency (even for country values) - ASSERT.that(bimap.values()) - .has().allOf(Country.SWITZERLAND, Country.CHILE).inOrder(); - // backward map ordered by country - ASSERT.that(bimap.inverse().keySet()) - .has().allOf(Country.CHILE, Country.SWITZERLAND).inOrder(); - // backward map ordered by country (even for currency values) - ASSERT.that(bimap.inverse().values()) - .has().allOf(Currency.PESO, Currency.FRANC).inOrder(); - } - - public void testValuesIteratorRemove() { + public void testIterationOrder() { // The enum orderings are alphabetical, leading to the bimap and its inverse // having inconsistent iteration orderings. Map<Currency, Country> map = ImmutableMap.of( @@ -244,27 +134,21 @@ public class EnumBiMapTest extends TestCase { Currency.FRANC, Country.SWITZERLAND); EnumBiMap<Currency, Country> bimap = EnumBiMap.create(map); - Iterator<Currency> iter = bimap.keySet().iterator(); - assertEquals(Currency.DOLLAR, iter.next()); - assertEquals(Currency.FRANC, iter.next()); - iter.remove(); - // forward map ordered by currency ASSERT.that(bimap.keySet()) - .has().allOf(Currency.DOLLAR, Currency.PESO).inOrder(); + .hasContentsInOrder(Currency.DOLLAR, Currency.FRANC, Currency.PESO); // forward map ordered by currency (even for country values) ASSERT.that(bimap.values()) - .has().allOf(Country.CANADA, Country.CHILE).inOrder(); + .hasContentsInOrder(Country.CANADA, Country.SWITZERLAND, Country.CHILE); // backward map ordered by country ASSERT.that(bimap.inverse().keySet()) - .has().allOf(Country.CANADA, Country.CHILE).inOrder(); + .hasContentsInOrder(Country.CANADA, Country.CHILE, Country.SWITZERLAND); // backward map ordered by country (even for currency values) ASSERT.that(bimap.inverse().values()) - .has().allOf(Currency.DOLLAR, Currency.PESO).inOrder(); + .hasContentsInOrder(Currency.DOLLAR, Currency.PESO, Currency.FRANC); } public void testEntrySet() { - // Bug 3168290 Map<Currency, Country> map = ImmutableMap.of( Currency.DOLLAR, Country.CANADA, Currency.PESO, Country.CHILE, @@ -275,29 +159,5 @@ public class EnumBiMapTest extends TestCase { assertEquals(3, uniqueEntries.size()); } - @GwtIncompatible("serialization") - public void testSerializable() { - SerializableTester.reserializeAndAssert( - EnumBiMap.create(ImmutableMap.of(Currency.DOLLAR, Country.CANADA))); - } - - @GwtIncompatible("reflection") - public void testNulls() { - new NullPointerTester().testAllPublicStaticMethods(EnumBiMap.class); - new NullPointerTester() - .testAllPublicInstanceMethods( - EnumBiMap.create(ImmutableMap.of(Currency.DOLLAR, Country.CHILE))); - } - - public void testEquals() { - new EqualsTester() - .addEqualityGroup( - EnumBiMap.create(ImmutableMap.of(Currency.DOLLAR, Country.CANADA)), - EnumBiMap.create(ImmutableMap.of(Currency.DOLLAR, Country.CANADA))) - .addEqualityGroup(EnumBiMap.create(ImmutableMap.of(Currency.DOLLAR, Country.CHILE))) - .addEqualityGroup(EnumBiMap.create(ImmutableMap.of(Currency.FRANC, Country.CANADA))) - .testEquals(); - } - /* Remaining behavior tested by AbstractBiMapTest. */ } |