I use Mockito 1.9.5.while trying to mock a method that located in the service I'm testing. I know that it's not usual to mock methods of service that you are testing but that method is just a part of complex logic for fetching configuration from DB.
What I want to achieve is just
when ( mockService.isFatureActive () ).thenReturn ( false );
@RunWith ( MockitoJUnitRunner.class )
public class MockSpyTestService {
@Spy
@InjectMocks
private MockSpyTestService mockService = new MockSpyTestService ();
@Before
public void init () {
mockService.setObjectFactory ( new ObjectFactory () );
}
@Test
public void verifyMockService () {
when ( mockService.isFatureActive() ).thenReturn ( false ); //real isFatureActive() called
verify ( mockService, times ( 1 ) ).isFatureActive();
}
}
According to documentation that should work just fine. Instead I'm getting invocation of real method - isFatureActive()