1616import org .springframework .test .web .servlet .setup .MockMvcBuilders ;
1717import org .springframework .web .context .WebApplicationContext ;
1818
19- import java .nio .charset .Charset ;
20-
2119import static org .hamcrest .Matchers .equalTo ;
2220import static org .hamcrest .Matchers .hasSize ;
2321import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .jsonPath ;
@@ -39,31 +37,23 @@ public void setupMockMvc() {
3937
4038 @ Test
4139 public void givenRequestHasBeenMade_whenMeetsAllOfGivenConditions_thenCorrect () throws Exception {
42- MediaType contentType = new MediaType (MediaType .APPLICATION_JSON .getType (), MediaType .APPLICATION_JSON .getSubtype (), Charset .forName ("utf8" ));
43-
44- mockMvc .perform (MockMvcRequestBuilders .get ("/entity/all" )).andExpect (MockMvcResultMatchers .status ().isOk ()).andExpect (MockMvcResultMatchers .content ().contentType (contentType )).andExpect (jsonPath ("$" , hasSize (4 )));
40+ mockMvc .perform (MockMvcRequestBuilders .get ("/entity/all" )).andExpect (MockMvcResultMatchers .status ().isOk ()).andExpect (MockMvcResultMatchers .content ().contentType (MediaType .APPLICATION_JSON )).andExpect (jsonPath ("$" , hasSize (4 )));
4541 }
4642
4743 @ Test
4844 public void givenRequestHasBeenMade_whenMeetsFindByDateOfGivenConditions_thenCorrect () throws Exception {
49- MediaType contentType = new MediaType (MediaType .APPLICATION_JSON .getType (), MediaType .APPLICATION_JSON .getSubtype (), Charset .forName ("utf8" ));
50-
51- mockMvc .perform (MockMvcRequestBuilders .get ("/entity/findbydate/{date}" , "2011-12-03T10:15:30" )).andExpect (MockMvcResultMatchers .status ().isOk ()).andExpect (MockMvcResultMatchers .content ().contentType (contentType ))
45+ mockMvc .perform (MockMvcRequestBuilders .get ("/entity/findbydate/{date}" , "2011-12-03T10:15:30" )).andExpect (MockMvcResultMatchers .status ().isOk ()).andExpect (MockMvcResultMatchers .content ().contentType (MediaType .APPLICATION_JSON ))
5246 .andExpect (jsonPath ("$.id" , equalTo (1 )));
5347 }
5448
5549 @ Test
5650 public void givenRequestHasBeenMade_whenMeetsFindByModeOfGivenConditions_thenCorrect () throws Exception {
57- MediaType contentType = new MediaType (MediaType .APPLICATION_JSON .getType (), MediaType .APPLICATION_JSON .getSubtype (), Charset .forName ("utf8" ));
58-
59- mockMvc .perform (MockMvcRequestBuilders .get ("/entity/findbymode/{mode}" , Modes .ALPHA .name ())).andExpect (MockMvcResultMatchers .status ().isOk ()).andExpect (MockMvcResultMatchers .content ().contentType (contentType )).andExpect (jsonPath ("$.id" , equalTo (1 )));
51+ mockMvc .perform (MockMvcRequestBuilders .get ("/entity/findbymode/{mode}" , Modes .ALPHA .name ())).andExpect (MockMvcResultMatchers .status ().isOk ()).andExpect (MockMvcResultMatchers .content ().contentType (MediaType .APPLICATION_JSON )).andExpect (jsonPath ("$.id" , equalTo (1 )));
6052 }
6153
6254 @ Test
6355 public void givenRequestHasBeenMade_whenMeetsFindByVersionOfGivenConditions_thenCorrect () throws Exception {
64- MediaType contentType = new MediaType (MediaType .APPLICATION_JSON .getType (), MediaType .APPLICATION_JSON .getSubtype (), Charset .forName ("utf8" ));
65-
66- mockMvc .perform (MockMvcRequestBuilders .get ("/entity/findbyversion" ).header ("Version" , "1.0.0" )).andExpect (MockMvcResultMatchers .status ().isOk ()).andExpect (MockMvcResultMatchers .content ().contentType (contentType ))
56+ mockMvc .perform (MockMvcRequestBuilders .get ("/entity/findbyversion" ).header ("Version" , "1.0.0" )).andExpect (MockMvcResultMatchers .status ().isOk ()).andExpect (MockMvcResultMatchers .content ().contentType (MediaType .APPLICATION_JSON ))
6757 .andExpect (jsonPath ("$.id" , equalTo (1 )));
6858 }
6959}
0 commit comments