Add unit test for PetController.findOwner with valid ownerId

This commit is contained in:
Auto_EPMD-EDP AIAssistant 2024-10-25 19:33:49 +03:00
parent 9359be811a
commit 0a7e1ae9dd

View file

@ -71,6 +71,21 @@ class PetControllerTest {
verify(ownerRepository).findById(ownerId);
}
@Test
@DisplayName("Test findOwner with valid ownerId")
void testFindOwnerWithValidOwnerId() {
int ownerId = 1;
Owner owner = new Owner();
owner.setId(ownerId);
doReturn(owner).when(ownerRepository).findById(ownerId);
Owner foundOwner = petController.findOwner(ownerId);
assertThat(foundOwner).isNotNull();
assertThat(foundOwner.getId()).isEqualTo(ownerId);
verify(ownerRepository).findById(ownerId);
}
@Test
@DisplayName("Test findPet with null petId returns new Pet")
void testFindPetWithNullPetIdReturnsNewPet() {