11package com .baeldung .mvc .velocity .test ;
22
3- import static org .hamcrest .Matchers .allOf ;
4- import static org .hamcrest .Matchers .hasItem ;
5- import static org .hamcrest .Matchers .hasProperty ;
6- import static org .hamcrest .Matchers .hasSize ;
7- import static org .hamcrest .Matchers .is ;
8- import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .get ;
9- import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .model ;
10- import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .status ;
11- import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .view ;
12-
13- import java .util .Arrays ;
14-
3+ import com .baeldung .mvc .velocity .domain .Tutorial ;
4+ import com .baeldung .mvc .velocity .service .ITutorialsService ;
5+ import com .baeldung .mvc .velocity .service .TutorialsService ;
156import org .junit .Before ;
167import org .junit .Test ;
178import org .junit .runner .RunWith ;
2415import org .springframework .test .web .servlet .setup .MockMvcBuilders ;
2516import org .springframework .web .context .WebApplicationContext ;
2617
27- import com .baeldung .mvc .velocity .domain .Tutorial ;
28- import com .baeldung .mvc .velocity .service .ITutorialsService ;
29- import com .baeldung .mvc .velocity .service .TutorialsService ;
18+ import java .util .Arrays ;
19+
20+ import static org .hamcrest .Matchers .allOf ;
21+ import static org .hamcrest .Matchers .containsString ;
22+ import static org .hamcrest .Matchers .hasItem ;
23+ import static org .hamcrest .Matchers .hasProperty ;
24+ import static org .hamcrest .Matchers .hasSize ;
25+ import static org .hamcrest .Matchers .is ;
26+ import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .get ;
27+ import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .content ;
28+ import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .model ;
29+ import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .status ;
30+ import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .view ;
3031
3132@ RunWith (SpringJUnit4ClassRunner .class )
3233@ ContextConfiguration (locations = {"classpath:mvc-servlet.xml" })
@@ -52,8 +53,7 @@ public void setUp() {
5253
5354 @ Test
5455 public void testModel () throws Exception {
55-
56-
56+
5757 Mockito .when (tutServiceMock .listTutorials ()).thenReturn (Arrays .asList (
5858 new Tutorial (1 , "Guava" , "Introduction to Guava" , "GuavaAuthor" ),
5959 new Tutorial (2 , "Android" , "Introduction to Android" , "AndroidAuthor" )
@@ -62,6 +62,11 @@ public void testModel() throws Exception{
6262 mockMvc .perform (get ("/" ))
6363 .andExpect (status ().isOk ())
6464 .andExpect (view ().name ("index" ))
65+ .andExpect (content ().string (containsString ("GuavaAuthor" )))
66+ .andExpect (content ().string (containsString ("Introduction to Guava" )))
67+ .andExpect (content ().string (containsString ("AndroidAuthor" )))
68+ .andExpect (content ().string (containsString ("Introduction to Android" )))
69+ .andExpect (model ().attribute ("tutorials" , hasSize (2 )))
6570 .andExpect (model ().attribute ("tutorials" , hasSize (2 )))
6671 .andExpect (model ().attribute ("tutorials" , hasItem (
6772 allOf (
0 commit comments