BAEL4640 Find First with Optional (#10142)
* BAEL4640 Find First with Optional * BAEL4640 Fixes for review comments * BAEL4640 Removing blank lines * BAEL4640 Removing blank lines * BAEL4640 Changes for 8.3 Optional.flatMap Co-authored-by: Chirag Dewan <chirag.dewan@ericsson.com>
This commit is contained in:
+23
-8
@@ -11,32 +11,47 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class UsingOptionalUnitTest {
|
||||
|
||||
private UsingOptional classUnderTest;
|
||||
private UsingOptional dataObject;
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
classUnderTest = new UsingOptional();
|
||||
dataObject = new UsingOptional();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenArgIsFalse_thenReturnEmptyResponse() {
|
||||
|
||||
Optional<Object> result = classUnderTest.process(false);
|
||||
Optional<Object> result = dataObject.process(false);
|
||||
|
||||
assertFalse(result.isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenArgIsTrue_thenReturnValidResponse() {
|
||||
|
||||
Optional<Object> result = classUnderTest.process(true);
|
||||
Optional<Object> result = dataObject.process(true);
|
||||
|
||||
assertTrue(result.isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenArgIsFalse_thenChainResponseAndThrowException() {
|
||||
|
||||
assertThrows(Exception.class, () -> classUnderTest.process(false).orElseThrow(() -> new Exception()));
|
||||
assertThrows(Exception.class, () -> dataObject.process(false).orElseThrow(() -> new Exception()));
|
||||
}
|
||||
|
||||
@Test()
|
||||
void givenEmptyList_whenFindFirst_getDefaultValue() {
|
||||
assertTrue(dataObject.findFirst().equalsIgnoreCase(UsingOptional.DEFAULT_VALUE));
|
||||
}
|
||||
|
||||
@Test()
|
||||
void givenEmptyList_whenFindOptionalFirst_returnsEmptyOptional() {
|
||||
assertFalse(dataObject.findOptionalFirst().isPresent());
|
||||
}
|
||||
|
||||
@Test()
|
||||
void whenOptionalListFirst_returnsEmptyOptional() {
|
||||
assertFalse(dataObject.optionalListFirst().isPresent());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user