Merge pull request #10574 from kwoyke/JAVA-4669
JAVA-4669: Code cleanup for UsingOptional
This commit is contained in:
commit
45764829f7
|
@ -38,8 +38,8 @@ public class UsingOptional {
|
||||||
.flatMap(list -> list.stream().findFirst());
|
.flatMap(list -> list.stream().findFirst());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Optional<List> getOptionalList() {
|
private Optional<List<String>> getOptionalList() {
|
||||||
return Optional.ofNullable(getList());
|
return Optional.of(getList());
|
||||||
}
|
}
|
||||||
|
|
||||||
private String doSomething(boolean processed) {
|
private String doSomething(boolean processed) {
|
||||||
|
|
|
@ -19,22 +19,22 @@ class UsingOptionalUnitTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenArgIsFalse_thenReturnEmptyResponse() {
|
void whenArgIsFalse_thenReturnEmptyResponse() {
|
||||||
Optional<Object> result = dataObject.process(false);
|
Optional<Object> result = dataObject.process(false);
|
||||||
|
|
||||||
assertFalse(result.isPresent());
|
assertFalse(result.isPresent());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenArgIsTrue_thenReturnValidResponse() {
|
void whenArgIsTrue_thenReturnValidResponse() {
|
||||||
Optional<Object> result = dataObject.process(true);
|
Optional<Object> result = dataObject.process(true);
|
||||||
|
|
||||||
assertTrue(result.isPresent());
|
assertTrue(result.isPresent());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenArgIsFalse_thenChainResponseAndThrowException() {
|
void whenArgIsFalse_thenChainResponseAndThrowException() {
|
||||||
assertThrows(Exception.class, () -> dataObject.process(false).orElseThrow(() -> new Exception()));
|
assertThrows(Exception.class, () -> dataObject.process(false).orElseThrow(Exception::new));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test()
|
@Test()
|
||||||
|
@ -51,7 +51,4 @@ class UsingOptionalUnitTest {
|
||||||
void whenOptionalListFirst_returnsEmptyOptional() {
|
void whenOptionalListFirst_returnsEmptyOptional() {
|
||||||
assertFalse(dataObject.optionalListFirst().isPresent());
|
assertFalse(dataObject.optionalListFirst().isPresent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue