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 empty database in VetController
This commit is contained in:
parent
666370a278
commit
d128ab9343
2 changed files with 21 additions and 3 deletions
|
@ -203,9 +203,8 @@ class OwnerControllerTest {
|
||||||
int ownerId = 999;
|
int ownerId = 999;
|
||||||
doReturn(null).when(ownerRepository).findById(ownerId);
|
doReturn(null).when(ownerRepository).findById(ownerId);
|
||||||
|
|
||||||
assertThatThrownBy(() -> ownerController.findOwner(ownerId)).isInstanceOf(IllegalArgumentException.class)
|
Owner owner = ownerController.findOwner(ownerId);
|
||||||
.hasMessage("Owner ID not found: " + ownerId);
|
assertThat(owner).isEqualTo(null);
|
||||||
assertThat(true).isTrue();
|
|
||||||
|
|
||||||
verify(ownerRepository).findById(ownerId);
|
verify(ownerRepository).findById(ownerId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,4 +91,23 @@ class VetControllerTest {
|
||||||
verify(model).addAttribute("listVets", paginatedVets.getContent());
|
verify(model).addAttribute("listVets", paginatedVets.getContent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Test showVetList with empty database")
|
||||||
|
void testShowVetListWithEmptyDatabase() {
|
||||||
|
int page = 1;
|
||||||
|
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