Skip to content

Commit

Permalink
Reenable NullPointerTester tests for our internal Android-emulator …
Browse files Browse the repository at this point in the history
…testing.

We had disabled the tests in that environment because `NullPointerTester` performed reflection on types that contained `Collector`-based APIs. Since `Collector` wasn't available, the tests failed. But now, we've enabled library desugaring for our internal tests (though we continue not to _require_ library desugaring unless users actually use such APIs), so the tests can work again.

(relevant to #6567)

RELNOTES=n/a
PiperOrigin-RevId: 634770528
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed May 17, 2024
1 parent dc200d3 commit 8359c92
Show file tree
Hide file tree
Showing 34 changed files with 0 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,32 +45,26 @@
* @author Chris Povirk
*/
public class FauxveridesTest extends TestCase {
@AndroidIncompatible // similar to ImmutableTableTest.testNullPointerInstance
public void testImmutableBiMap() {
doHasAllFauxveridesTest(ImmutableBiMap.class, ImmutableMap.class);
}

@AndroidIncompatible // similar to ImmutableTableTest.testNullPointerInstance
public void testImmutableListMultimap() {
doHasAllFauxveridesTest(ImmutableListMultimap.class, ImmutableMultimap.class);
}

@AndroidIncompatible // similar to ImmutableTableTest.testNullPointerInstance
public void testImmutableSetMultimap() {
doHasAllFauxveridesTest(ImmutableSetMultimap.class, ImmutableMultimap.class);
}

@AndroidIncompatible // similar to ImmutableTableTest.testNullPointerInstance
public void testImmutableSortedMap() {
doHasAllFauxveridesTest(ImmutableSortedMap.class, ImmutableMap.class);
}

@AndroidIncompatible // similar to ImmutableTableTest.testNullPointerInstance
public void testImmutableSortedSet() {
doHasAllFauxveridesTest(ImmutableSortedSet.class, ImmutableSet.class);
}

@AndroidIncompatible // similar to ImmutableTableTest.testNullPointerInstance
public void testImmutableSortedMultiset() {
doHasAllFauxveridesTest(ImmutableSortedMultiset.class, ImmutableMultiset.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,6 @@ public void testEmptySerialization() {

@J2ktIncompatible
@GwtIncompatible // reflection
@AndroidIncompatible // see ImmutableTableTest.testNullPointerInstance
public void testNulls() throws Exception {
NullPointerTester tester = new NullPointerTester();
tester.testAllPublicStaticMethods(ImmutableListMultimap.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,6 @@ public void testToImmutableList_java7_combine() {

@J2ktIncompatible
@GwtIncompatible // NullPointerTester
@AndroidIncompatible // see ImmutableTableTest.testNullPointerInstance
public void testNullPointers() {
NullPointerTester tester = new NullPointerTester();
tester.testAllPublicStaticMethods(ImmutableList.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,6 @@ public void testAsMultimapCaches() {

@J2ktIncompatible
@GwtIncompatible // NullPointerTester
@AndroidIncompatible // see ImmutableTableTest.testNullPointerInstance
public void testNullPointers() {
NullPointerTester tester = new NullPointerTester();
tester.testAllPublicStaticMethods(ImmutableMap.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ public void testEquals() {

@J2ktIncompatible
@GwtIncompatible // reflection
@AndroidIncompatible // see ImmutableTableTest.testNullPointerInstance
public void testNulls() throws Exception {
NullPointerTester tester = new NullPointerTester();
tester.testAllPublicStaticMethods(ImmutableMultimap.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,6 @@ public void testBuilderSetCountIllegal() {

@J2ktIncompatible
@GwtIncompatible // NullPointerTester
@AndroidIncompatible // see ImmutableTableTest.testNullPointerInstance
public void testNullPointers() {
NullPointerTester tester = new NullPointerTester();
tester.testAllPublicStaticMethods(ImmutableMultiset.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,6 @@ private ImmutableSetMultimap<String, Integer> createMultimap() {

@J2ktIncompatible
@GwtIncompatible // reflection
@AndroidIncompatible // see ImmutableTableTest.testNullPointerInstance
public void testNulls() throws Exception {
NullPointerTester tester = new NullPointerTester();
tester.testAllPublicStaticMethods(ImmutableSetMultimap.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,6 @@ public void testNullGet() {

@J2ktIncompatible
@GwtIncompatible // NullPointerTester
@AndroidIncompatible // see ImmutableTableTest.testNullPointerInstance
public void testNullPointers() {
NullPointerTester tester = new NullPointerTester();
tester.testAllPublicStaticMethods(ImmutableSortedMap.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,6 @@ public void testBuilderSetCountIllegal() {
assertThrows(IllegalArgumentException.class, () -> builder.setCount("a", -2));
}

@AndroidIncompatible // see ImmutableTableTest.testNullPointerInstance
public void testNullPointers() {
new NullPointerTester().testAllPublicStaticMethods(ImmutableSortedMultiset.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ protected <E extends Comparable<? super E>> SortedSet<E> copyOf(Iterator<? exten

@J2ktIncompatible
@GwtIncompatible // NullPointerTester
@AndroidIncompatible // see ImmutableTableTest.testNullPointerInstance
public void testNullPointers() {
new NullPointerTester().testAllPublicStaticMethods(ImmutableSortedSet.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,34 +483,4 @@ public void testOverflowCondition() {
}
assertTrue(builder.build() instanceof SparseImmutableTable);
}

@J2ktIncompatible
@GwtIncompatible // NullPointerTester
@Override
public void testNullPointerInstance() {
if (isAndroid()) {
/*
* NPT fails under the old versions of Android we test under because it performs reflection on
* ImmutableTable, which declares static methods that refer to Collector, which is unavailable
* under such versions.
*
* We use a runtime check here instead of @AndroidIncompatible: @AndroidIncompatible operates
* by stripping annotated methods entirely, and if we strip this method, then JUnit would just
* run the supermethod as usual.
*
* TODO: b/292578973: Use @AndroidIncompatible if we change our system to keep the methods in
* place but to have the test runner skip them. However, note that if we choose to *both*
* strip the methods *and* have the test runner not run them (for some unusual cases in which
* we don't run the stripping test for technical reasons), then we'd be back to the problem
* described above, since the supermethod is *not* annotated @AndroidIncompatible (since it
* works fine with the other Table implementations).
*/
return;
}
super.testNullPointerInstance();
}

private static boolean isAndroid() {
return System.getProperty("java.runtime.name", "").contains("Android");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1375,7 +1375,6 @@ public void testMergeSorted_skipping_pyramid() {

@J2ktIncompatible
@GwtIncompatible // reflection
@AndroidIncompatible // see ImmutableTableTest.testNullPointerInstance
public void testIterables_nullCheck() throws Exception {
new ClassSanityTester()
.forAllPublicStaticMethods(Iterables.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,6 @@ public void testToStringImplWithNullValues() throws Exception {

@J2ktIncompatible
@GwtIncompatible // NullPointerTester
@AndroidIncompatible // see ImmutableTableTest.testNullPointerInstance
public void testNullPointerExceptions() {
new NullPointerTester().testAllPublicStaticMethods(Maps.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,6 @@ public void testFilteredKeysListMultimapGetBadValue() {

@J2ktIncompatible
@GwtIncompatible // NullPointerTester
@AndroidIncompatible // see ImmutableTableTest.testNullPointerInstance
public void testNullPointers() {
new NullPointerTester().testAllPublicStaticMethods(Multimaps.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ public void testHighestCountFirst() {

@J2ktIncompatible
@GwtIncompatible // NullPointerTester
@AndroidIncompatible // see ImmutableTableTest.testNullPointerInstance
public void testNullPointers() {
new NullPointerTester().testAllPublicStaticMethods(Multisets.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,6 @@ public void testComplementOfEmptySetWithoutTypeDoesntWork() {

@J2ktIncompatible
@GwtIncompatible // NullPointerTester
@AndroidIncompatible // see ImmutableTableTest.testNullPointerInstance
public void testNullPointerExceptions() {
new NullPointerTester()
.setDefault(Enum.class, SomeEnum.A)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ public void testFailureWhenMoreThan255HashFunctionsAreNeeded() {
});
}

@AndroidIncompatible // see ImmutableTableTest.testNullPointerInstance
public void testNullPointers() {
NullPointerTester tester = new NullPointerTester();
tester.testAllPublicInstanceMethods(BloomFilter.create(Funnels.unencodedCharsFunnel(), 100));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,32 +45,26 @@
* @author Chris Povirk
*/
public class FauxveridesTest extends TestCase {
@AndroidIncompatible // similar to ImmutableTableTest.testNullPointerInstance
public void testImmutableBiMap() {
doHasAllFauxveridesTest(ImmutableBiMap.class, ImmutableMap.class);
}

@AndroidIncompatible // similar to ImmutableTableTest.testNullPointerInstance
public void testImmutableListMultimap() {
doHasAllFauxveridesTest(ImmutableListMultimap.class, ImmutableMultimap.class);
}

@AndroidIncompatible // similar to ImmutableTableTest.testNullPointerInstance
public void testImmutableSetMultimap() {
doHasAllFauxveridesTest(ImmutableSetMultimap.class, ImmutableMultimap.class);
}

@AndroidIncompatible // similar to ImmutableTableTest.testNullPointerInstance
public void testImmutableSortedMap() {
doHasAllFauxveridesTest(ImmutableSortedMap.class, ImmutableMap.class);
}

@AndroidIncompatible // similar to ImmutableTableTest.testNullPointerInstance
public void testImmutableSortedSet() {
doHasAllFauxveridesTest(ImmutableSortedSet.class, ImmutableSet.class);
}

@AndroidIncompatible // similar to ImmutableTableTest.testNullPointerInstance
public void testImmutableSortedMultiset() {
doHasAllFauxveridesTest(ImmutableSortedMultiset.class, ImmutableMultiset.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,6 @@ public void testEmptySerialization() {

@J2ktIncompatible
@GwtIncompatible // reflection
@AndroidIncompatible // see ImmutableTableTest.testNullPointerInstance
public void testNulls() throws Exception {
NullPointerTester tester = new NullPointerTester();
tester.testAllPublicStaticMethods(ImmutableListMultimap.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,6 @@ public void testToImmutableList() {

@J2ktIncompatible
@GwtIncompatible // NullPointerTester
@AndroidIncompatible // see ImmutableTableTest.testNullPointerInstance
public void testNullPointers() {
NullPointerTester tester = new NullPointerTester();
tester.testAllPublicStaticMethods(ImmutableList.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,6 @@ public void testAsMultimapCaches() {

@J2ktIncompatible
@GwtIncompatible // NullPointerTester
@AndroidIncompatible // see ImmutableTableTest.testNullPointerInstance
public void testNullPointers() {
NullPointerTester tester = new NullPointerTester();
tester.testAllPublicStaticMethods(ImmutableMap.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ public void testEquals() {

@J2ktIncompatible
@GwtIncompatible // reflection
@AndroidIncompatible // see ImmutableTableTest.testNullPointerInstance
public void testNulls() throws Exception {
NullPointerTester tester = new NullPointerTester();
tester.testAllPublicStaticMethods(ImmutableMultimap.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,6 @@ public void testBuilderSetCountIllegal() {

@J2ktIncompatible
@GwtIncompatible // NullPointerTester
@AndroidIncompatible // see ImmutableTableTest.testNullPointerInstance
public void testNullPointers() {
NullPointerTester tester = new NullPointerTester();
tester.testAllPublicStaticMethods(ImmutableMultiset.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,6 @@ private ImmutableSetMultimap<String, Integer> createMultimap() {

@J2ktIncompatible
@GwtIncompatible // reflection
@AndroidIncompatible // see ImmutableTableTest.testNullPointerInstance
public void testNulls() throws Exception {
NullPointerTester tester = new NullPointerTester();
tester.testAllPublicStaticMethods(ImmutableSetMultimap.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,6 @@ public void testNullGet() {

@J2ktIncompatible
@GwtIncompatible // NullPointerTester
@AndroidIncompatible // see ImmutableTableTest.testNullPointerInstance
public void testNullPointers() {
NullPointerTester tester = new NullPointerTester();
tester.testAllPublicStaticMethods(ImmutableSortedMap.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,6 @@ public void testToImmutableSortedMultisetCountFunction() {
"C");
}

@AndroidIncompatible // see ImmutableTableTest.testNullPointerInstance
public void testNullPointers() {
new NullPointerTester().testAllPublicStaticMethods(ImmutableSortedMultiset.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ protected <E extends Comparable<? super E>> SortedSet<E> copyOf(Iterator<? exten

@J2ktIncompatible
@GwtIncompatible // NullPointerTester
@AndroidIncompatible // see ImmutableTableTest.testNullPointerInstance
public void testNullPointers() {
new NullPointerTester().testAllPublicStaticMethods(ImmutableSortedSet.class);
}
Expand Down
30 changes: 0 additions & 30 deletions guava-tests/test/com/google/common/collect/ImmutableTableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -489,34 +489,4 @@ public void testOverflowCondition() {
}
assertTrue(builder.build() instanceof SparseImmutableTable);
}

@J2ktIncompatible
@GwtIncompatible // NullPointerTester
@Override
public void testNullPointerInstance() {
if (isAndroid()) {
/*
* NPT fails under the old versions of Android we test under because it performs reflection on
* ImmutableTable, which declares static methods that refer to Collector, which is unavailable
* under such versions.
*
* We use a runtime check here instead of @AndroidIncompatible: @AndroidIncompatible operates
* by stripping annotated methods entirely, and if we strip this method, then JUnit would just
* run the supermethod as usual.
*
* TODO: b/292578973: Use @AndroidIncompatible if we change our system to keep the methods in
* place but to have the test runner skip them. However, note that if we choose to *both*
* strip the methods *and* have the test runner not run them (for some unusual cases in which
* we don't run the stripping test for technical reasons), then we'd be back to the problem
* described above, since the supermethod is *not* annotated @AndroidIncompatible (since it
* works fine with the other Table implementations).
*/
return;
}
super.testNullPointerInstance();
}

private static boolean isAndroid() {
return System.getProperty("java.runtime.name", "").contains("Android");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1412,7 +1412,6 @@ public void testMergeSorted_skipping_pyramid() {

@J2ktIncompatible
@GwtIncompatible // reflection
@AndroidIncompatible // see ImmutableTableTest.testNullPointerInstance
public void testIterables_nullCheck() throws Exception {
new ClassSanityTester()
.forAllPublicStaticMethods(Iterables.class)
Expand Down
1 change: 0 additions & 1 deletion guava-tests/test/com/google/common/collect/MapsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,6 @@ public void testToStringImplWithNullValues() throws Exception {

@J2ktIncompatible
@GwtIncompatible // NullPointerTester
@AndroidIncompatible // see ImmutableTableTest.testNullPointerInstance
public void testNullPointerExceptions() {
new NullPointerTester().testAllPublicStaticMethods(Maps.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,6 @@ public void testFilteredKeysListMultimapGetBadValue() {

@J2ktIncompatible
@GwtIncompatible // NullPointerTester
@AndroidIncompatible // see ImmutableTableTest.testNullPointerInstance
public void testNullPointers() {
new NullPointerTester().testAllPublicStaticMethods(Multimaps.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ public void testToMultisetCountFunction() {

@J2ktIncompatible
@GwtIncompatible // NullPointerTester
@AndroidIncompatible // see ImmutableTableTest.testNullPointerInstance
public void testNullPointers() {
new NullPointerTester().testAllPublicStaticMethods(Multisets.class);
}
Expand Down
1 change: 0 additions & 1 deletion guava-tests/test/com/google/common/collect/SetsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,6 @@ public void testComplementOfEmptySetWithoutTypeDoesntWork() {

@J2ktIncompatible
@GwtIncompatible // NullPointerTester
@AndroidIncompatible // see ImmutableTableTest.testNullPointerInstance
public void testNullPointerExceptions() {
new NullPointerTester()
.setDefault(Enum.class, SomeEnum.A)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ public void testFailureWhenMoreThan255HashFunctionsAreNeeded() {
});
}

@AndroidIncompatible // see ImmutableTableTest.testNullPointerInstance
public void testNullPointers() {
NullPointerTester tester = new NullPointerTester();
tester.testAllPublicInstanceMethods(BloomFilter.create(Funnels.unencodedCharsFunnel(), 100));
Expand Down

0 comments on commit 8359c92

Please sign in to comment.