use of com.amplifyframework.predictions.result.IdentifyResult 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);
}
use of com.amplifyframework.predictions.result.IdentifyResult in project amplify-android by aws-amplify.
the class RxPredictionsBindingTest method testSuccessfulImageIdentification.
/**
* When the delegate of {@link RxPredictionsBinding#identify(IdentifyAction, Bitmap)} succeeds,
* the result should be propagated via the returned {@link Single}.
* @throws InterruptedException If interrupted while test observer is awaiting terminal event
*/
@Test
public void testSuccessfulImageIdentification() throws InterruptedException {
Bitmap bitmap = Bitmap.createBitmap(10, 10, Bitmap.Config.ALPHA_8);
IdentifyDocumentTextResult result = IdentifyDocumentTextResult.builder().fullText(RandomString.string()).keyValues(Collections.emptyList()).lines(Collections.emptyList()).rawLineText(Collections.emptyList()).selections(Collections.emptyList()).tables(Collections.emptyList()).words(Collections.emptyList()).build();
doAnswer(invocation -> {
// 0 = type, 1 = bitmap, 2 = result, 3 = error
final int indexOfResultConsumer = 2;
Consumer<IdentifyDocumentTextResult> onResult = invocation.getArgument(indexOfResultConsumer);
onResult.accept(result);
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.assertValue(result);
}
Aggregations