BAEL-2122 Optional or else throw (#5047)
* Throw and throws in Java * BAEL-2122 | throw exception in optional * BAEL-2122 | optional orelsethrow
This commit is contained in:
@@ -4,6 +4,7 @@ import org.junit.Test;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertAll;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
@@ -29,4 +30,14 @@ public class PersonRepositoryUnitTest {
|
||||
.orElseThrow(Exception::new));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenIdIsNonNull_thenShouldReturnNameUpperCase() throws Exception {
|
||||
String name = Optional
|
||||
.ofNullable(personRepository.findNameById("id"))
|
||||
.map(String::toUpperCase)
|
||||
.orElseThrow(Exception::new);
|
||||
|
||||
assertEquals("NAME", name);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user