mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-20 06:45:50 +00:00
Add unit test for showVetList with non-empty paginated results in VetController
This commit is contained in:
parent
45d0528d7e
commit
a68a2596cc
1 changed files with 20 additions and 0 deletions
|
@ -71,4 +71,24 @@ class VetControllerTest {
|
|||
verify(model).addAttribute("listVets", paginatedVets.getContent());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Test showVetList with non-empty paginated result")
|
||||
void testShowVetListWithNonEmptyPagination() {
|
||||
int page = 1;
|
||||
Pageable pageable = PageRequest.of(page - 1, 5);
|
||||
Vet vet = new Vet();
|
||||
Page<Vet> paginatedVets = new PageImpl<>(Collections.singletonList(vet), pageable, 1);
|
||||
|
||||
doReturn(paginatedVets).when(vetRepository).findAll(pageable);
|
||||
|
||||
String viewName = vetController.showVetList(page, model);
|
||||
|
||||
assertThat(viewName).isEqualTo("vets/vetList");
|
||||
verify(vetRepository).findAll(pageable);
|
||||
verify(model).addAttribute("currentPage", page);
|
||||
verify(model).addAttribute("totalPages", paginatedVets.getTotalPages());
|
||||
verify(model).addAttribute("totalItems", paginatedVets.getTotalElements());
|
||||
verify(model).addAttribute("listVets", paginatedVets.getContent());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue