Mock nested method calls using Mockito in Spring Boot
Quite often you have a nested call chain to get a result in Java. Mocking these in a test is a little different than mocking just one call. I’m here going to show a solution to that. Say you have
Just another Tech blog from a forgetful mind
Quite often you have a nested call chain to get a result in Java. Mocking these in a test is a little different than mocking just one call. I’m here going to show a solution to that. Say you have
System under test class example: import my.special.sclient … class App { Sclient sclient = getNewSclient(); public String methodA(String input) { return sclient.getValue(input); } protected Sclient getNewSclient() { return new Sclient(); } } Test class example: import org.mockito.InjectMocks; import org.mockito.Spy; import