mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-20 06:45:50 +00:00
Add unit test for processFindForm with multiple results in OwnerController
This commit is contained in:
parent
3717a2b115
commit
74e791dcaa
1 changed files with 22 additions and 0 deletions
|
@ -23,6 +23,7 @@ import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
|||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Page;
|
||||
import java.util.ArrayList;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -165,4 +166,25 @@ class OwnerControllerTest {
|
|||
verify(result).rejectValue("lastName", "notFound", "not found");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Test processFindForm with multiple results")
|
||||
void testProcessFindFormWithMultipleResults() {
|
||||
Owner owner = new Owner();
|
||||
owner.setLastName("Doe");
|
||||
|
||||
List<Owner> owners = new ArrayList<>();
|
||||
owners.add(new Owner());
|
||||
owners.add(new Owner());
|
||||
Page<Owner> page = new PageImpl<>(owners);
|
||||
|
||||
doReturn(page).when(ownerRepository).findByLastName("Doe", PageRequest.of(0, 5));
|
||||
|
||||
Model model = new ConcurrentModel();
|
||||
String view = ownerController.processFindForm(1, owner, result, model);
|
||||
|
||||
assertThat(view).isEqualTo("owners/ownersList");
|
||||
assertThat(model.asMap().get("listOwners")).isNotNull();
|
||||
verify(ownerRepository).findByLastName("Doe", PageRequest.of(0, 5));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue