/** * Returns a timing {@link TimerContext}, which measures an elapsed time in nanoseconds. * * @return a new {@link TimerContext} */ public TimerContext time() { return new TimerContext(this, clock); }
@Test public void testIndex() { clientTest = Mockito.spy(new MyClient()); //this is a field, which we mock IndexTimer indexTimerSpy = Mockito.spy(new IndexTimer()); //TimerContext we mock too TimerContext timerContextSpy = Mockito.spy(new TimerContext()); //IndexTimer.time returns our timer context Mockito.doReturn(timerContextSpy).when(indexTimerSpy).time(); //set indexTimer clientTest.setIndexTimer(indexTimerSpy); //calls method under test clientTest.index(null); //verify calls of methods Mockito.verify(indexTimerSpy).time(); Mockito.verify(timerContextSpy).stop(); // Prevent/stub logic when calling super.index(request) //Mockito.doNothing().when((YourSuperclass)clientTest).index(); }