From 0a7e1ae9dd3357758592f74f545c18fae1e585ae Mon Sep 17 00:00:00 2001 From: Auto_EPMD-EDP AIAssistant Date: Fri, 25 Oct 2024 19:33:49 +0300 Subject: [PATCH] Add unit test for PetController.findOwner with valid ownerId --- .../petclinic/owner/PetControllerTest.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/test/java/org/springframework/samples/petclinic/owner/PetControllerTest.java b/src/test/java/org/springframework/samples/petclinic/owner/PetControllerTest.java index 1f7f190fb..6ddf9fa50 100644 --- a/src/test/java/org/springframework/samples/petclinic/owner/PetControllerTest.java +++ b/src/test/java/org/springframework/samples/petclinic/owner/PetControllerTest.java @@ -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() {