Using Spring’s mockMvc, how do I check if the returned data contains part of a string?

Looks like you can pass a Hamcrest Matcher instead of a string there. Should be something like:

mockMvc.perform(get("/api/users/" + id))
    .andExpect(status().isOk())
    .andExpect(content().string(org.hamcrest.Matchers.containsString("{\"id\":\"" + id + "\"}"))); 

Leave a Comment

404 Not Found

Not Found

The requested URL was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.