aboutsummaryrefslogtreecommitdiffstats
path: root/guava-testlib/src/com/google/common/collect/testing/TestsForMapsInJavaUtil.java
diff options
context:
space:
mode:
Diffstat (limited to 'guava-testlib/src/com/google/common/collect/testing/TestsForMapsInJavaUtil.java')
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/TestsForMapsInJavaUtil.java126
1 files changed, 25 insertions, 101 deletions
diff --git a/guava-testlib/src/com/google/common/collect/testing/TestsForMapsInJavaUtil.java b/guava-testlib/src/com/google/common/collect/testing/TestsForMapsInJavaUtil.java
index fa996b3..6b71f22 100644
--- a/guava-testlib/src/com/google/common/collect/testing/TestsForMapsInJavaUtil.java
+++ b/guava-testlib/src/com/google/common/collect/testing/TestsForMapsInJavaUtil.java
@@ -23,7 +23,6 @@ import com.google.common.collect.testing.features.MapFeature;
import junit.framework.Test;
import junit.framework.TestSuite;
-import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Collections;
@@ -31,12 +30,11 @@ import java.util.Comparator;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.LinkedHashMap;
+import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-import java.util.SortedMap;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentSkipListMap;
/**
* Generates a test suite covering the {@link Map} implementations in the
@@ -46,7 +44,6 @@ import java.util.concurrent.ConcurrentSkipListMap;
* @author Kevin Bourrillion
*/
public class TestsForMapsInJavaUtil {
-
public static Test suite() {
return new TestsForMapsInJavaUtil().allTests();
}
@@ -57,12 +54,9 @@ public class TestsForMapsInJavaUtil {
suite.addTest(testsForSingletonMap());
suite.addTest(testsForHashMap());
suite.addTest(testsForLinkedHashMap());
- suite.addTest(testsForTreeMapNatural());
- suite.addTest(testsForTreeMapWithComparator());
+ suite.addTest(testsForTreeMap());
suite.addTest(testsForEnumMap());
suite.addTest(testsForConcurrentHashMap());
- suite.addTest(testsForConcurrentSkipListMapNatural());
- suite.addTest(testsForConcurrentSkipListMapWithComparator());
return suite;
}
@@ -78,10 +72,7 @@ public class TestsForMapsInJavaUtil {
protected Collection<Method> suppressForLinkedHashMap() {
return Collections.emptySet();
}
- protected Collection<Method> suppressForTreeMapNatural() {
- return Collections.emptySet();
- }
- protected Collection<Method> suppressForTreeMapWithComparator() {
+ protected Collection<Method> suppressForTreeMap() {
return Collections.emptySet();
}
protected Collection<Method> suppressForEnumMap() {
@@ -90,9 +81,6 @@ public class TestsForMapsInJavaUtil {
protected Collection<Method> suppressForConcurrentHashMap() {
return Collections.emptySet();
}
- protected Collection<Method> suppressForConcurrentSkipListMap() {
- return Collections.emptySet();
- }
public Test testsForEmptyMap() {
return MapTestSuiteBuilder
@@ -104,7 +92,7 @@ public class TestsForMapsInJavaUtil {
})
.named("emptyMap")
.withFeatures(
- CollectionFeature.SERIALIZABLE,
+ CollectionFeature.NONE,
CollectionSize.ZERO)
.suppressing(suppressForEmptyMap())
.createTestSuite();
@@ -123,7 +111,6 @@ public class TestsForMapsInJavaUtil {
.withFeatures(
MapFeature.ALLOWS_NULL_KEYS,
MapFeature.ALLOWS_NULL_VALUES,
- CollectionFeature.SERIALIZABLE,
CollectionSize.ONE)
.suppressing(suppressForSingletonMap())
.createTestSuite();
@@ -136,14 +123,20 @@ public class TestsForMapsInJavaUtil {
Entry<String, String>[] entries) {
return toHashMap(entries);
}
+ @Override public Iterable<Entry<String, String>> order(
+ List<Entry<String, String>> insertionOrder) {
+ /*
+ * For convenience, make this test double as a test that no tester
+ * calls order() on a container without the KNOWN_ORDER feature.
+ */
+ throw new UnsupportedOperationException();
+ }
})
.named("HashMap")
.withFeatures(
MapFeature.GENERAL_PURPOSE,
MapFeature.ALLOWS_NULL_KEYS,
MapFeature.ALLOWS_NULL_VALUES,
- MapFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,
- CollectionFeature.SERIALIZABLE,
CollectionSize.ANY)
.suppressing(suppressForHashMap())
.createTestSuite();
@@ -162,57 +155,29 @@ public class TestsForMapsInJavaUtil {
MapFeature.GENERAL_PURPOSE,
MapFeature.ALLOWS_NULL_KEYS,
MapFeature.ALLOWS_NULL_VALUES,
- MapFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,
CollectionFeature.KNOWN_ORDER,
- CollectionFeature.SERIALIZABLE,
CollectionSize.ANY)
.suppressing(suppressForLinkedHashMap())
.createTestSuite();
}
- public Test testsForTreeMapNatural() {
+ public Test testsForTreeMap() {
return NavigableMapTestSuiteBuilder
- .using(new TestStringSortedMapGenerator() {
- @Override protected SortedMap<String, String> create(
- Entry<String, String>[] entries) {
- /*
- * TODO(cpovirk): it would be nice to create an input Map and use
- * the copy constructor here and in the other tests
- */
- return populate(new TreeMap<String, String>(), entries);
- }
- })
- .named("TreeMap, natural")
- .withFeatures(
- MapFeature.GENERAL_PURPOSE,
- MapFeature.ALLOWS_NULL_VALUES,
- MapFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,
- CollectionFeature.KNOWN_ORDER,
- CollectionFeature.SERIALIZABLE,
- CollectionSize.ANY)
- .suppressing(suppressForTreeMapNatural())
- .createTestSuite();
- }
-
- public Test testsForTreeMapWithComparator() {
- return NavigableMapTestSuiteBuilder
- .using(new TestStringSortedMapGenerator() {
- @Override protected SortedMap<String, String> create(
+ .using(new TestStringMapGenerator() {
+ @Override protected Map<String, String> create(
Entry<String, String>[] entries) {
return populate(new TreeMap<String, String>(
arbitraryNullFriendlyComparator()), entries);
}
})
- .named("TreeMap, with comparator")
+ .named("TreeMap")
.withFeatures(
MapFeature.GENERAL_PURPOSE,
MapFeature.ALLOWS_NULL_KEYS,
MapFeature.ALLOWS_NULL_VALUES,
- MapFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,
CollectionFeature.KNOWN_ORDER,
- CollectionFeature.SERIALIZABLE,
CollectionSize.ANY)
- .suppressing(suppressForTreeMapWithComparator())
+ .suppressing(suppressForTreeMap())
.createTestSuite();
}
@@ -231,7 +196,6 @@ public class TestsForMapsInJavaUtil {
MapFeature.ALLOWS_NULL_VALUES,
MapFeature.RESTRICTS_KEYS,
CollectionFeature.KNOWN_ORDER,
- CollectionFeature.SERIALIZABLE,
CollectionSize.ANY)
.suppressing(suppressForEnumMap())
.createTestSuite();
@@ -248,49 +212,11 @@ public class TestsForMapsInJavaUtil {
.named("ConcurrentHashMap")
.withFeatures(
MapFeature.GENERAL_PURPOSE,
- CollectionFeature.SERIALIZABLE,
CollectionSize.ANY)
.suppressing(suppressForConcurrentHashMap())
.createTestSuite();
}
- public Test testsForConcurrentSkipListMapNatural() {
- return NavigableMapTestSuiteBuilder
- .using(new TestStringSortedMapGenerator() {
- @Override protected SortedMap<String, String> create(
- Entry<String, String>[] entries) {
- return populate(new ConcurrentSkipListMap<String, String>(), entries);
- }
- })
- .named("ConcurrentSkipListMap, natural")
- .withFeatures(
- MapFeature.GENERAL_PURPOSE,
- CollectionFeature.KNOWN_ORDER,
- CollectionFeature.SERIALIZABLE,
- CollectionSize.ANY)
- .suppressing(suppressForConcurrentSkipListMap())
- .createTestSuite();
- }
-
- public Test testsForConcurrentSkipListMapWithComparator() {
- return NavigableMapTestSuiteBuilder
- .using(new TestStringSortedMapGenerator() {
- @Override protected SortedMap<String, String> create(
- Entry<String, String>[] entries) {
- return populate(new ConcurrentSkipListMap<String, String>(
- arbitraryNullFriendlyComparator()), entries);
- }
- })
- .named("ConcurrentSkipListMap, with comparator")
- .withFeatures(
- MapFeature.GENERAL_PURPOSE,
- CollectionFeature.KNOWN_ORDER,
- CollectionFeature.SERIALIZABLE,
- CollectionSize.ANY)
- .suppressing(suppressForConcurrentSkipListMap())
- .createTestSuite();
- }
-
// TODO: IdentityHashMap, AbstractMap
private static Map<String, String> toHashMap(
@@ -300,8 +226,8 @@ public class TestsForMapsInJavaUtil {
// TODO: call conversion constructors or factory methods instead of using
// populate() on an empty map
- private static <T, M extends Map<T, String>> M populate(
- M map, Entry<T, String>[] entries) {
+ private static <T> Map<T, String> populate(
+ Map<T, String> map, Entry<T, String>[] entries) {
for (Entry<T, String> entry : entries) {
map.put(entry.getKey(), entry.getValue());
}
@@ -309,13 +235,11 @@ public class TestsForMapsInJavaUtil {
}
static <T> Comparator<T> arbitraryNullFriendlyComparator() {
- return new NullFriendlyComparator<T>();
- }
-
- private static final class NullFriendlyComparator<T> implements Comparator<T>, Serializable {
- @Override
- public int compare(T left, T right) {
- return String.valueOf(left).compareTo(String.valueOf(right));
- }
+ return new Comparator<T>() {
+ @Override
+ public int compare(T left, T right) {
+ return String.valueOf(left).compareTo(String.valueOf(right));
+ }
+ };
}
}