update source code to sync with article

This commit is contained in:
amit.pandey
2020-04-18 20:57:13 +05:30
parent 21a8fe648e
commit 9332b64fd8
7 changed files with 86 additions and 30 deletions

View File

@@ -86,6 +86,15 @@ public class OptionalUnitTest {
Optional<String> opt = Optional.ofNullable(null);
String name = opt.get();
}
@Test
public void givenAnEmptyOptional_thenIsEmptyBehavesAsExpected() {
Optional<String> opt = Optional.of("Baeldung");
assertTrue(opt.isPresent());
opt = Optional.ofNullable(null);
assertFalse(opt.isPresent());
}
// Conditional Return With filter()
@Test