Jake Wharton | 801cb3e | 2019-12-12 23:35:29 -0500 | [diff] [blame] | 1 | // Copyright (c) 2019, 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 | |
| 5 | package backport; |
| 6 | |
| 7 | import java.util.OptionalInt; |
| 8 | |
| 9 | public final class OptionalIntBackportJava11Main { |
| 10 | |
| 11 | public static void main(String[] args) { |
| 12 | testIsEmpty(); |
| 13 | } |
| 14 | |
| 15 | private static void testIsEmpty() { |
| 16 | OptionalInt present = OptionalInt.of(2); |
| 17 | assertFalse(present.isEmpty()); |
| 18 | |
| 19 | OptionalInt absent = OptionalInt.empty(); |
| 20 | assertTrue(absent.isEmpty()); |
| 21 | } |
| 22 | |
| 23 | private static void assertTrue(boolean value) { |
| 24 | if (!value) { |
| 25 | throw new AssertionError("Expected <true> but was <false>"); |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | private static void assertFalse(boolean value) { |
| 30 | if (value) { |
| 31 | throw new AssertionError("Expected <false> but was <true>"); |
| 32 | } |
| 33 | } |
| 34 | } |