mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-20 06:45:50 +00:00
Add unit test for findOwner method in PetController to handle IllegalArgumentException scenario
This commit is contained in:
parent
69cdebe4e7
commit
605eedff8e
1 changed files with 15 additions and 0 deletions
|
@ -17,6 +17,8 @@ import java.util.Collection;
|
|||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@DisplayName("PetController Tests")
|
||||
|
@ -52,4 +54,17 @@ class PetControllerTest {
|
|||
verify(ownerRepository).findPetTypes();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Test findOwner throws IllegalArgumentException")
|
||||
void testFindOwnerThrowsIllegalArgumentException() {
|
||||
int ownerId = 999;
|
||||
doThrow(new IllegalArgumentException()).when(ownerRepository).findById(ownerId);
|
||||
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> {
|
||||
petController.findOwner(ownerId);
|
||||
});
|
||||
|
||||
verify(ownerRepository).findById(ownerId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue