PurchaseManager { @NonNull public Observable<Set<InAppPurchase>> getAllAvailablePurchaseSkus() { return getAllAvailablePurchases() .map(availablePurchases ->{ final Set<InAppPurchase> inAppPurchases = new HashSet<>(); for (final AvailablePurchase availablePurchase : availablePurchases) { inAppPurchases.add(availablePurchase.getInAppPurchase()); } return inAppPurchases; }); } @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 getAllAvailablePurchaseSkus() throws Exception { final Bundle getSubscriptionsResponse = new Bundle(); getSubscriptionsResponse.putInt("RESPONSE_CODE", RESULT_OK); getSubscriptionsResponse.putStringArrayList("DETAILS_LIST", new ArrayList<>(Collections.singletonList(getSkuDetails(InAppPurchase.SmartReceiptsPlus)))); when(inAppBillingService.getSkuDetails(eq(3), eq(packageName), eq("subs"), bundleCaptor.capture())).thenReturn(getSubscriptionsResponse); final Bundle getConsumablePurchasesResponse = new Bundle(); getConsumablePurchasesResponse.putInt("RESPONSE_CODE", RESULT_OK); getConsumablePurchasesResponse.putStringArrayList("DETAILS_LIST", new ArrayList<>(Collections.singletonList(getSkuDetails(InAppPurchase.OcrScans50)))); when(inAppBillingService.getSkuDetails(eq(3), eq(packageName), eq("inapp"), bundleCaptor.capture())).thenReturn(getConsumablePurchasesResponse); purchaseManager.getAllAvailablePurchaseSkus().test() .assertValue(new HashSet<>(Arrays.asList(InAppPurchase.SmartReceiptsPlus, InAppPurchase.OcrScans50))) .assertComplete() .assertNoErrors(); verify(purchaseWallet, never()).addLocalInAppPurchaseToWallet(any(ManagedProduct.class)); verify(purchaseWallet, never()).updateLocalInAppPurchasesInWallet(anySetOf(ManagedProduct.class)); }