DefaultInAppPurchaseConsumer implements InAppPurchaseConsumer<ManagedProduct> { @Override public boolean isConsumed(@NonNull ManagedProduct managedProduct, @NonNull PurchaseFamily purchaseFamily) { if (managedProduct instanceof ConsumablePurchase) { return consumableInAppPurchaseConsumer.isConsumed((ConsumablePurchase)managedProduct, purchaseFamily); } else if (managedProduct instanceof Subscription) { return subscriptionInAppPurchaseConsumer.isConsumed((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 isConsumedForConsumablePurchase() { defaultInAppPurchaseConsumer.isConsumed(consumablePurchase, PurchaseFamily.Ocr); verify(consumableInAppPurchaseConsumer).isConsumed(consumablePurchase, PurchaseFamily.Ocr); verifyZeroInteractions(subscriptionInAppPurchaseConsumer); }
@Test public void isConsumedForSubscription() { defaultInAppPurchaseConsumer.isConsumed(subscription, PurchaseFamily.Ocr); verify(subscriptionInAppPurchaseConsumer).isConsumed(subscription, PurchaseFamily.Ocr); verifyZeroInteractions(consumableInAppPurchaseConsumer); }