I have a controller
@Controller
public class SomeController extends BaseController {
@RequestMapping(method=POST, value="/something")
public @ResponseBody SomeReturnType createReturnType(@Requestbody SomeReqBody someReqBody, Object obj) {
return someMethod(someReqBody,"SomeString");
}
public SomeReturnType someMethod(SomeReqBody someReqBody, String someString) {
return someProtectedMethodFromBaseController(someReqBody, someString);
}
}
I need to test the method createReturnType()
using JUnit and Mockito. So I wrote some piece of code in test class as follows :
@RunWith(MockitoJunitRunner.class)
public class testSomeController {
@Mock
SomeController someControllerMock = new SomeController();
@Test
public void test createReturnType() {
SomeReqBody someReqBody = mockRequestBody();
SomeReturnType someReturnType = mockRetruntype();
Object someObject = mockObject();
when(someControllerMock.someMethod(someReqBody,"SomeString")).thenReturn(someReturnType);
SomeReturnType returnTypeExp = someControllerMock.createReturnType(someReqBody, someObject);
assertNotNull(returnTypeExp);
}
}
Now the problem is that everything works fine in the test except the expected result is always null
. I couldn't find where I did things wrong. Can someone figure out the problem?