mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-20 06:45:50 +00:00
Add unit test for showVetList method in VetController with page 2 and empty result
This commit is contained in:
parent
54aef7ab64
commit
1484e2f55b
1 changed files with 19 additions and 0 deletions
|
@ -110,4 +110,23 @@ class VetControllerTest {
|
|||
verify(model).addAttribute("listVets", paginatedVets.getContent());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Test showVetList with page 2 and empty result")
|
||||
void testShowVetListWithPage2AndEmptyResult() {
|
||||
int page = 2;
|
||||
Pageable pageable = PageRequest.of(page - 1, 5);
|
||||
Page<Vet> paginatedVets = new PageImpl<>(Collections.emptyList(), pageable, 0);
|
||||
|
||||
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