I am testing a todo controller using MockMVC:
mockMvc.perform(MockMvcRequestBuilders.get("/toDos/")
.with(user("user").password("password").roles("ADMIN"))
.content("{ \"saved_date\": \"2010-01-01\"}")
.accept(MediaType.APPLICATION_JSON_VALUE))
.andExpect((ResultMatcher) jsonPath("$.id").doesNotExist())
.andExpect(status().isOk())
.andExpect( content().contentType("application/json"));
}
I keep getting this error:
java.lang.ClassCastException: org.springframework.test.web.client.match.JsonPathRequestMatchers$5 cannot be cast to org.springframework.test.web.servlet.ResultMatcher
I want to delete the cast to (ResultMatcher) , but don't know how to create a ResultMatcher that tests the presence of Id. Any ideas ?
I think you want to use:
org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath
... instead of:
org.springframework.test.web.client.match.MockMvcResultMatchers.jsonPath
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With