< prev index next >
test/jdk/java/util/Optional/BasicInt.java
Print this page
rev 48216 : 8140281: add no-arg Optional.orElseThrow() as preferred alternative to get()
Reviewed-by: XXX
*** 122,131 ****
--- 122,138 ----
OptionalInt empty = OptionalInt.empty();
int got = empty.orElseThrow(ObscureException::new);
}
+ @Test(expectedExceptions=NoSuchElementException.class)
+ public void testEmptyOrElseThrowNoArg() throws Exception {
+ OptionalInt empty = OptionalInt.empty();
+
+ int got = empty.orElseThrow();
+ }
+
@Test(groups = "unit")
public void testPresent() {
OptionalInt empty = OptionalInt.empty();
OptionalInt present = OptionalInt.of(1);
*** 135,145 ****
--- 142,154 ----
assertTrue(present.equals(OptionalInt.of(1)));
assertFalse(present.equals(empty));
assertTrue(Integer.hashCode(1) == present.hashCode());
assertFalse(present.toString().isEmpty());
assertTrue(-1 != present.toString().indexOf(Integer.toString(present.getAsInt()).toString()));
+ assertTrue(-1 != present.toString().indexOf(Integer.toString(present.orElseThrow()).toString()));
assertEquals(1, present.getAsInt());
+ assertEquals(1, present.orElseThrow());
AtomicBoolean presentCheck = new AtomicBoolean();
present.ifPresent(v -> presentCheck.set(true));
assertTrue(presentCheck.get());
presentCheck.set(false);
< prev index next >