mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-23 15:55:49 +00:00
Add unit test for initUpdateForm method in PetController
This commit is contained in:
parent
74ce3d2818
commit
6ac57b9b15
1 changed files with 18 additions and 0 deletions
|
@ -103,4 +103,22 @@ class PetControllerTest {
|
|||
verify(model).put("pet", newPet);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Test initUpdateForm adds existing Pet to model")
|
||||
void testInitUpdateFormAddsExistingPetToModel() {
|
||||
Owner owner = org.mockito.Mockito.mock(Owner.class);
|
||||
Pet pet = new Pet();
|
||||
pet.setId(2);
|
||||
ModelMap model = org.mockito.Mockito.mock(ModelMap.class);
|
||||
|
||||
doReturn(pet).when(owner).getPet(2);
|
||||
|
||||
RedirectAttributes redirectAttributes = org.mockito.Mockito.mock(RedirectAttributes.class);
|
||||
String view = petController.initUpdateForm(owner, 2, model, redirectAttributes);
|
||||
|
||||
assertThat(view).isEqualTo("pets/createOrUpdatePetForm");
|
||||
verify(owner).getPet(2);
|
||||
verify(model).put("pet", pet);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue