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);
}
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);
}
Aggregations