diff --git a/patterns/design-patterns-behavioral/src/main/java/com/baeldung/nulls/UsingOptional.java b/patterns/design-patterns-behavioral/src/main/java/com/baeldung/nulls/UsingOptional.java index 099864589c..03bed5fedf 100644 --- a/patterns/design-patterns-behavioral/src/main/java/com/baeldung/nulls/UsingOptional.java +++ b/patterns/design-patterns-behavioral/src/main/java/com/baeldung/nulls/UsingOptional.java @@ -38,8 +38,8 @@ public class UsingOptional { .flatMap(list -> list.stream().findFirst()); } - private Optional getOptionalList() { - return Optional.ofNullable(getList()); + private Optional> getOptionalList() { + return Optional.of(getList()); } private String doSomething(boolean processed) { diff --git a/patterns/design-patterns-behavioral/src/test/java/com/baeldung/nulls/UsingOptionalUnitTest.java b/patterns/design-patterns-behavioral/src/test/java/com/baeldung/nulls/UsingOptionalUnitTest.java index 73797d48c8..576d2bacf3 100644 --- a/patterns/design-patterns-behavioral/src/test/java/com/baeldung/nulls/UsingOptionalUnitTest.java +++ b/patterns/design-patterns-behavioral/src/test/java/com/baeldung/nulls/UsingOptionalUnitTest.java @@ -19,22 +19,22 @@ class UsingOptionalUnitTest { } @Test - public void whenArgIsFalse_thenReturnEmptyResponse() { + void whenArgIsFalse_thenReturnEmptyResponse() { Optional result = dataObject.process(false); assertFalse(result.isPresent()); } @Test - public void whenArgIsTrue_thenReturnValidResponse() { + void whenArgIsTrue_thenReturnValidResponse() { Optional result = dataObject.process(true); assertTrue(result.isPresent()); } @Test - public void whenArgIsFalse_thenChainResponseAndThrowException() { - assertThrows(Exception.class, () -> dataObject.process(false).orElseThrow(() -> new Exception())); + void whenArgIsFalse_thenChainResponseAndThrowException() { + assertThrows(Exception.class, () -> dataObject.process(false).orElseThrow(Exception::new)); } @Test() @@ -51,7 +51,4 @@ class UsingOptionalUnitTest { void whenOptionalListFirst_returnsEmptyOptional() { assertFalse(dataObject.optionalListFirst().isPresent()); } - - - } \ No newline at end of file