I'm trying to make a simple test using spring boot.
mockMvc.perform(post("/user")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(userJohn)))
.andExpect(jsonPath("$[0].username", is("bob")));
Using this import for the jsonPath:
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
I get:
andExpect (org.springframework.test.web.servlet.ResultMatcher) in ResultActions cannot be applied to (org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath)
If i try to cast it to (ResultMatcher) i get:
java.lang.ClassCastException: org.springframework.test.web.servlet.result.JsonPathResultMatchers cannot be cast to org.springframework.test.web.servlet.ResultMatcher
I'm using the version 2.0.4 of Spring boot. Any ideas of what can be the problem?
Thanks
try it:
mockMvc.perform(post("/user")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(userJohn)))
.andExpect(jsonPath("$[0].username").value("bob"));
I don't know when these changes. see more :
https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/test/web/servlet/result/JsonPathResultMatchers.html
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