Search in sources :

Example 76 with TextToSpeech

use of android.speech.tts.TextToSpeech in project robolectric by robolectric.

the class ShadowTextToSpeechTest method getOnInitListener_shouldReturnListener.

@Test
public void getOnInitListener_shouldReturnListener() {
    TextToSpeech.OnInitListener listener = result -> {
    };
    TextToSpeech textToSpeech = new TextToSpeech(activity, listener);
    assertThat(shadowOf(textToSpeech).getOnInitListener()).isEqualTo(listener);
}
Also used : Bundle(android.os.Bundle) Shadows(org.robolectric.Shadows) RunWith(org.junit.runner.RunWith) Config(org.robolectric.annotation.Config) UtteranceProgressListener(android.speech.tts.UtteranceProgressListener) HashMap(java.util.HashMap) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) AtomicReference(java.util.concurrent.atomic.AtomicReference) Shadows.shadowOf(org.robolectric.Shadows.shadowOf) LOLLIPOP(android.os.Build.VERSION_CODES.LOLLIPOP) ShadowLooper.shadowMainLooper(org.robolectric.shadows.ShadowLooper.shadowMainLooper) Voice(android.speech.tts.Voice) Locale(java.util.Locale) Engine(android.speech.tts.TextToSpeech.Engine) Before(org.junit.Before) ImmutableSet(com.google.common.collect.ImmutableSet) Robolectric(org.robolectric.Robolectric) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) File(java.io.File) Mockito.verify(org.mockito.Mockito.verify) Mockito.never(org.mockito.Mockito.never) TextToSpeech(android.speech.tts.TextToSpeech) Activity(android.app.Activity) Mockito.mock(org.mockito.Mockito.mock) TextToSpeech(android.speech.tts.TextToSpeech) Test(org.junit.Test)

Example 77 with TextToSpeech

use of android.speech.tts.TextToSpeech in project robolectric by robolectric.

the class ShadowTextToSpeechTest method getSpokenTextList_spoke_returnsSpokenTexts.

@Test
public void getSpokenTextList_spoke_returnsSpokenTexts() {
    TextToSpeech textToSpeech = new TextToSpeech(activity, result -> {
    });
    textToSpeech.speak("one", TextToSpeech.QUEUE_FLUSH, null);
    textToSpeech.speak("two", TextToSpeech.QUEUE_FLUSH, null);
    textToSpeech.speak("three", TextToSpeech.QUEUE_FLUSH, null);
    assertThat(shadowOf(textToSpeech).getSpokenTextList()).containsExactly("one", "two", "three");
}
Also used : TextToSpeech(android.speech.tts.TextToSpeech) Test(org.junit.Test)

Example 78 with TextToSpeech

use of android.speech.tts.TextToSpeech in project robolectric by robolectric.

the class ShadowTextToSpeechTest method synthesizeToFile_neverCalled_lastSynthesizeToFileTextNull.

@Test
@Config(minSdk = LOLLIPOP)
public void synthesizeToFile_neverCalled_lastSynthesizeToFileTextNull() {
    TextToSpeech textToSpeech = new TextToSpeech(activity, result -> {
    });
    assertThat(shadowOf(textToSpeech).getLastSynthesizeToFileText()).isNull();
}
Also used : TextToSpeech(android.speech.tts.TextToSpeech) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 79 with TextToSpeech

use of android.speech.tts.TextToSpeech in project robolectric by robolectric.

the class ShadowTextToSpeechTest method onInitListener_error.

@Test
public void onInitListener_error() {
    AtomicReference<Integer> onInitCalled = new AtomicReference<>();
    TextToSpeech.OnInitListener listener = onInitCalled::set;
    TextToSpeech textToSpeech = new TextToSpeech(activity, listener);
    assertThat(textToSpeech).isNotNull();
    Shadows.shadowOf(textToSpeech).getOnInitListener().onInit(TextToSpeech.ERROR);
    assertThat(onInitCalled.get()).isEqualTo(TextToSpeech.ERROR);
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) TextToSpeech(android.speech.tts.TextToSpeech) Test(org.junit.Test)

Example 80 with TextToSpeech

use of android.speech.tts.TextToSpeech in project robolectric by robolectric.

the class ShadowTextToSpeechTest method getLastSpokenText_shouldReturnSpokenText.

@Test
public void getLastSpokenText_shouldReturnSpokenText() {
    TextToSpeech textToSpeech = new TextToSpeech(activity, result -> {
    });
    textToSpeech.speak("Hello", TextToSpeech.QUEUE_FLUSH, null);
    assertThat(shadowOf(textToSpeech).getLastSpokenText()).isEqualTo("Hello");
}
Also used : TextToSpeech(android.speech.tts.TextToSpeech) Test(org.junit.Test)

Aggregations

TextToSpeech (android.speech.tts.TextToSpeech)103 Test (org.junit.Test)34 Locale (java.util.Locale)18 TtsEngines (android.speech.tts.TtsEngines)15 ActivityNotFoundException (android.content.ActivityNotFoundException)12 Intent (android.content.Intent)12 ContentResolver (android.content.ContentResolver)10 MissingResourceException (java.util.MissingResourceException)10 IntentFilter (android.content.IntentFilter)8 TextView (android.widget.TextView)7 Config (org.robolectric.annotation.Config)7 BluetoothAdapter (android.bluetooth.BluetoothAdapter)6 Handler (android.os.Handler)6 UtteranceProgressListener (android.speech.tts.UtteranceProgressListener)6 ArrayAdapter (android.widget.ArrayAdapter)6 Context (android.content.Context)5 HashMap (java.util.HashMap)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 Bundle (android.os.Bundle)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)3