22
33import com .baeldung .beanvalidation .application .controllers .UserController ;
44import com .baeldung .beanvalidation .application .repositories .UserRepository ;
5-
6- import java .nio .charset .Charset ;
7- import static org .assertj .core .api .Assertions .assertThat ;
85import org .hamcrest .core .Is ;
96import org .junit .Test ;
107import org .junit .runner .RunWith ;
1815import org .springframework .test .web .servlet .request .MockMvcRequestBuilders ;
1916import org .springframework .test .web .servlet .result .MockMvcResultMatchers ;
2017
18+ import java .nio .charset .Charset ;
19+
20+ import static org .assertj .core .api .Assertions .assertThat ;
21+
2122@ RunWith (SpringRunner .class )
2223@ WebMvcTest
2324@ AutoConfigureMockMvc
@@ -40,9 +41,9 @@ public void whenUserControllerInjected_thenNotNull() throws Exception {
4041 @ Test
4142 public void whenGetRequestToUsers_thenCorrectResponse () throws Exception {
4243 mockMvc .perform (MockMvcRequestBuilders .get ("/users" )
43- .contentType (MediaType .APPLICATION_JSON_UTF8 ))
44+ .contentType (MediaType .APPLICATION_JSON ))
4445 .andExpect (MockMvcResultMatchers .status ().isOk ())
45- .andExpect (MockMvcResultMatchers .content ().contentType (MediaType .APPLICATION_JSON_UTF8 ));
46+ .andExpect (MockMvcResultMatchers .content ().contentType (MediaType .APPLICATION_JSON ));
4647
4748 }
4849
@@ -52,7 +53,7 @@ public void whenPostRequestToUsersAndValidUser_thenCorrectResponse() throws Exce
5253 String user = "{\" name\" : \" bob\" , \" email\" : \" bob@domain.com\" }" ;
5354 mockMvc .perform (MockMvcRequestBuilders .post ("/users" )
5455 .content (user )
55- .contentType (MediaType .APPLICATION_JSON_UTF8 ))
56+ .contentType (MediaType .APPLICATION_JSON ))
5657 .andExpect (MockMvcResultMatchers .status ().isOk ())
5758 .andExpect (MockMvcResultMatchers .content ().contentType (textPlainUtf8 ));
5859 }
@@ -62,9 +63,9 @@ public void whenPostRequestToUsersAndInValidUser_thenCorrectReponse() throws Exc
6263 String user = "{\" name\" : \" \" , \" email\" : \" bob@domain.com\" }" ;
6364 mockMvc .perform (MockMvcRequestBuilders .post ("/users" )
6465 .content (user )
65- .contentType (MediaType .APPLICATION_JSON_UTF8 ))
66+ .contentType (MediaType .APPLICATION_JSON ))
6667 .andExpect (MockMvcResultMatchers .status ().isBadRequest ())
6768 .andExpect (MockMvcResultMatchers .jsonPath ("$.name" , Is .is ("Name is mandatory" )))
68- .andExpect (MockMvcResultMatchers .content ().contentType (MediaType .APPLICATION_JSON_UTF8 ));
69+ .andExpect (MockMvcResultMatchers .content ().contentType (MediaType .APPLICATION_JSON ));
6970 }
7071}
0 commit comments