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 empty result in OwnerController
This commit is contained in:
parent
764c1faed6
commit
4ebe0c6def
1 changed files with 18 additions and 0 deletions
|
@ -20,6 +20,8 @@ import org.springframework.test.web.servlet.MockMvc;
|
|||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.validation.BindingResult;
|
||||
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 java.util.List;
|
||||
|
||||
|
@ -147,4 +149,20 @@ class OwnerControllerTest {
|
|||
verify(ownerRepository).save(owner);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Test processFindForm with empty result")
|
||||
void testProcessFindFormWithEmptyResult() {
|
||||
Owner owner = new Owner();
|
||||
owner.setLastName("");
|
||||
|
||||
doReturn(Page.empty()).when(ownerRepository).findByLastName("", PageRequest.of(0, 5));
|
||||
|
||||
Model model = new ConcurrentModel();
|
||||
String view = ownerController.processFindForm(1, owner, result, model);
|
||||
|
||||
assertThat(view).isEqualTo("owners/findOwners");
|
||||
verify(ownerRepository).findByLastName("", PageRequest.of(0, 5));
|
||||
verify(result).rejectValue("lastName", "notFound", "not found");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue