diff --git a/src/test/java/org/springframework/samples/petclinic/web/VetControllerTest.java b/src/test/java/org/springframework/samples/petclinic/web/VetControllerTest.java index a778727c..118fbcef 100644 --- a/src/test/java/org/springframework/samples/petclinic/web/VetControllerTest.java +++ b/src/test/java/org/springframework/samples/petclinic/web/VetControllerTest.java @@ -9,6 +9,8 @@ import org.springframework.samples.petclinic.model.Vet; import org.springframework.samples.petclinic.model.Vets; import org.springframework.samples.petclinic.service.ClinicService; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; import java.util.ArrayList; import java.util.List; @@ -19,6 +21,9 @@ import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; +import static org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder.*; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; @ExtendWith(MockitoExtension.class) class VetControllerTest { @@ -34,6 +39,8 @@ class VetControllerTest { List vetsList = new ArrayList<>(); + MockMvc mockMvc; + @BeforeEach void setUp() { @@ -41,6 +48,16 @@ void setUp() { vetsList.add(new Vet()); given(clinicService.findVets()).willReturn(vetsList); + + mockMvc = MockMvcBuilders.standaloneSetup(controller).build(); + } + + @Test + void testControllerShowVetList() throws Exception { + mockMvc.perform(get("/vets.html")) + .andExpect(status().isOk()) + .andExpect(model().attributeExists("vets")) //gets the model + .andExpect(view().name("vets/vetList")); //gets the view } @Test