JAVA-4669: Code cleanup for UsingOptional

This commit is contained in:
Krzysztof Woyke 2021-03-20 20:43:49 +01:00
parent d1a87c711b
commit 01e95b4df0
2 changed files with 6 additions and 9 deletions

View File

@ -38,8 +38,8 @@ public class UsingOptional {
.flatMap(list -> list.stream().findFirst());
}
private Optional<List> getOptionalList() {
return Optional.ofNullable(getList());
private Optional<List<String>> getOptionalList() {
return Optional.of(getList());
}
private String doSomething(boolean processed) {

View File

@ -19,22 +19,22 @@ class UsingOptionalUnitTest {
}
@Test
public void whenArgIsFalse_thenReturnEmptyResponse() {
void whenArgIsFalse_thenReturnEmptyResponse() {
Optional<Object> result = dataObject.process(false);
assertFalse(result.isPresent());
}
@Test
public void whenArgIsTrue_thenReturnValidResponse() {
void whenArgIsTrue_thenReturnValidResponse() {
Optional<Object> 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());
}
}