Mockito - internal method call
Try this:
@RunWith(MockitoJUnitRunner.class)
public class AvailabilityTest {
@InjectMocks
@Spy
private Availability availability = new Availability();
@Test
public void testGetStockLevelStage() {
Mockito.doReturn(expectedLong).when(availability).getStockLevelLimit();
availability.getStockLevelStage();
}
}
Here is an article I wrote on Mockito Spying if you need a further read.
if getStockLevelLimit()
has not to be executed during your test, it means in a some way you want to mock the class under test.
Doing it reduces the relevance and the authenticity of the behavior tested.
You should mock dependencies and not internal methods of the tested class.
I suppose you don't want to execute getStockLevelLimit()
because it uses external dependency that you want to isolate or something of similar.
So you should mock and isolate which is behind getStockLevelLimit()
and that doesn't make directly part of the Availability
class.