Search in sources :

Example 31 with PredictionsException

use of com.amplifyframework.predictions.PredictionsException in project amplify-android by aws-amplify.

the class RxPredictionsBindingTest method testFailedTranslateText.

/**
 * When the delegate emits an error for the {@link RxPredictionsBinding#translateText(String)}
 * call, that error should be propagated via the returned {@link Single}.
 * @throws InterruptedException If interrupted while test observer is awaiting terminal event
 */
@Test
public void testFailedTranslateText() throws InterruptedException {
    String text = "Cat";
    PredictionsException predictionsException = new PredictionsException("Uh", "Oh");
    doAnswer(invocation -> {
        // 0 = text, 1 = result, 2 = error
        final int indexOfFailureConsumer = 2;
        Consumer<PredictionsException> onFailure = invocation.getArgument(indexOfFailureConsumer);
        onFailure.accept(predictionsException);
        return mock(TranslateTextOperation.class);
    }).when(delegate).translateText(eq(text), anyConsumer(), anyConsumer());
    TestObserver<TranslateTextResult> observer = rxPredictions.translateText(text).test();
    observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
    observer.assertError(predictionsException);
}
Also used : PredictionsException(com.amplifyframework.predictions.PredictionsException) RandomString(com.amplifyframework.testutils.random.RandomString) TranslateTextResult(com.amplifyframework.predictions.result.TranslateTextResult) Test(org.junit.Test)

Example 32 with PredictionsException

use of com.amplifyframework.predictions.PredictionsException in project amplify-android by aws-amplify.

the class RxPredictionsBindingTest method testFailedImageIdentification.

/**
 * When the delegate of {@link RxPredictionsBinding#identify(IdentifyAction, Bitmap)} fails,
 * the failure should be propagated via the returned {@link Single}.
 * @throws InterruptedException If interrupted while test observer is awaiting terminal event
 */
@Test
public void testFailedImageIdentification() throws InterruptedException {
    Bitmap bitmap = Bitmap.createBitmap(10, 10, Bitmap.Config.ALPHA_8);
    PredictionsException predictionsException = new PredictionsException("Uh", "Oh");
    doAnswer(invocation -> {
        // 0 = type, 1 = bitmap, 2 = result, 3 = error
        final int indexOfFailureConsumer = 3;
        Consumer<PredictionsException> onFailure = invocation.getArgument(indexOfFailureConsumer);
        onFailure.accept(predictionsException);
        return mock(IdentifyOperation.class);
    }).when(delegate).identify(eq(IdentifyActionType.DETECT_TEXT), eq(bitmap), anyConsumer(), anyConsumer());
    TestObserver<IdentifyResult> observer = rxPredictions.identify(IdentifyActionType.DETECT_TEXT, bitmap).test();
    observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
    observer.assertError(predictionsException);
}
Also used : Bitmap(android.graphics.Bitmap) IdentifyResult(com.amplifyframework.predictions.result.IdentifyResult) PredictionsException(com.amplifyframework.predictions.PredictionsException) Test(org.junit.Test)

Aggregations

PredictionsException (com.amplifyframework.predictions.PredictionsException)32 AmazonClientException (com.amazonaws.AmazonClientException)15 ArrayList (java.util.ArrayList)9 Image (com.amazonaws.services.rekognition.model.Image)6 Test (org.junit.Test)5 RectF (android.graphics.RectF)4 IdentifyEntitiesConfiguration (com.amplifyframework.predictions.aws.configuration.IdentifyEntitiesConfiguration)3 Sentiment (com.amplifyframework.predictions.models.Sentiment)3 InputStream (java.io.InputStream)3 DominantLanguage (com.amazonaws.services.comprehend.model.DominantLanguage)2 ComparedFace (com.amazonaws.services.rekognition.model.ComparedFace)2 ModerationLabel (com.amazonaws.services.rekognition.model.ModerationLabel)2 Document (com.amazonaws.services.textract.model.Document)2 SpeechGeneratorConfiguration (com.amplifyframework.predictions.aws.configuration.SpeechGeneratorConfiguration)2 CelebrityDetails (com.amplifyframework.predictions.models.CelebrityDetails)2 KeyPhrase (com.amplifyframework.predictions.models.KeyPhrase)2 Landmark (com.amplifyframework.predictions.models.Landmark)2 LanguageType (com.amplifyframework.predictions.models.LanguageType)2 Pose (com.amplifyframework.predictions.models.Pose)2 Syntax (com.amplifyframework.predictions.models.Syntax)2