public void testRun_noService() throws Exception {
    startTask(TextToSpeech.SUCCESS);

    // Run the announcement
    AndroidMock.replay(tts);
    task.run(null);
    AndroidMock.verify(mockTask, tts);
  }
  public void testRun_notReady() throws Exception {
    // Put task in "not ready" state
    startTask(TextToSpeech.ERROR);

    // Run the announcement
    AndroidMock.replay(tts);
    task.run(null);
    AndroidMock.verify(mockTask, tts);
  }
  public void testRun_whileRinging() throws Exception {
    startTask(TextToSpeech.SUCCESS);

    expect(tts.isSpeaking()).andStubReturn(false);

    // Run the announcement
    AndroidMock.replay(tts);
    PhoneStateListener phoneListener = phoneListenerCapture.getValue();
    phoneListener.onCallStateChanged(TelephonyManager.CALL_STATE_RINGING, null);
    task.run(null);
    AndroidMock.verify(mockTask, tts);
  }
  public void testRun_ringWhileSpeaking() throws Exception {
    startTask(TextToSpeech.SUCCESS);

    expect(tts.isSpeaking()).andStubReturn(true);
    expect(tts.stop()).andReturn(TextToSpeech.SUCCESS);

    AndroidMock.replay(tts);

    // Update the state to ringing - this should stop the current announcement.
    PhoneStateListener phoneListener = phoneListenerCapture.getValue();
    phoneListener.onCallStateChanged(TelephonyManager.CALL_STATE_RINGING, null);

    // Run the announcement - this should do nothing.
    task.run(null);

    AndroidMock.verify(mockTask, tts);
  }