blob: d16674a8773d7320af53e0cf60ab73db4b2f6b4f [file] [log] [blame]
Clément Béra26a495c2022-03-15 13:43:12 +00001// Copyright (c) 2022, the R8 project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5package backport;
6
7import java.util.Objects;
8import java.util.function.Predicate;
9
10public final class PredicateBackportJava11Main {
11 public static void main(String[] args) {
12 testNot();
13 }
14
15 private static void testNot() {
16
17 Predicate<Object> isNull = Objects::isNull;
18 Predicate<Object> notNull = Predicate.not(isNull);
19
20 assertEquals(notNull.test(null), false);
21 assertEquals(notNull.test("something"), true);
22
23 try {
24 Predicate.not(null);
25 throw new AssertionError("Expected to throw NPE");
26 } catch (Throwable t) {
27 // Expected.
28 }
29 }
30
31 private static void assertEquals(Object expected, Object actual) {
32 if (expected != actual && (expected == null || !expected.equals(actual))) {
33 throw new AssertionError("Expected <" + expected + "> but was <" + actual + '>');
34 }
35 }
36}