diff --git a/android/guava-testlib/src/com/google/common/collect/testing/SortedSetTestSuiteBuilder.java b/android/guava-testlib/src/com/google/common/collect/testing/SortedSetTestSuiteBuilder.java index 93aa389f835d..d61dd96ad240 100644 --- a/android/guava-testlib/src/com/google/common/collect/testing/SortedSetTestSuiteBuilder.java +++ b/android/guava-testlib/src/com/google/common/collect/testing/SortedSetTestSuiteBuilder.java @@ -21,10 +21,15 @@ import com.google.common.collect.testing.DerivedCollectionGenerators.SortedSetSubsetTestSetGenerator; import com.google.common.collect.testing.features.CollectionFeature; import com.google.common.collect.testing.features.Feature; +import com.google.common.collect.testing.testers.CollectionAddAllTester; +import com.google.common.collect.testing.testers.CollectionAddTester; import com.google.common.collect.testing.testers.SortedSetNavigationTester; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collection; +import java.util.HashSet; import java.util.List; +import java.util.Set; import junit.framework.TestSuite; /** @@ -87,13 +92,20 @@ final TestSuite createSubsetSuite( (TestSortedSetGenerator) parentBuilder.getSubjectGenerator().getInnerGenerator(); List> features = new ArrayList<>(parentBuilder.getFeatures()); - features.remove(CollectionFeature.ALLOWS_NULL_VALUES); + Set suppressing = new HashSet<>(parentBuilder.getSuppressedTests()); features.add(CollectionFeature.SUBSET_VIEW); + if (features.remove(CollectionFeature.ALLOWS_NULL_VALUES)) { + // the null value might be out of bounds, so we can't always construct a subset with nulls + features.add(CollectionFeature.ALLOWS_NULL_QUERIES); + // but add null might still be supported if it happens to be within range of the subset + suppressing.add(CollectionAddTester.getAddNullUnsupportedMethod()); + suppressing.add(CollectionAddAllTester.getAddAllNullUnsupportedMethod()); + } return newBuilderUsing(delegate, to, from) .named(parentBuilder.getName() + " subSet " + from + "-" + to) .withFeatures(features) - .suppressing(parentBuilder.getSuppressedTests()) + .suppressing(suppressing) .withSetUp(parentBuilder.getSetUp()) .withTearDown(parentBuilder.getTearDown()) .createTestSuite(); diff --git a/android/guava-testlib/src/com/google/common/collect/testing/google/BiMapGenerators.java b/android/guava-testlib/src/com/google/common/collect/testing/google/BiMapGenerators.java index 260a160fbb94..f6c050f7bae4 100644 --- a/android/guava-testlib/src/com/google/common/collect/testing/google/BiMapGenerators.java +++ b/android/guava-testlib/src/com/google/common/collect/testing/google/BiMapGenerators.java @@ -16,6 +16,8 @@ package com.google.common.collect.testing.google; +import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.annotations.GwtCompatible; import com.google.common.collect.BiMap; import com.google.common.collect.ImmutableBiMap; @@ -38,6 +40,7 @@ public static class ImmutableBiMapGenerator extends TestStringBiMapGenerator { protected BiMap create(Entry[] entries) { ImmutableBiMap.Builder builder = ImmutableBiMap.builder(); for (Entry entry : entries) { + checkNotNull(entry); builder.put(entry.getKey(), entry.getValue()); } return builder.build(); diff --git a/android/guava-testlib/src/com/google/common/collect/testing/google/DerivedGoogleCollectionGenerators.java b/android/guava-testlib/src/com/google/common/collect/testing/google/DerivedGoogleCollectionGenerators.java index cede1bd5f7a2..fb0861d4f571 100644 --- a/android/guava-testlib/src/com/google/common/collect/testing/google/DerivedGoogleCollectionGenerators.java +++ b/android/guava-testlib/src/com/google/common/collect/testing/google/DerivedGoogleCollectionGenerators.java @@ -16,6 +16,8 @@ package com.google.common.collect.testing.google; +import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.annotations.GwtCompatible; import com.google.common.collect.BiMap; import com.google.common.collect.testing.DerivedGenerator; @@ -112,6 +114,7 @@ public SampleElements> samples() { } private Entry reverse(Entry entry) { + checkNotNull(entry); return Helpers.mapEntry(entry.getValue(), entry.getKey()); } diff --git a/android/guava-testlib/src/com/google/common/collect/testing/google/ListMultimapTestSuiteBuilder.java b/android/guava-testlib/src/com/google/common/collect/testing/google/ListMultimapTestSuiteBuilder.java index 981c29afe4d2..0ddc1517bdb1 100644 --- a/android/guava-testlib/src/com/google/common/collect/testing/google/ListMultimapTestSuiteBuilder.java +++ b/android/guava-testlib/src/com/google/common/collect/testing/google/ListMultimapTestSuiteBuilder.java @@ -102,6 +102,9 @@ Set> computeMultimapGetFeatures(Set> multimapFeatures) { if (derivedFeatures.contains(CollectionFeature.SUPPORTS_ADD)) { derivedFeatures.add(ListFeature.SUPPORTS_ADD_WITH_INDEX); } + if (derivedFeatures.contains(CollectionFeature.SUPPORTS_REMOVE)) { + derivedFeatures.add(ListFeature.SUPPORTS_REMOVE_WITH_INDEX); + } if (derivedFeatures.contains(CollectionFeature.GENERAL_PURPOSE)) { derivedFeatures.add(ListFeature.GENERAL_PURPOSE); } diff --git a/android/guava-testlib/src/com/google/common/collect/testing/google/MapGenerators.java b/android/guava-testlib/src/com/google/common/collect/testing/google/MapGenerators.java index 169785dff0ac..1c06c1ff9a04 100644 --- a/android/guava-testlib/src/com/google/common/collect/testing/google/MapGenerators.java +++ b/android/guava-testlib/src/com/google/common/collect/testing/google/MapGenerators.java @@ -16,6 +16,7 @@ package com.google.common.collect.testing.google; +import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.collect.testing.Helpers.mapEntry; import com.google.common.annotations.GwtCompatible; @@ -53,6 +54,7 @@ public static class ImmutableMapGenerator extends TestStringMapGenerator { protected Map create(Entry[] entries) { ImmutableMap.Builder builder = ImmutableMap.builder(); for (Entry entry : entries) { + checkNotNull(entry); builder.put(entry.getKey(), entry.getValue()); } return builder.buildOrThrow(); @@ -142,7 +144,7 @@ public List> create(Object... elements) { ImmutableMap.Builder builder = ImmutableMap.builder(); for (Object o : elements) { @SuppressWarnings("unchecked") - Entry entry = (Entry) o; + Entry entry = (Entry) checkNotNull(o); builder.put(entry); } return builder.buildOrThrow().entrySet().asList(); @@ -154,7 +156,7 @@ public static class ImmutableEnumMapGenerator extends TestEnumMapGenerator { protected Map create(Entry[] entries) { Map map = Maps.newHashMap(); for (Entry entry : entries) { - // checkArgument(!map.containsKey(entry.getKey())); + checkNotNull(entry); map.put(entry.getKey(), entry.getValue()); } return Maps.immutableEnumMap(map); diff --git a/android/guava-testlib/src/com/google/common/collect/testing/google/MultimapPutIterableTester.java b/android/guava-testlib/src/com/google/common/collect/testing/google/MultimapPutIterableTester.java index abdec536f217..99b8864bd61e 100644 --- a/android/guava-testlib/src/com/google/common/collect/testing/google/MultimapPutIterableTester.java +++ b/android/guava-testlib/src/com/google/common/collect/testing/google/MultimapPutIterableTester.java @@ -157,7 +157,7 @@ public void testPutAllOnPresentNullKey() { assertGet(null, v3(), v4()); } - @MapFeature.Require(absent = ALLOWS_NULL_KEYS) + @MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_KEYS) public void testPutAllNullForbidden() { try { multimap().putAll(null, Collections.singletonList(v3())); diff --git a/android/guava-testlib/src/com/google/common/collect/testing/google/SortedMapGenerators.java b/android/guava-testlib/src/com/google/common/collect/testing/google/SortedMapGenerators.java index 21165583776f..4bc153be3100 100644 --- a/android/guava-testlib/src/com/google/common/collect/testing/google/SortedMapGenerators.java +++ b/android/guava-testlib/src/com/google/common/collect/testing/google/SortedMapGenerators.java @@ -98,7 +98,7 @@ public List> create(Object... elements) { ImmutableSortedMap.Builder builder = ImmutableSortedMap.naturalOrder(); for (Object o : elements) { @SuppressWarnings("unchecked") - Entry entry = (Entry) o; + Entry entry = (Entry) checkNotNull(o); builder.put(entry); } return builder.build().entrySet().asList(); diff --git a/android/guava-tests/test/com/google/common/collect/MultisetsCollectionTest.java b/android/guava-tests/test/com/google/common/collect/MultisetsCollectionTest.java index f143ebd10831..71fcf00d0e20 100644 --- a/android/guava-tests/test/com/google/common/collect/MultisetsCollectionTest.java +++ b/android/guava-tests/test/com/google/common/collect/MultisetsCollectionTest.java @@ -50,7 +50,7 @@ public static Test suite() { CollectionSize.ANY, CollectionFeature.KNOWN_ORDER, CollectionFeature.SERIALIZABLE, - CollectionFeature.ALLOWS_NULL_QUERIES) + CollectionFeature.ALLOWS_NULL_VALUES) .named("Multisets.unmodifiableMultiset[LinkedHashMultiset]") .createTestSuite()); diff --git a/guava-testlib/src/com/google/common/collect/testing/SortedSetTestSuiteBuilder.java b/guava-testlib/src/com/google/common/collect/testing/SortedSetTestSuiteBuilder.java index 93aa389f835d..d61dd96ad240 100644 --- a/guava-testlib/src/com/google/common/collect/testing/SortedSetTestSuiteBuilder.java +++ b/guava-testlib/src/com/google/common/collect/testing/SortedSetTestSuiteBuilder.java @@ -21,10 +21,15 @@ import com.google.common.collect.testing.DerivedCollectionGenerators.SortedSetSubsetTestSetGenerator; import com.google.common.collect.testing.features.CollectionFeature; import com.google.common.collect.testing.features.Feature; +import com.google.common.collect.testing.testers.CollectionAddAllTester; +import com.google.common.collect.testing.testers.CollectionAddTester; import com.google.common.collect.testing.testers.SortedSetNavigationTester; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collection; +import java.util.HashSet; import java.util.List; +import java.util.Set; import junit.framework.TestSuite; /** @@ -87,13 +92,20 @@ final TestSuite createSubsetSuite( (TestSortedSetGenerator) parentBuilder.getSubjectGenerator().getInnerGenerator(); List> features = new ArrayList<>(parentBuilder.getFeatures()); - features.remove(CollectionFeature.ALLOWS_NULL_VALUES); + Set suppressing = new HashSet<>(parentBuilder.getSuppressedTests()); features.add(CollectionFeature.SUBSET_VIEW); + if (features.remove(CollectionFeature.ALLOWS_NULL_VALUES)) { + // the null value might be out of bounds, so we can't always construct a subset with nulls + features.add(CollectionFeature.ALLOWS_NULL_QUERIES); + // but add null might still be supported if it happens to be within range of the subset + suppressing.add(CollectionAddTester.getAddNullUnsupportedMethod()); + suppressing.add(CollectionAddAllTester.getAddAllNullUnsupportedMethod()); + } return newBuilderUsing(delegate, to, from) .named(parentBuilder.getName() + " subSet " + from + "-" + to) .withFeatures(features) - .suppressing(parentBuilder.getSuppressedTests()) + .suppressing(suppressing) .withSetUp(parentBuilder.getSetUp()) .withTearDown(parentBuilder.getTearDown()) .createTestSuite(); diff --git a/guava-testlib/src/com/google/common/collect/testing/google/BiMapGenerators.java b/guava-testlib/src/com/google/common/collect/testing/google/BiMapGenerators.java index 260a160fbb94..f6c050f7bae4 100644 --- a/guava-testlib/src/com/google/common/collect/testing/google/BiMapGenerators.java +++ b/guava-testlib/src/com/google/common/collect/testing/google/BiMapGenerators.java @@ -16,6 +16,8 @@ package com.google.common.collect.testing.google; +import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.annotations.GwtCompatible; import com.google.common.collect.BiMap; import com.google.common.collect.ImmutableBiMap; @@ -38,6 +40,7 @@ public static class ImmutableBiMapGenerator extends TestStringBiMapGenerator { protected BiMap create(Entry[] entries) { ImmutableBiMap.Builder builder = ImmutableBiMap.builder(); for (Entry entry : entries) { + checkNotNull(entry); builder.put(entry.getKey(), entry.getValue()); } return builder.build(); diff --git a/guava-testlib/src/com/google/common/collect/testing/google/DerivedGoogleCollectionGenerators.java b/guava-testlib/src/com/google/common/collect/testing/google/DerivedGoogleCollectionGenerators.java index cede1bd5f7a2..fb0861d4f571 100644 --- a/guava-testlib/src/com/google/common/collect/testing/google/DerivedGoogleCollectionGenerators.java +++ b/guava-testlib/src/com/google/common/collect/testing/google/DerivedGoogleCollectionGenerators.java @@ -16,6 +16,8 @@ package com.google.common.collect.testing.google; +import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.annotations.GwtCompatible; import com.google.common.collect.BiMap; import com.google.common.collect.testing.DerivedGenerator; @@ -112,6 +114,7 @@ public SampleElements> samples() { } private Entry reverse(Entry entry) { + checkNotNull(entry); return Helpers.mapEntry(entry.getValue(), entry.getKey()); } diff --git a/guava-testlib/src/com/google/common/collect/testing/google/ListMultimapTestSuiteBuilder.java b/guava-testlib/src/com/google/common/collect/testing/google/ListMultimapTestSuiteBuilder.java index 981c29afe4d2..0ddc1517bdb1 100644 --- a/guava-testlib/src/com/google/common/collect/testing/google/ListMultimapTestSuiteBuilder.java +++ b/guava-testlib/src/com/google/common/collect/testing/google/ListMultimapTestSuiteBuilder.java @@ -102,6 +102,9 @@ Set> computeMultimapGetFeatures(Set> multimapFeatures) { if (derivedFeatures.contains(CollectionFeature.SUPPORTS_ADD)) { derivedFeatures.add(ListFeature.SUPPORTS_ADD_WITH_INDEX); } + if (derivedFeatures.contains(CollectionFeature.SUPPORTS_REMOVE)) { + derivedFeatures.add(ListFeature.SUPPORTS_REMOVE_WITH_INDEX); + } if (derivedFeatures.contains(CollectionFeature.GENERAL_PURPOSE)) { derivedFeatures.add(ListFeature.GENERAL_PURPOSE); } diff --git a/guava-testlib/src/com/google/common/collect/testing/google/MapGenerators.java b/guava-testlib/src/com/google/common/collect/testing/google/MapGenerators.java index 169785dff0ac..1c06c1ff9a04 100644 --- a/guava-testlib/src/com/google/common/collect/testing/google/MapGenerators.java +++ b/guava-testlib/src/com/google/common/collect/testing/google/MapGenerators.java @@ -16,6 +16,7 @@ package com.google.common.collect.testing.google; +import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.collect.testing.Helpers.mapEntry; import com.google.common.annotations.GwtCompatible; @@ -53,6 +54,7 @@ public static class ImmutableMapGenerator extends TestStringMapGenerator { protected Map create(Entry[] entries) { ImmutableMap.Builder builder = ImmutableMap.builder(); for (Entry entry : entries) { + checkNotNull(entry); builder.put(entry.getKey(), entry.getValue()); } return builder.buildOrThrow(); @@ -142,7 +144,7 @@ public List> create(Object... elements) { ImmutableMap.Builder builder = ImmutableMap.builder(); for (Object o : elements) { @SuppressWarnings("unchecked") - Entry entry = (Entry) o; + Entry entry = (Entry) checkNotNull(o); builder.put(entry); } return builder.buildOrThrow().entrySet().asList(); @@ -154,7 +156,7 @@ public static class ImmutableEnumMapGenerator extends TestEnumMapGenerator { protected Map create(Entry[] entries) { Map map = Maps.newHashMap(); for (Entry entry : entries) { - // checkArgument(!map.containsKey(entry.getKey())); + checkNotNull(entry); map.put(entry.getKey(), entry.getValue()); } return Maps.immutableEnumMap(map); diff --git a/guava-testlib/src/com/google/common/collect/testing/google/MultimapPutIterableTester.java b/guava-testlib/src/com/google/common/collect/testing/google/MultimapPutIterableTester.java index abdec536f217..99b8864bd61e 100644 --- a/guava-testlib/src/com/google/common/collect/testing/google/MultimapPutIterableTester.java +++ b/guava-testlib/src/com/google/common/collect/testing/google/MultimapPutIterableTester.java @@ -157,7 +157,7 @@ public void testPutAllOnPresentNullKey() { assertGet(null, v3(), v4()); } - @MapFeature.Require(absent = ALLOWS_NULL_KEYS) + @MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_KEYS) public void testPutAllNullForbidden() { try { multimap().putAll(null, Collections.singletonList(v3())); diff --git a/guava-testlib/src/com/google/common/collect/testing/google/SortedMapGenerators.java b/guava-testlib/src/com/google/common/collect/testing/google/SortedMapGenerators.java index 21165583776f..4bc153be3100 100644 --- a/guava-testlib/src/com/google/common/collect/testing/google/SortedMapGenerators.java +++ b/guava-testlib/src/com/google/common/collect/testing/google/SortedMapGenerators.java @@ -98,7 +98,7 @@ public List> create(Object... elements) { ImmutableSortedMap.Builder builder = ImmutableSortedMap.naturalOrder(); for (Object o : elements) { @SuppressWarnings("unchecked") - Entry entry = (Entry) o; + Entry entry = (Entry) checkNotNull(o); builder.put(entry); } return builder.build().entrySet().asList(); diff --git a/guava-tests/test/com/google/common/collect/MultisetsCollectionTest.java b/guava-tests/test/com/google/common/collect/MultisetsCollectionTest.java index f143ebd10831..71fcf00d0e20 100644 --- a/guava-tests/test/com/google/common/collect/MultisetsCollectionTest.java +++ b/guava-tests/test/com/google/common/collect/MultisetsCollectionTest.java @@ -50,7 +50,7 @@ public static Test suite() { CollectionSize.ANY, CollectionFeature.KNOWN_ORDER, CollectionFeature.SERIALIZABLE, - CollectionFeature.ALLOWS_NULL_QUERIES) + CollectionFeature.ALLOWS_NULL_VALUES) .named("Multisets.unmodifiableMultiset[LinkedHashMultiset]") .createTestSuite());