DefaultInAppPurchaseConsumer implements InAppPurchaseConsumer<ManagedProduct> { @Override public Completable consumePurchase(@NonNull ManagedProduct managedProduct, @NonNull PurchaseFamily purchaseFamily) { if (managedProduct instanceof ConsumablePurchase) { return consumableInAppPurchaseConsumer.consumePurchase((ConsumablePurchase)managedProduct, purchaseFamily); } else if (managedProduct instanceof Subscription) { return subscriptionInAppPurchaseConsumer.consumePurchase((Subscription)managedProduct, purchaseFamily); } else { throw new IllegalArgumentException("Unsupported managed product type: " + managedProduct); } } @Inject  DefaultInAppPurchaseConsumer(@NonNull ConsumableInAppPurchaseConsumer consumableInAppPurchaseConsumer,
                                        @NonNull SubscriptionInAppPurchaseConsumer subscriptionInAppPurchaseConsumer); @Override boolean isConsumed(@NonNull ManagedProduct managedProduct, @NonNull PurchaseFamily purchaseFamily); @Override Completable consumePurchase(@NonNull ManagedProduct managedProduct, @NonNull PurchaseFamily purchaseFamily);  }
@Test public void consumePurchaseForConsumablePurchase() { defaultInAppPurchaseConsumer.consumePurchase(consumablePurchase, PurchaseFamily.Ocr); verify(consumableInAppPurchaseConsumer).consumePurchase(consumablePurchase, PurchaseFamily.Ocr); verifyZeroInteractions(subscriptionInAppPurchaseConsumer); }
@Test public void consumePurchaseForSubscription() { defaultInAppPurchaseConsumer.consumePurchase(subscription, PurchaseFamily.Ocr); verify(subscriptionInAppPurchaseConsumer).consumePurchase(subscription, PurchaseFamily.Ocr); verifyZeroInteractions(consumableInAppPurchaseConsumer); }