/** * Destroys previously created purchase flow. Nothing happens if flow has already been * destroyed. * * @param requestCode purchase request code */ public void destroyPurchaseFlow(int requestCode) { final PurchaseFlow flow = mFlows.get(requestCode); if (flow == null) { return; } mFlows.delete(requestCode); // instead of cancelling purchase request in `Billing` class (which we can't do as we don't // have `requestId`) let's cancel it here flow.cancel(); }
@Test public void testShouldNotCallListenerIfCancelled() throws Exception { Tests.mockVerifier(mVerifier, true); mFlow.cancel(); mFlow.onActivityResult(1, RESULT_OK, newOkIntent()); mFlow.onActivityResult(1, RESULT_OK, newIntent(ACCOUNT_ERROR, "{productId:'test', purchaseTime:1000}", "signature")); verify(mListener, never()).onError(anyInt(), any(Exception.class)); verify(mListener, never()).onSuccess(any(Purchase.class)); } }