diff --git a/core-java/src/test/java/com/baeldung/throwsexception/PersonRepositoryUnitTest.java b/core-java/src/test/java/com/baeldung/throwsexception/PersonRepositoryUnitTest.java index 0d1859fb1a..3749ce10d0 100644 --- a/core-java/src/test/java/com/baeldung/throwsexception/PersonRepositoryUnitTest.java +++ b/core-java/src/test/java/com/baeldung/throwsexception/PersonRepositoryUnitTest.java @@ -13,21 +13,31 @@ public class PersonRepositoryUnitTest { PersonRepository personRepository = new PersonRepository(); @Test - public void whenIdIsNull_thenExceptionIsThrown() throws Exception { - assertThrows(Exception.class, + public void whenIdIsNull_thenExceptionIsThrown() { + assertThrows(IllegalArgumentException.class, () -> Optional .ofNullable(personRepository.findNameById(null)) - .orElseThrow(Exception::new)); + .orElseThrow(IllegalArgumentException::new)); } @Test - public void whenIdIsNonNull_thenNoExceptionIsThrown() throws Exception { + public void whenIdIsNonNull_thenNoExceptionIsThrown() { assertAll( () -> Optional .ofNullable(personRepository.findNameById("id")) - .orElseThrow(Exception::new)); + .orElseThrow(RuntimeException::new)); + } + + @Test + public void whenIdNonNull_thenReturnsNameUpperCase() { + String name = Optional + .ofNullable(personRepository.findNameById("id")) + .map(String::toUpperCase) + .orElseThrow(RuntimeException::new); + + assertEquals("NAME", name); } @Test