How can you possibly write test case for boolean in mockito, spring mvc environment

mockito, spring-mvc, springmockito

Solution

All you need to do is the following:

mockMvc.perform(get("/reqMapping/methodName"))
                    .andExpect(status().isOk())
                    .andExpect(content().contentType("application/json;charset=UTF-8")) 
                    .andExpect(content().string("true");

The meat of the above code the is the `string` method of `ContentResultMatchers` (returned by `content()`).

Here is the relevant javadoc

Problem

How can I possibly write test case for boolean in mockito, spring mvc environment For e.g, like the following response ``` MockHttpServletResponse: Status = 200 Error message = null Headers = {Content-Type=[application/json;charset=UTF-8]} Content type = application/json;charset=UTF-8 Body = {"name":"myName","DOB":"12345"} Forwarded URL = null Redirected URL = null Cookies = [] ``` We would write the test case like, ``` mockMvc.perform(get("/reqMapping/methodName")) .andExpect(status().isOk()) .andExpect(content().contentType("application/json;charset=UTF-8")) .andExpect(jsonPath("$.name",comparesEqualTo("myName"); .andExpect(jsonPath("$.DOB",comparesEqualTo("12345"); ``` Right? But, when we got the response like follow ``` MockHttpServletResponse: Status = 200 Error message = null Headers = {Content-Type=[application/json;charset=UTF-8]} Content type = application/json;charset=UTF-8 **Body = true** Forwarded URL = null Redirected URL = null Cookies = [] ``` How should I write the test case? ``` mockMvc.perform(get("/reqMapping/methodName")) .andExpect(status().isOk()) .andExpect(content().contentType("application/json;charset=UTF-8")) .andExpect(???); ```

Original source