This question has been asked before and I have tried their solution but that doesn't work for me, I am using MockMvc
to unit test content type of my rest call.
I am getting this exception:
java.lang.AssertionError: Content type not set
While I'm setting it in my search method using produces
attribute.
This is the method where I am initializing the mocks:
@Before
public void init() {
MockitoAnnotations.initMocks(this);
ReflectionTestUtils.setField(restController, "luceneSearchEnabled", true);
mockMvc = standaloneSetup(restController).build();
}
This is my test method:
@Test
public void pmmSearchContentTypeTest() throws Exception {
mockMvc
.perform(get("/api/v1/pmm").contentType(MediaType.APPLICATION_JSON))
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON_VALUE)
.andReturn();
}
This is my search method where I am setting content type:
@RequestMapping(value = "/api/" + REST_API_VERSION + "/" + ONE_INTERFACE, method = RequestMethod.GET, produces ={MediaType.APPLICATION_JSON_VALUE})
@ResponseBody
public String pmmSearch() { ... }
I don't know what is wrong here.