InputTimeoutDetector { public void startWaitingForFirstInput() { if (isSessionStarted()) { if (!isSpeechDetected()) { startWaitingForFirstInputTimestamp = getCurrentTimestamp(); if (logger.isTraceEnabled()) { logger.trace("startWaitingForFirstInput [startWaitingForFirstInputTimestamp=" + startWaitingForFirstInputTimestamp + "]"); } executor.schedule(new FirstInputTimeoutDetector(), firstInputTimeout, TimeUnit.NANOSECONDS); } else { if(logger.isTraceEnabled()) { logger.trace("startWaitingForFirstInput: We already have first input"); } } } else { logger.warn("startWaitingForFirstInput: Session is not started"); } } InputTimeoutDetector(final ListeningScheduledExecutorService executor); void startSession(final InputTimeoutListener listener, final long firstInputTimeout, final long maxInputTimeout, final long nextInputTimeout); void startWaitingForFirstInput(); void processInput(); long getIdleTimeInNanoseconds(); void stopSession(); boolean isSpeechDetected();  }
@Test public void testFirstInputTimeout() throws InterruptedException { startWaitingForFirstInput(true); final int timeToSleep = getSlightlyMoreThanHalf(FIRST_INPUT_TIMEOUT); expectedListenerCounter.verifyListener(); doNothing(timeToSleep); expectedListenerCounter.verifyListener(); doNothing(timeToSleep); expectedListenerCounter.incrementExpectedPreSpeechTimerCounter(); expectedListenerCounter.verifyListener(); }
@Test public void testNextInputTimeout() throws InterruptedException { startWaitingForFirstInput(true); expectedListenerCounter.verifyListener(); speakSomething(getSlightlyMoreThanHalf(MAX_INPUT_TIMEOUT)); expectedListenerCounter.verifyListener(); doNothing(NEXT_INPUT_TIMEOUT + EPSILON); expectedListenerCounter.incrementPostSpeechTimerCounter(); expectedListenerCounter.verifyListener(); }
@Test public void testMaxInputTimeout() throws InterruptedException { startWaitingForFirstInput(true); final int timeToSpeak = getSlightlyMoreThanHalf(MAX_INPUT_TIMEOUT); expectedListenerCounter.verifyListener(); speakSomething(timeToSpeak); expectedListenerCounter.verifyListener(); speakSomething(timeToSpeak); expectedListenerCounter.incrementMaximumRecognitionTimeCounter(); expectedListenerCounter.verifyListener(); }