Let's quickly write a unit test checking for the JSON response and then add the test to BasicControllerTest:
@Test fun `GET welcome-with-object returns "Hello World"`() { mvc.perform( MockMvcRequestBuilders.get("/welcome-with-object") .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(content().string( containsString("Hello World"))); }
This test is very similar to the earlier unit test, except that we are using containsString to check whether the content contains an "Hello World" substring.