### Question:
PurchaseFlow implements CancellableRequestListener<PendingIntent> { void onActivityResult(int requestCode, int resultCode, Intent intent) { try { Check.equals(mRequestCode, requestCode); if (intent == null) { handleError(NULL_INTENT); return; } final int responseCode = intent.getIntExtra(EXTRA_RESPONSE, OK); if (resultCode != RESULT_OK || responseCode != OK) { handleError(responseCode); return; } final String data = intent.getStringExtra(EXTRA_PURCHASE_DATA); final String signature = intent.getStringExtra(EXTRA_PURCHASE_SIGNATURE); Check.isNotNull(data); Check.isNotNull(signature); final Purchase purchase = Purchase.fromJson(data, signature); mVerifier.verify(singletonList(purchase), new VerificationListener()); } catch (RuntimeException | JSONException e) { handleError(e); } } PurchaseFlow(@Nonnull IntentStarter intentStarter, int requestCode, @Nonnull RequestListener<Purchase> listener, @Nonnull PurchaseVerifier verifier); @Override void onSuccess(@Nonnull PendingIntent purchaseIntent); @Override void onError(int response, @Nonnull Exception e); @Override void cancel();  }### Answer:
@Test public void testShouldErrorIfIntentIsNull() throws Exception { mFlow.onActivityResult(1, 1, null); verifyError(ResponseCodes.NULL_INTENT, BillingException.class); }
@Test public void testShouldErrorIfRequestCodeIsDifferent() throws Exception { mFlow.onActivityResult(2, 1, new Intent()); verifyError(ResponseCodes.EXCEPTION, RuntimeException.class); }
@Test public void testShouldErrorIfResultCodeItNotOk() throws Exception { mFlow.onActivityResult(1, Activity.RESULT_CANCELED, new Intent()); verifyError(OK, BillingException.class); }
@Test public void testShouldErrorIfResponseCodeItNotOk() throws Exception { mFlow.onActivityResult(1, RESULT_OK, newIntent(ResponseCodes.ACCOUNT_ERROR, null, null)); verifyError(ResponseCodes.ACCOUNT_ERROR, BillingException.class); }
@Test public void testShouldErrorWithNoData() throws Exception { mFlow.onActivityResult(1, RESULT_OK, newIntent(OK, null, "signature")); verifyError(ResponseCodes.EXCEPTION, RuntimeException.class); }
@Test public void testShouldErrorWithNoSignature() throws Exception { mFlow.onActivityResult(1, RESULT_OK, newIntent(OK, "data", null)); verifyError(ResponseCodes.EXCEPTION, RuntimeException.class); }
@Test public void testShouldErrorWithEmptySignature() throws Exception { mFlow.onActivityResult(1, RESULT_OK, newIntent(OK, "{productId:'test', purchaseTime:1000}", "")); verifyError(ResponseCodes.WRONG_SIGNATURE, RuntimeException.class); }
@Test public void testShouldErrorIfVerificationFailed() throws Exception { Tests.mockVerifier(mVerifier, false); mFlow.onActivityResult(1, RESULT_OK, newIntent(OK, "{productId:'test', purchaseTime:1000}", "signature")); verifyError(ResponseCodes.WRONG_SIGNATURE, RuntimeException.class); }