Hi Everyone,
Ive been having a play the spring-test-mvc library and very impressed with it. I have one small issue in which I was hoping someone could help?
Im using mockito and am having problems with the MockHttpServletRequest.
My unit test
My issue is that mockito never matches the mocked request in the controller and returns null.Code:DefaultRequestBuilder requestBuilder = MockMvcRequestBuilders.post("/service/transactionKey") .header("Client-IP-Address", "192.168.0.1") .requestAttr("Application-Context", "something"); MockHttpServletRequest request = requestBuilder.buildRequest(wac.getServletContext()); when(requestHelper.getApplicationContext(request)).thenReturn(productApplicationContext); MvcResult mvcResult = mockMvc.perform(requestBuilder) .andDo(print()) .andReturn();
I would like it to return the productApplicationContext mocked object.Code:when(requestHelper.getApplicationContext(request)).thenReturn(productApplicationContext);
In my controller I have
Can anyone kindly give some advise? It appears the request in my unit test is not the request that the controllers receives.Code:@ResponseBody public Response createTransactionKey(final HttpServletRequest request) { final ProductApplicationContext applContext = requestHelper.getApplicationContext(request);


Reply With Quote