Support Predicate#not as backport
Bug: 222647019
Change-Id: I9795c1b9cd5f7cc4a6eaca63ffb29d536db8ca1a
diff --git a/src/test/examplesJava11/backport/PredicateBackportJava11Main.java b/src/test/examplesJava11/backport/PredicateBackportJava11Main.java
new file mode 100644
index 0000000..d16674a
--- /dev/null
+++ b/src/test/examplesJava11/backport/PredicateBackportJava11Main.java
@@ -0,0 +1,36 @@
+// Copyright (c) 2022, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+package backport;
+
+import java.util.Objects;
+import java.util.function.Predicate;
+
+public final class PredicateBackportJava11Main {
+ public static void main(String[] args) {
+ testNot();
+ }
+
+ private static void testNot() {
+
+ Predicate<Object> isNull = Objects::isNull;
+ Predicate<Object> notNull = Predicate.not(isNull);
+
+ assertEquals(notNull.test(null), false);
+ assertEquals(notNull.test("something"), true);
+
+ try {
+ Predicate.not(null);
+ throw new AssertionError("Expected to throw NPE");
+ } catch (Throwable t) {
+ // Expected.
+ }
+ }
+
+ private static void assertEquals(Object expected, Object actual) {
+ if (expected != actual && (expected == null || !expected.equals(actual))) {
+ throw new AssertionError("Expected <" + expected + "> but was <" + actual + '>');
+ }
+ }
+}