3

I have been writing jUnit test for a while now, but novice to spring mvc controller testing. To be specific, I have a controller method which calls service method, service method interface & impl is outside webapp, which is nothing but a jar file. When I try to mock the same using mockito I get null as an output. The same holds good if service method ( Interface & Impl ) in same webapp.

Could you please let me know how do I mock the service which is outside webapp.

Below is my code :

@Mock
private FMService fService;

@InjectMocks
private FMController fmController;

testMethod() {
     when(SQ2Service.getListProblem(linkMap,serviceAccessParams)).thenReturn(listSQ);

}

call goes to controller successfully, but returns null when encounters the SQ2Service.getListProblem(linkMap,serviceAccessParams);

Aldeguer
  • 821
  • 9
  • 32
  • Please post your controller code. It will give me a better idea on what you are trying to achieve. – Indra Basak Oct 01 '17 at 03:16
  • Seems like spring test doesn't scan beens in the dependent jar. Take a look on this: https://stackoverflow.com/a/29571429/2065796 – Sasha Shpota Oct 01 '17 at 18:03

0 Answers0