PurchaseManager { @SuppressLint("CheckResult") @SuppressWarnings("ResultOfMethodCallIgnored") public void initialize(@NonNull Application application) { Logger.debug(PurchaseManager.this, "Initializing the purchase manager"); application.registerActivityLifecycleCallbacks(new PurchaseManagerActivityLifecycleCallbacks(this)); Observable.fromCallable(purchaseWallet::getActiveLocalInAppPurchases) .subscribeOn(subscribeOnScheduler) .subscribe(); getAllOwnedPurchases() .subscribeOn(subscribeOnScheduler) .subscribe(managedProducts -> Logger.debug(PurchaseManager.this, "Successfully initialized all user owned purchases {}.", managedProducts), throwable -> Logger.error(PurchaseManager.this, "Failed to initialize all user owned purchases.", throwable)); remoteSubscriptionManager.getNewRemoteSubscriptions() .subscribe(newInAppSubscriptions -> { for (RemoteSubscription newRemoteSubscription : newInAppSubscriptions) { for (final PurchaseEventsListener listener : listeners) { listener.onPurchaseSuccess(newRemoteSubscription.getInAppPurchase(), PurchaseSource.Remote); } } }, throwable -> Logger.error(this, "Failed to fetch our remote subscriptions")); } @Inject  PurchaseManager(@NonNull Context context,
                           @NonNull RemoteSubscriptionManager remoteSubscriptionManager,
                           @NonNull PurchaseWallet purchaseWallet,
                           @NonNull Analytics analytics); @VisibleForTesting  PurchaseManager(@NonNull Context context,
                    @NonNull RemoteSubscriptionManager remoteSubscriptionManager,
                    @NonNull PurchaseWallet purchaseWallet,
                    @NonNull Analytics analytics,
                    @NonNull Scheduler subscribeOnScheduler,
                    @NonNull Scheduler observeOnScheduler); void addEventListener(@NonNull PurchaseEventsListener listener); void removeEventListener(@NonNull PurchaseEventsListener listener); @SuppressLint("CheckResult") @SuppressWarnings("ResultOfMethodCallIgnored") void initialize(@NonNull Application application); void onActivityResumed(@NonNull Activity activity); void onActivityPaused(); void initiatePurchase(@NonNull final InAppPurchase inAppPurchase, @NonNull final PurchaseSource purchaseSource); @VisibleForTesting void sendMockPurchaseRequest(@NonNull InAppPurchase inAppPurchase); boolean onActivityResult(int requestCode, int resultCode, @Nullable Intent data); @NonNull Observable<Set<ManagedProduct>> getAllOwnedPurchases(); @NonNull Observable<Set<AvailablePurchase>> getAllAvailablePurchases(); @NonNull Observable<Set<InAppPurchase>> getAllAvailablePurchaseSkus(); @NonNull Completable consumePurchase(@NonNull final ConsumablePurchase consumablePurchase); static final int REQUEST_CODE; }
@Test public void onCreate() { purchaseManager.initialize(application); verifyInAppBillingServiceConnected(); verify(purchaseWallet).getActiveLocalInAppPurchases(); }
@Test public void initializeSubscriptionsThrowsRemoteException() throws Exception { when(inAppBillingService.getPurchases(3, packageName, "subs", null)).thenThrow(new RemoteException()); final Bundle getConsumablePurchasesResponse = new Bundle(); getConsumablePurchasesResponse.putInt("RESPONSE_CODE", RESULT_OK); getConsumablePurchasesResponse.putStringArrayList("INAPP_PURCHASE_ITEM_LIST", new ArrayList<>()); getConsumablePurchasesResponse.putStringArrayList("INAPP_PURCHASE_DATA_LIST", new ArrayList<>()); getConsumablePurchasesResponse.putStringArrayList("INAPP_DATA_SIGNATURE_LIST", new ArrayList<>()); when(inAppBillingService.getPurchases(3, packageName, "inapp", null)).thenReturn(getConsumablePurchasesResponse); purchaseManager.initialize(application); verifyInAppBillingServiceConnected(); verify(purchaseWallet).getActiveLocalInAppPurchases(); }
@Test public void initializeConsumablePurchasesThrowsRemoteException() throws Exception { final Bundle getSubscriptionsResponse = new Bundle(); getSubscriptionsResponse.putInt("RESPONSE_CODE", RESULT_OK); getSubscriptionsResponse.putStringArrayList("INAPP_PURCHASE_ITEM_LIST", new ArrayList<>()); getSubscriptionsResponse.putStringArrayList("INAPP_PURCHASE_DATA_LIST", new ArrayList<>()); getSubscriptionsResponse.putStringArrayList("INAPP_DATA_SIGNATURE_LIST", new ArrayList<>()); when(inAppBillingService.getPurchases(3, packageName, "subs", null)).thenReturn(getSubscriptionsResponse); when(inAppBillingService.getPurchases(3, packageName, "inapp", null)).thenThrow(new RemoteException()); purchaseManager.initialize(application); verifyInAppBillingServiceConnected(); verify(purchaseWallet).getActiveLocalInAppPurchases(); }
@Test public void initializeSubscriptionsHasResponseError() throws Exception { final Bundle getSubscriptionsResponse = new Bundle(); getSubscriptionsResponse.putInt("RESPONSE_CODE", RESULT_ERROR); when(inAppBillingService.getPurchases(3, packageName, "subs", null)).thenReturn(getSubscriptionsResponse); final Bundle getConsumablePurchasesResponse = new Bundle(); getConsumablePurchasesResponse.putInt("RESPONSE_CODE", RESULT_OK); getConsumablePurchasesResponse.putStringArrayList("INAPP_PURCHASE_ITEM_LIST", new ArrayList<>()); getConsumablePurchasesResponse.putStringArrayList("INAPP_PURCHASE_DATA_LIST", new ArrayList<>()); getConsumablePurchasesResponse.putStringArrayList("INAPP_DATA_SIGNATURE_LIST", new ArrayList<>()); when(inAppBillingService.getPurchases(3, packageName, "inapp", null)).thenReturn(getConsumablePurchasesResponse); purchaseManager.initialize(application); verifyInAppBillingServiceConnected(); verify(purchaseWallet).getActiveLocalInAppPurchases(); }
@Test public void initializeConsumablePurchasesHasResponseError() throws Exception { final Bundle getSubscriptionsResponse = new Bundle(); getSubscriptionsResponse.putInt("RESPONSE_CODE", RESULT_OK); getSubscriptionsResponse.putStringArrayList("INAPP_PURCHASE_ITEM_LIST", new ArrayList<>()); getSubscriptionsResponse.putStringArrayList("INAPP_PURCHASE_DATA_LIST", new ArrayList<>()); getSubscriptionsResponse.putStringArrayList("INAPP_DATA_SIGNATURE_LIST", new ArrayList<>()); when(inAppBillingService.getPurchases(3, packageName, "subs", null)).thenReturn(getSubscriptionsResponse); final Bundle getConsumablePurchasesResponse = new Bundle(); getConsumablePurchasesResponse.putInt("RESPONSE_CODE", RESULT_ERROR); when(inAppBillingService.getPurchases(3, packageName, "inapp", null)).thenReturn(getConsumablePurchasesResponse); purchaseManager.initialize(application); verifyInAppBillingServiceConnected(); verify(purchaseWallet).getActiveLocalInAppPurchases(); }
@Test public void initializeWithNoneOwned() throws Exception { final Bundle getSubscriptionsResponse = new Bundle(); getSubscriptionsResponse.putInt("RESPONSE_CODE", RESULT_OK); getSubscriptionsResponse.putStringArrayList("INAPP_PURCHASE_ITEM_LIST", new ArrayList<>()); getSubscriptionsResponse.putStringArrayList("INAPP_PURCHASE_DATA_LIST", new ArrayList<>()); getSubscriptionsResponse.putStringArrayList("INAPP_DATA_SIGNATURE_LIST", new ArrayList<>()); when(inAppBillingService.getPurchases(3, packageName, "subs", null)).thenReturn(getSubscriptionsResponse); final Bundle getConsumablePurchasesResponse = new Bundle(); getConsumablePurchasesResponse.putInt("RESPONSE_CODE", RESULT_OK); getConsumablePurchasesResponse.putStringArrayList("INAPP_PURCHASE_ITEM_LIST", new ArrayList<>()); getConsumablePurchasesResponse.putStringArrayList("INAPP_PURCHASE_DATA_LIST", new ArrayList<>()); getConsumablePurchasesResponse.putStringArrayList("INAPP_DATA_SIGNATURE_LIST", new ArrayList<>()); when(inAppBillingService.getPurchases(3, packageName, "inapp", null)).thenReturn(getConsumablePurchasesResponse); purchaseManager.initialize(application); verifyInAppBillingServiceConnected(); verify(purchaseWallet).updateLocalInAppPurchasesInWallet(updateManagedProductsCaptor.capture()); when(purchaseWallet.getActiveLocalInAppPurchases()).thenReturn(updateManagedProductsCaptor.getValue()); assertEquals(Collections.<ManagedProduct>emptySet(), updateManagedProductsCaptor.getValue()); verify(purchaseWallet, times(2)).getActiveLocalInAppPurchases(); verifyNoMoreInteractions(purchaseWallet); }
@Test public void initializeWithCancelledConsumablePurchase() throws Exception { final Bundle getSubscriptionsResponse = new Bundle(); getSubscriptionsResponse.putInt("RESPONSE_CODE", RESULT_OK); getSubscriptionsResponse.putStringArrayList("INAPP_PURCHASE_ITEM_LIST", new ArrayList<>()); getSubscriptionsResponse.putStringArrayList("INAPP_PURCHASE_DATA_LIST", new ArrayList<>()); getSubscriptionsResponse.putStringArrayList("INAPP_DATA_SIGNATURE_LIST", new ArrayList<>()); when(inAppBillingService.getPurchases(3, packageName, "subs", null)).thenReturn(getSubscriptionsResponse); final Bundle getConsumablePurchasesResponse = new Bundle(); getConsumablePurchasesResponse.putInt("RESPONSE_CODE", RESULT_OK); getConsumablePurchasesResponse.putStringArrayList("INAPP_PURCHASE_ITEM_LIST", new ArrayList<>(Collections.singletonList(getInAppPurchaseItem(InAppPurchase.OcrScans50)))); getConsumablePurchasesResponse.putStringArrayList("INAPP_PURCHASE_DATA_LIST", new ArrayList<>(Collections.singletonList(getInAppPurchaseData(InAppPurchase.OcrScans50, PURCHASE_STATE_CANCELLED)))); getConsumablePurchasesResponse.putStringArrayList("INAPP_DATA_SIGNATURE_LIST", new ArrayList<>(Collections.singletonList(getInAppDataSignature()))); when(inAppBillingService.getPurchases(3, packageName, "inapp", null)).thenReturn(getConsumablePurchasesResponse); purchaseManager.initialize(application); verifyInAppBillingServiceConnected(); verify(purchaseWallet).updateLocalInAppPurchasesInWallet(updateManagedProductsCaptor.capture()); when(purchaseWallet.getActiveLocalInAppPurchases()).thenReturn(updateManagedProductsCaptor.getValue()); assertEquals(Collections.<ManagedProduct>emptySet(), updateManagedProductsCaptor.getValue()); verify(purchaseWallet, times(2)).getActiveLocalInAppPurchases(); verifyNoMoreInteractions(purchaseWallet); }
@Test public void initializeWithCancelledSubscription() throws Exception { final Bundle getSubscriptionsResponse = new Bundle(); getSubscriptionsResponse.putInt("RESPONSE_CODE", RESULT_OK); getSubscriptionsResponse.putStringArrayList("INAPP_PURCHASE_ITEM_LIST", new ArrayList<>(Collections.singletonList(getInAppPurchaseItem(InAppPurchase.SmartReceiptsPlus)))); getSubscriptionsResponse.putStringArrayList("INAPP_PURCHASE_DATA_LIST", new ArrayList<>(Collections.singletonList(getInAppPurchaseData(InAppPurchase.SmartReceiptsPlus, PURCHASE_STATE_CANCELLED)))); getSubscriptionsResponse.putStringArrayList("INAPP_DATA_SIGNATURE_LIST", new ArrayList<>(Collections.singletonList(getInAppDataSignature()))); when(inAppBillingService.getPurchases(3, packageName, "subs", null)).thenReturn(getSubscriptionsResponse); final Bundle getConsumablePurchasesResponse = new Bundle(); getConsumablePurchasesResponse.putInt("RESPONSE_CODE", RESULT_OK); getConsumablePurchasesResponse.putStringArrayList("INAPP_PURCHASE_ITEM_LIST", new ArrayList<>()); getConsumablePurchasesResponse.putStringArrayList("INAPP_PURCHASE_DATA_LIST", new ArrayList<>()); getConsumablePurchasesResponse.putStringArrayList("INAPP_DATA_SIGNATURE_LIST", new ArrayList<>()); when(inAppBillingService.getPurchases(3, packageName, "inapp", null)).thenReturn(getConsumablePurchasesResponse); purchaseManager.initialize(application); verifyInAppBillingServiceConnected(); verify(purchaseWallet).updateLocalInAppPurchasesInWallet(updateManagedProductsCaptor.capture()); when(purchaseWallet.getActiveLocalInAppPurchases()).thenReturn(updateManagedProductsCaptor.getValue()); assertEquals(Collections.<ManagedProduct>emptySet(), updateManagedProductsCaptor.getValue()); verify(purchaseWallet, times(2)).getActiveLocalInAppPurchases(); verifyNoMoreInteractions(purchaseWallet); }
@Test public void initializeWithRefundedConsumablePurchase() throws Exception { final Bundle getSubscriptionsResponse = new Bundle(); getSubscriptionsResponse.putInt("RESPONSE_CODE", RESULT_OK); getSubscriptionsResponse.putStringArrayList("INAPP_PURCHASE_ITEM_LIST", new ArrayList<>()); getSubscriptionsResponse.putStringArrayList("INAPP_PURCHASE_DATA_LIST", new ArrayList<>()); getSubscriptionsResponse.putStringArrayList("INAPP_DATA_SIGNATURE_LIST", new ArrayList<>()); when(inAppBillingService.getPurchases(3, packageName, "subs", null)).thenReturn(getSubscriptionsResponse); final Bundle getConsumablePurchasesResponse = new Bundle(); getConsumablePurchasesResponse.putInt("RESPONSE_CODE", RESULT_OK); getConsumablePurchasesResponse.putStringArrayList("INAPP_PURCHASE_ITEM_LIST", new ArrayList<>(Collections.singletonList(getInAppPurchaseItem(InAppPurchase.OcrScans50)))); getConsumablePurchasesResponse.putStringArrayList("INAPP_PURCHASE_DATA_LIST", new ArrayList<>(Collections.singletonList(getInAppPurchaseData(InAppPurchase.OcrScans50, PURCHASE_STATE_REFUNDED)))); getConsumablePurchasesResponse.putStringArrayList("INAPP_DATA_SIGNATURE_LIST", new ArrayList<>(Collections.singletonList(getInAppDataSignature()))); when(inAppBillingService.getPurchases(3, packageName, "inapp", null)).thenReturn(getConsumablePurchasesResponse); purchaseManager.initialize(application); verifyInAppBillingServiceConnected(); verify(purchaseWallet).updateLocalInAppPurchasesInWallet(updateManagedProductsCaptor.capture()); when(purchaseWallet.getActiveLocalInAppPurchases()).thenReturn(updateManagedProductsCaptor.getValue()); assertEquals(Collections.<ManagedProduct>emptySet(), updateManagedProductsCaptor.getValue()); verify(purchaseWallet, times(2)).getActiveLocalInAppPurchases(); verifyNoMoreInteractions(purchaseWallet); }
@Test public void initializeWithRefundedSubscription() throws Exception { final Bundle getSubscriptionsResponse = new Bundle(); getSubscriptionsResponse.putInt("RESPONSE_CODE", RESULT_OK); getSubscriptionsResponse.putStringArrayList("INAPP_PURCHASE_ITEM_LIST", new ArrayList<>(Collections.singletonList(getInAppPurchaseItem(InAppPurchase.SmartReceiptsPlus)))); getSubscriptionsResponse.putStringArrayList("INAPP_PURCHASE_DATA_LIST", new ArrayList<>(Collections.singletonList(getInAppPurchaseData(InAppPurchase.SmartReceiptsPlus, PURCHASE_STATE_REFUNDED)))); getSubscriptionsResponse.putStringArrayList("INAPP_DATA_SIGNATURE_LIST", new ArrayList<>(Collections.singletonList(getInAppDataSignature()))); when(inAppBillingService.getPurchases(3, packageName, "subs", null)).thenReturn(getSubscriptionsResponse); final Bundle getConsumablePurchasesResponse = new Bundle(); getConsumablePurchasesResponse.putInt("RESPONSE_CODE", RESULT_OK); getConsumablePurchasesResponse.putStringArrayList("INAPP_PURCHASE_ITEM_LIST", new ArrayList<>()); getConsumablePurchasesResponse.putStringArrayList("INAPP_PURCHASE_DATA_LIST", new ArrayList<>()); getConsumablePurchasesResponse.putStringArrayList("INAPP_DATA_SIGNATURE_LIST", new ArrayList<>()); when(inAppBillingService.getPurchases(3, packageName, "inapp", null)).thenReturn(getConsumablePurchasesResponse); purchaseManager.initialize(application); verifyInAppBillingServiceConnected(); verify(purchaseWallet).updateLocalInAppPurchasesInWallet(updateManagedProductsCaptor.capture()); when(purchaseWallet.getActiveLocalInAppPurchases()).thenReturn(updateManagedProductsCaptor.getValue()); assertEquals(Collections.<ManagedProduct>emptySet(), updateManagedProductsCaptor.getValue()); verify(purchaseWallet, times(2)).getActiveLocalInAppPurchases(); verifyNoMoreInteractions(purchaseWallet); }
@Test public void initializeWithConsumablePurchasesOwned() throws Exception { final Bundle getSubscriptionsResponse = new Bundle(); getSubscriptionsResponse.putInt("RESPONSE_CODE", RESULT_OK); getSubscriptionsResponse.putStringArrayList("INAPP_PURCHASE_ITEM_LIST", new ArrayList<>()); getSubscriptionsResponse.putStringArrayList("INAPP_PURCHASE_DATA_LIST", new ArrayList<>()); getSubscriptionsResponse.putStringArrayList("INAPP_DATA_SIGNATURE_LIST", new ArrayList<>()); when(inAppBillingService.getPurchases(3, packageName, "subs", null)).thenReturn(getSubscriptionsResponse); final Bundle getConsumablePurchasesResponse = new Bundle(); getConsumablePurchasesResponse.putInt("RESPONSE_CODE", RESULT_OK); getConsumablePurchasesResponse.putStringArrayList("INAPP_PURCHASE_ITEM_LIST", new ArrayList<>(Collections.singletonList(getInAppPurchaseItem(InAppPurchase.OcrScans50)))); getConsumablePurchasesResponse.putStringArrayList("INAPP_PURCHASE_DATA_LIST", new ArrayList<>(Collections.singletonList(getInAppPurchaseData(InAppPurchase.OcrScans50, PURCHASE_STATE_PURCHASED)))); getConsumablePurchasesResponse.putStringArrayList("INAPP_DATA_SIGNATURE_LIST", new ArrayList<>(Collections.singletonList(getInAppDataSignature()))); when(inAppBillingService.getPurchases(3, packageName, "inapp", null)).thenReturn(getConsumablePurchasesResponse); purchaseManager.initialize(application); verifyInAppBillingServiceConnected(); final ManagedProduct consumablePurchase = new ConsumablePurchase(InAppPurchase.OcrScans50, getInAppPurchaseData(InAppPurchase.OcrScans50, PURCHASE_STATE_PURCHASED), PURCHASE_TOKEN, IN_APP_DATA_SIGNATURE); verify(purchaseWallet).updateLocalInAppPurchasesInWallet(updateManagedProductsCaptor.capture()); when(purchaseWallet.getActiveLocalInAppPurchases()).thenReturn(updateManagedProductsCaptor.getValue()); assertEquals(Collections.singleton(consumablePurchase), updateManagedProductsCaptor.getValue()); verify(purchaseWallet, times(2)).getActiveLocalInAppPurchases(); verifyNoMoreInteractions(purchaseWallet); }
@Test public void initializeWithSubscriptionsOwned() throws Exception { final Bundle getSubscriptionsResponse = new Bundle(); getSubscriptionsResponse.putInt("RESPONSE_CODE", RESULT_OK); getSubscriptionsResponse.putStringArrayList("INAPP_PURCHASE_ITEM_LIST", new ArrayList<>(Collections.singletonList(getInAppPurchaseItem(InAppPurchase.SmartReceiptsPlus)))); getSubscriptionsResponse.putStringArrayList("INAPP_PURCHASE_DATA_LIST", new ArrayList<>(Collections.singletonList(getInAppPurchaseData(InAppPurchase.SmartReceiptsPlus, PURCHASE_STATE_PURCHASED)))); getSubscriptionsResponse.putStringArrayList("INAPP_DATA_SIGNATURE_LIST", new ArrayList<>(Collections.singletonList(getInAppDataSignature()))); when(inAppBillingService.getPurchases(3, packageName, "subs", null)).thenReturn(getSubscriptionsResponse); final Bundle getConsumablePurchasesResponse = new Bundle(); getConsumablePurchasesResponse.putInt("RESPONSE_CODE", RESULT_OK); getConsumablePurchasesResponse.putStringArrayList("INAPP_PURCHASE_ITEM_LIST", new ArrayList<>()); getConsumablePurchasesResponse.putStringArrayList("INAPP_PURCHASE_DATA_LIST", new ArrayList<>()); getConsumablePurchasesResponse.putStringArrayList("INAPP_DATA_SIGNATURE_LIST", new ArrayList<>()); when(inAppBillingService.getPurchases(3, packageName, "inapp", null)).thenReturn(getConsumablePurchasesResponse); purchaseManager.initialize(application); verifyInAppBillingServiceConnected(); final ManagedProduct subscription = new Subscription(InAppPurchase.SmartReceiptsPlus, getInAppPurchaseData(InAppPurchase.SmartReceiptsPlus, PURCHASE_STATE_PURCHASED), PURCHASE_TOKEN, IN_APP_DATA_SIGNATURE); verify(purchaseWallet).updateLocalInAppPurchasesInWallet(updateManagedProductsCaptor.capture()); when(purchaseWallet.getActiveLocalInAppPurchases()).thenReturn(updateManagedProductsCaptor.getValue()); assertEquals(Collections.singleton(subscription), updateManagedProductsCaptor.getValue()); verify(purchaseWallet, times(2)).getActiveLocalInAppPurchases(); verifyNoMoreInteractions(purchaseWallet); }
@Test public void initializeWithSubscriptionsAndConsumablePurchasesOwned() throws Exception { final Bundle getSubscriptionsResponse = new Bundle(); getSubscriptionsResponse.putInt("RESPONSE_CODE", RESULT_OK); getSubscriptionsResponse.putStringArrayList("INAPP_PURCHASE_ITEM_LIST", new ArrayList<>(Collections.singletonList(getInAppPurchaseItem(InAppPurchase.SmartReceiptsPlus)))); getSubscriptionsResponse.putStringArrayList("INAPP_PURCHASE_DATA_LIST", new ArrayList<>(Collections.singletonList(getInAppPurchaseData(InAppPurchase.SmartReceiptsPlus, PURCHASE_STATE_PURCHASED)))); getSubscriptionsResponse.putStringArrayList("INAPP_DATA_SIGNATURE_LIST", new ArrayList<>(Collections.singletonList(getInAppDataSignature()))); when(inAppBillingService.getPurchases(3, packageName, "subs", null)).thenReturn(getSubscriptionsResponse); final Bundle getConsumablePurchasesResponse = new Bundle(); getConsumablePurchasesResponse.putInt("RESPONSE_CODE", RESULT_OK); getConsumablePurchasesResponse.putStringArrayList("INAPP_PURCHASE_ITEM_LIST", new ArrayList<>(Collections.singletonList(getInAppPurchaseItem(InAppPurchase.OcrScans50)))); getConsumablePurchasesResponse.putStringArrayList("INAPP_PURCHASE_DATA_LIST", new ArrayList<>(Collections.singletonList(getInAppPurchaseData(InAppPurchase.OcrScans50, PURCHASE_STATE_PURCHASED)))); getConsumablePurchasesResponse.putStringArrayList("INAPP_DATA_SIGNATURE_LIST", new ArrayList<>(Collections.singletonList(getInAppDataSignature()))); when(inAppBillingService.getPurchases(3, packageName, "inapp", null)).thenReturn(getConsumablePurchasesResponse); purchaseManager.initialize(application); verifyInAppBillingServiceConnected(); final ManagedProduct subscription = new Subscription(InAppPurchase.SmartReceiptsPlus, getInAppPurchaseData(InAppPurchase.SmartReceiptsPlus, PURCHASE_STATE_PURCHASED), PURCHASE_TOKEN, IN_APP_DATA_SIGNATURE); final ManagedProduct consumablePurchase = new ConsumablePurchase(InAppPurchase.OcrScans50, getInAppPurchaseData(InAppPurchase.OcrScans50, PURCHASE_STATE_PURCHASED), PURCHASE_TOKEN, IN_APP_DATA_SIGNATURE); verify(purchaseWallet).updateLocalInAppPurchasesInWallet(updateManagedProductsCaptor.capture()); when(purchaseWallet.getActiveLocalInAppPurchases()).thenReturn(updateManagedProductsCaptor.getValue()); assertEquals(new HashSet<>(Arrays.asList(subscription, consumablePurchase)), updateManagedProductsCaptor.getValue()); verify(purchaseWallet, times(2)).getActiveLocalInAppPurchases(); verifyNoMoreInteractions(purchaseWallet); }
@Test public void initializeWithNewRemoteSubscriptions() throws Exception { RemoteSubscription mockSubscription = mock(RemoteSubscription.class); when(mockSubscription.getInAppPurchase()).thenReturn(InAppPurchase.SmartReceiptsPlus); when(remoteSubscriptionManager.getNewRemoteSubscriptions()).thenReturn(Observable.just(Collections.singleton(mockSubscription))); purchaseManager.initialize(application); verifyInAppBillingServiceConnected(); verify(listener1).onPurchaseSuccess(InAppPurchase.SmartReceiptsPlus, PurchaseSource.Remote); verify(listener2).onPurchaseSuccess(InAppPurchase.SmartReceiptsPlus, PurchaseSource.Remote); verifyZeroInteractions(listener3); }