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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)