1- package com .baeldung .intro ;
2-
3- import static org .hamcrest . Matchers . equalTo ;
4- import static org .springframework . test . web . servlet . result . MockMvcResultMatchers . content ;
5- import static org .springframework .test . web . servlet . result . MockMvcResultMatchers . status ;
6-
7- import org .junit . Test ;
8- import org .junit . runner . RunWith ;
9- import org .springframework .beans . factory . annotation . Autowired ;
10- import org .springframework .boot . test .autoconfigure . web .servlet .AutoConfigureMockMvc ;
11- import org .springframework .boot . test .context . SpringBootTest ;
12- import org . springframework . http . MediaType ;
13- import org .springframework . test . context . junit4 . SpringRunner ;
14- import org .springframework .test .web .servlet .MockMvc ;
15- import org .springframework .test .web .servlet .request . MockMvcRequestBuilders ;
16-
17- @ RunWith (SpringRunner .class )
18- @ SpringBootTest
19- @ AutoConfigureMockMvc
20- public class AppTest {
21-
22- @ Autowired
23- private MockMvc mvc ;
24-
25- @ Test
26- public void getIndex () throws Exception {
27- mvc .perform (MockMvcRequestBuilders .get ("/" ).accept (MediaType .APPLICATION_JSON ))
28- .andExpect (status ().isOk ())
29- .andExpect (content ().string (equalTo ("Index Page" )));
30- }
31-
32- @ Test
33- public void getLocal () throws Exception {
34- mvc .perform (MockMvcRequestBuilders .get ("/local" ).accept (MediaType .APPLICATION_JSON ))
35- .andExpect (status ().isOk ())
36- .andExpect (content ().string (equalTo ("/local" )));
37- }
38-
1+ package com .baeldung .intro ;
2+
3+ import org .junit . Test ;
4+ import org .junit . runner . RunWith ;
5+ import org .springframework .beans . factory . annotation . Autowired ;
6+ import org . springframework . boot . test . autoconfigure . web . servlet . AutoConfigureMockMvc ;
7+ import org .springframework . boot . test . context . SpringBootTest ;
8+ import org .springframework . http . MediaType ;
9+ import org .springframework .test . context . junit4 . SpringRunner ;
10+ import org .springframework .test .web .servlet .MockMvc ;
11+ import org .springframework .test .web . servlet . request . MockMvcRequestBuilders ;
12+
13+ import static org .hamcrest . Matchers . equalTo ;
14+ import static org .springframework .test .web .servlet .result . MockMvcResultMatchers . content ;
15+ import static org .springframework .test .web .servlet .result . MockMvcResultMatchers . status ;
16+
17+ @ RunWith (SpringRunner .class )
18+ @ SpringBootTest
19+ @ AutoConfigureMockMvc
20+ public class AppLiveTest {
21+
22+ @ Autowired
23+ private MockMvc mvc ;
24+
25+ @ Test
26+ public void getIndex () throws Exception {
27+ mvc .perform (MockMvcRequestBuilders .get ("/" ).accept (MediaType .APPLICATION_JSON ))
28+ .andExpect (status ().isOk ())
29+ .andExpect (content ().string (equalTo ("Index Page" )));
30+ }
31+
32+ @ Test
33+ public void getLocal () throws Exception {
34+ mvc .perform (MockMvcRequestBuilders .get ("/local" ).accept (MediaType .APPLICATION_JSON ))
35+ .andExpect (status ().isOk ())
36+ .andExpect (content ().string (equalTo ("/local" )));
37+ }
38+
3939}
0 commit comments