diff options
Diffstat (limited to 'guava-tests/test/com/google/common/collect/SynchronizedBiMapTest.java')
-rw-r--r-- | guava-tests/test/com/google/common/collect/SynchronizedBiMapTest.java | 78 |
1 files changed, 23 insertions, 55 deletions
diff --git a/guava-tests/test/com/google/common/collect/SynchronizedBiMapTest.java b/guava-tests/test/com/google/common/collect/SynchronizedBiMapTest.java index b0efcf0..7e99f71 100644 --- a/guava-tests/test/com/google/common/collect/SynchronizedBiMapTest.java +++ b/guava-tests/test/com/google/common/collect/SynchronizedBiMapTest.java @@ -16,20 +16,11 @@ package com.google.common.collect; -import static com.google.common.base.Preconditions.checkArgument; - import com.google.common.collect.Synchronized.SynchronizedBiMap; import com.google.common.collect.Synchronized.SynchronizedSet; -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.BiMapInverseTester; -import com.google.common.collect.testing.google.BiMapTestSuiteBuilder; -import com.google.common.collect.testing.google.TestStringBiMapGenerator; import junit.framework.TestSuite; -import java.util.Map.Entry; import java.util.Set; /** @@ -41,24 +32,7 @@ public class SynchronizedBiMapTest extends SynchronizedMapTest { public static TestSuite suite() { TestSuite suite = new TestSuite(SynchronizedBiMapTest.class); - suite.addTest(BiMapTestSuiteBuilder.using(new SynchTestingBiMapGenerator()) - .named("Synchronized.biMap[TestBiMap]") - .withFeatures(CollectionSize.ANY, - MapFeature.ALLOWS_NULL_KEYS, - MapFeature.ALLOWS_NULL_VALUES, - MapFeature.GENERAL_PURPOSE, - MapFeature.REJECTS_DUPLICATES_AT_CREATION) - .createTestSuite()); - suite.addTest(BiMapTestSuiteBuilder.using(new SynchronizedHashBiMapGenerator()) - .named("synchronizedBiMap[HashBiMap]") - .withFeatures(CollectionSize.ANY, - MapFeature.ALLOWS_NULL_KEYS, - MapFeature.ALLOWS_NULL_VALUES, - MapFeature.GENERAL_PURPOSE, - MapFeature.REJECTS_DUPLICATES_AT_CREATION, - CollectionFeature.SERIALIZABLE) - .suppressing(BiMapInverseTester.getInverseSameAfterSerializingMethods()) - .createTestSuite()); + suite.addTestSuite(AbstractBiMapTests.class); return suite; } @@ -69,34 +43,6 @@ public class SynchronizedBiMapTest extends SynchronizedMapTest { return outer; } - public static final class SynchronizedHashBiMapGenerator extends TestStringBiMapGenerator { - @Override - protected BiMap<String, String> create(Entry<String, String>[] entries) { - Object mutex = new Object(); - BiMap<String, String> result = HashBiMap.create(); - for (Entry<String, String> entry : entries) { - checkArgument(!result.containsKey(entry.getKey())); - result.put(entry.getKey(), entry.getValue()); - } - return Maps.synchronizedBiMap(result); - } - } - - public static final class SynchTestingBiMapGenerator extends TestStringBiMapGenerator { - @Override - protected BiMap<String, String> create(Entry<String, String>[] entries) { - Object mutex = new Object(); - BiMap<String, String> backing = - new TestBiMap<String, String>(HashBiMap.<String, String>create(), mutex); - BiMap<String, String> result = Synchronized.biMap(backing, mutex); - for (Entry<String, String> entry : entries) { - checkArgument(!result.containsKey(entry.getKey())); - result.put(entry.getKey(), entry.getValue()); - } - return result; - } - } - static class TestBiMap<K, V> extends TestMap<K, V> implements BiMap<K, V> { private final BiMap<K, V> delegate; @@ -143,4 +89,26 @@ public class SynchronizedBiMapTest extends SynchronizedMapTest { assertTrue(values instanceof SynchronizedSet); assertSame(mutex, ((SynchronizedSet<?>) values).mutex); } + + public static class AbstractBiMapTests extends AbstractBiMapTest { + public final Object mutex = new Integer(1); // something Serializable + + @Override protected BiMap<Integer, String> create() { + TestBiMap<Integer, String> inner = new TestBiMap<Integer, String>( + HashBiMap.<Integer, String>create(), mutex); + BiMap<Integer, String> outer = Synchronized.biMap(inner, mutex); + return outer; + } + + /** + * If you serialize a synchronized bimap and its inverse together, the + * reserialized bimaps will have backing maps that stay in sync, as shown + * by the {@code testSerializationWithInverseEqual()} test. However, the + * inverse of one won't be the same as the other. + * + * To make them the same, the inverse synchronized bimap would need a custom + * serialized form, similar to what {@code AbstractBiMap.Inverse} does. + */ + @Override public void testSerializationWithInverseSame() {} + } } |