Search in sources :

Example 1 with IdentifyResult

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);
}
Also used : Bitmap(android.graphics.Bitmap) IdentifyResult(com.amplifyframework.predictions.result.IdentifyResult) PredictionsException(com.amplifyframework.predictions.PredictionsException) Test(org.junit.Test)

Example 2 with IdentifyResult

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);
}
Also used : Bitmap(android.graphics.Bitmap) IdentifyResult(com.amplifyframework.predictions.result.IdentifyResult) IdentifyDocumentTextResult(com.amplifyframework.predictions.result.IdentifyDocumentTextResult) Test(org.junit.Test)

Aggregations

Bitmap (android.graphics.Bitmap)2 IdentifyResult (com.amplifyframework.predictions.result.IdentifyResult)2 Test (org.junit.Test)2 PredictionsException (com.amplifyframework.predictions.PredictionsException)1 IdentifyDocumentTextResult (com.amplifyframework.predictions.result.IdentifyDocumentTextResult)1