@@ -17,42 +17,63 @@ public class GreetControllerUnitTest {
17
17
18
18
@ BeforeEach
19
19
void setUp () {
20
- this .mockMvc = MockMvcBuilders .standaloneSetup (new GreetController ()).build ();
20
+ this .mockMvc = MockMvcBuilders .standaloneSetup (new GreetController ())
21
+ .build ();
21
22
}
22
23
23
24
@ Test
24
25
public void givenHomePageURI_whenMockMVC_thenReturnsIndexJSPViewName () throws Exception {
25
- this .mockMvc .perform (get ("/homePage" )).andExpect (view ().name ("index" ));
26
+ this .mockMvc .perform (get ("/homePage" ))
27
+ .andExpect (view ().name ("index" ));
26
28
}
27
29
28
30
@ Test
29
31
public void givenGreetURI_whenMockMVC_thenVerifyResponse () throws Exception {
30
- this .mockMvc .perform (get ("/greet" )).andExpect (status ().isOk ()).andExpect (content ().contentType (CONTENT_TYPE )).andExpect (jsonPath ("$.message" ).value ("Hello World!!!" ));
32
+ this .mockMvc .perform (get ("/greet" ))
33
+ .andExpect (status ().isOk ())
34
+ .andExpect (content ().contentType (CONTENT_TYPE ))
35
+ .andExpect (jsonPath ("$.message" ).value ("Hello World!!!" ));
31
36
}
32
37
33
38
@ Test
34
39
public void givenGreetURIWithPathVariable_whenMockMVC_thenVerifyResponse () throws Exception {
35
- this .mockMvc .perform (get ("/greetWithPathVariable/John" )).andExpect (status ().isOk ()).andExpect (content ().contentType (CONTENT_TYPE )).andExpect (jsonPath ("$.message" ).value ("Hello World John!!!" ));
40
+ this .mockMvc .perform (get ("/greetWithPathVariable/John" ))
41
+ .andExpect (status ().isOk ())
42
+ .andExpect (content ().contentType (CONTENT_TYPE ))
43
+ .andExpect (jsonPath ("$.message" ).value ("Hello World John!!!" ));
36
44
}
37
45
38
46
@ Test
39
47
public void givenGreetURIWithPathVariable_2_whenMockMVC_thenVerifyResponse () throws Exception {
40
- this .mockMvc .perform (get ("/greetWithPathVariable/{name}" , "Doe" )).andExpect (status ().isOk ()).andExpect (content ().contentType (CONTENT_TYPE )).andExpect (jsonPath ("$.message" ).value ("Hello World Doe!!!" ));
48
+ this .mockMvc .perform (get ("/greetWithPathVariable/{name}" , "Doe" ))
49
+ .andExpect (status ().isOk ())
50
+ .andExpect (content ().contentType (CONTENT_TYPE ))
51
+ .andExpect (jsonPath ("$.message" ).value ("Hello World Doe!!!" ));
41
52
}
42
53
43
54
@ Test
44
55
public void givenGreetURIWithQueryParameter_whenMockMVC_thenVerifyResponse () throws Exception {
45
- this .mockMvc .perform (get ("/greetWithQueryVariable" ).param ("name" , "John Doe" )).andDo (print ()).andExpect (status ().isOk ()).andExpect (content ().contentType (CONTENT_TYPE )).andExpect (jsonPath ("$.message" ).value ("Hello World John Doe!!!" ));
56
+ this .mockMvc .perform (get ("/greetWithQueryVariable" ).param ("name" , "John Doe" ))
57
+ .andExpect (status ().isOk ())
58
+ .andExpect (content ().contentType (CONTENT_TYPE ))
59
+ .andExpect (jsonPath ("$.message" ).value ("Hello World John Doe!!!" ));
46
60
}
47
61
48
62
@ Test
49
63
public void givenGreetURIWithPost_whenMockMVC_thenVerifyResponse () throws Exception {
50
- this .mockMvc .perform (post ("/greetWithPost" )).andDo (print ()).andExpect (status ().isOk ()).andExpect (content ().contentType (CONTENT_TYPE )).andExpect (jsonPath ("$.message" ).value ("Hello World!!!" ));
64
+ this .mockMvc .perform (post ("/greetWithPost" ))
65
+ .andExpect (status ().isOk ())
66
+ .andExpect (content ().contentType (CONTENT_TYPE ))
67
+ .andExpect (jsonPath ("$.message" ).value ("Hello World!!!" ));
51
68
}
52
69
53
70
@ Test
54
71
public void givenGreetURIWithPostAndFormData_whenMockMVC_thenVerifyResponse () throws Exception {
55
- this .mockMvc .perform (post ("/greetWithPostAndFormData" ).param ("id" , "1" ).param ("name" , "John Doe" )).andDo (print ()).andExpect (status ().isOk ()).andExpect (content ().contentType (CONTENT_TYPE ))
56
- .andExpect (jsonPath ("$.message" ).value ("Hello World John Doe!!!" )).andExpect (jsonPath ("$.id" ).value (1 ));
72
+ this .mockMvc .perform (post ("/greetWithPostAndFormData" ).param ("id" , "1" )
73
+ .param ("name" , "John Doe" ))
74
+ .andExpect (status ().isOk ())
75
+ .andExpect (content ().contentType (CONTENT_TYPE ))
76
+ .andExpect (jsonPath ("$.message" ).value ("Hello World John Doe!!!" ))
77
+ .andExpect (jsonPath ("$.id" ).value (1 ));
57
78
}
58
79
}
0 commit comments