OptionalUtil { public static Object unwrap(Object potentiallyOptional) { if (potentiallyOptional instanceof Optional<?>) { return unwrap((Optional<?>) potentiallyOptional); } else { return potentiallyOptional; } } private  OptionalUtil(); static Object unwrap(Object potentiallyOptional); static T unwrap(@SuppressWarnings("OptionalUsedAsFieldOrParameterType") Optional<T> optional); static Integer unwrap(@SuppressWarnings("OptionalUsedAsFieldOrParameterType") OptionalInt optional); static Boolean unwrap(OptionalBoolean optional); static Long unwrap(@SuppressWarnings("OptionalUsedAsFieldOrParameterType") OptionalLong optional); static Double unwrap(@SuppressWarnings("OptionalUsedAsFieldOrParameterType") OptionalDouble optional); static OptionalLong ofNullable(Long l); static OptionalInt ofNullable(Integer i); static OptionalDouble ofNullable(Double d); static OptionalBoolean ofNullable(Boolean b); static OptionalLong parseLong(String value); static OptionalInt parseInt(String value); static OptionalDouble parseDouble(String value); static OptionalBoolean parseBoolean(String value);  }
@Test void unwrap() { assertEquals("string", OptionalUtil.unwrap("string")); assertEquals("string", OptionalUtil.unwrap((Object) Optional.of("string"))); assertEquals("string", OptionalUtil.unwrap(Optional.of("string"))); assertEquals(1, OptionalUtil.unwrap(OptionalInt.of(1))); assertEquals(1, OptionalUtil.unwrap(OptionalLong.of(1))); assertEquals(1, OptionalUtil.unwrap(OptionalDouble.of(1))); assertEquals(true, OptionalUtil.unwrap(OptionalBoolean.of(true))); assertNull(OptionalUtil.unwrap((Optional<Object>) null)); assertNull(OptionalUtil.unwrap((OptionalInt) null)); assertNull(OptionalUtil.unwrap((OptionalLong) null)); assertNull(OptionalUtil.unwrap((OptionalDouble) null)); assertNull(OptionalUtil.unwrap((OptionalBoolean) null)); assertNull(OptionalUtil.unwrap(Optional.empty())); assertNull(OptionalUtil.unwrap(OptionalInt.empty())); assertNull(OptionalUtil.unwrap(OptionalLong.empty())); assertNull(OptionalUtil.unwrap(OptionalDouble.empty())); assertNull(OptionalUtil.unwrap(OptionalBoolean.empty())); }