JAVA-4669: Code cleanup for UsingOptional
This commit is contained in:
parent
d1a87c711b
commit
01e95b4df0
|
@ -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) {
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue