File tree 1 file changed +17
-0
lines changed
src/test/java/org/springframework/samples/petclinic/web
1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change 9
9
import org .springframework .samples .petclinic .model .Vet ;
10
10
import org .springframework .samples .petclinic .model .Vets ;
11
11
import org .springframework .samples .petclinic .service .ClinicService ;
12
+ import org .springframework .test .web .servlet .MockMvc ;
13
+ import org .springframework .test .web .servlet .setup .MockMvcBuilders ;
12
14
13
15
import java .util .ArrayList ;
14
16
import java .util .List ;
19
21
import static org .mockito .ArgumentMatchers .anyString ;
20
22
import static org .mockito .BDDMockito .given ;
21
23
import static org .mockito .BDDMockito .then ;
24
+ import static org .springframework .test .web .servlet .request .MockHttpServletRequestBuilder .*;
25
+ import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .get ;
26
+ import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .*;
22
27
23
28
@ ExtendWith (MockitoExtension .class )
24
29
class VetControllerTest {
@@ -34,13 +39,25 @@ class VetControllerTest {
34
39
35
40
List <Vet > vetsList = new ArrayList <>();
36
41
42
+ MockMvc mockMvc ;
43
+
37
44
@ BeforeEach
38
45
void setUp () {
39
46
40
47
//given
41
48
vetsList .add (new Vet ());
42
49
43
50
given (clinicService .findVets ()).willReturn (vetsList );
51
+
52
+ mockMvc = MockMvcBuilders .standaloneSetup (controller ).build ();
53
+ }
54
+
55
+ @ Test
56
+ void testControllerShowVetList () throws Exception {
57
+ mockMvc .perform (get ("/vets.html" ))
58
+ .andExpect (status ().isOk ())
59
+ .andExpect (model ().attributeExists ("vets" )) //gets the model
60
+ .andExpect (view ().name ("vets/vetList" )); //gets the view
44
61
}
45
62
46
63
@ Test
You can’t perform that action at this time.
0 commit comments