PlusPurchaseWallet extends DefaultPurchaseWallet { @Override public synchronized boolean hasActivePurchase(@NonNull InAppPurchase inAppPurchase) { if (inAppPurchase == InAppPurchase.SmartReceiptsPlus) { return true; } else { return super.hasActivePurchase(inAppPurchase); } } @Inject  PlusPurchaseWallet(@NonNull Lazy<SharedPreferences> preferences); @Override synchronized boolean hasActivePurchase(@NonNull InAppPurchase inAppPurchase);  }
@Test public void emptyPurchases() { assertTrue(plusPurchaseWallet.hasActivePurchase(InAppPurchase.SmartReceiptsPlus)); assertNull(plusPurchaseWallet.getLocalInAppManagedProduct(InAppPurchase.SmartReceiptsPlus)); assertFalse(plusPurchaseWallet.hasActivePurchase(InAppPurchase.OcrScans50)); assertNull(plusPurchaseWallet.getLocalInAppManagedProduct(InAppPurchase.OcrScans50)); assertEquals(plusPurchaseWallet.getActiveLocalInAppPurchases(), Collections.emptySet()); }
@Test public void singlePurchase() { plusPurchaseWallet.addLocalInAppPurchaseToWallet(managedProduct); assertTrue(plusPurchaseWallet.hasActivePurchase(InAppPurchase.SmartReceiptsPlus)); assertNull(plusPurchaseWallet.getLocalInAppManagedProduct(InAppPurchase.SmartReceiptsPlus)); assertTrue(plusPurchaseWallet.hasActivePurchase(InAppPurchase.OcrScans50)); assertEquals(managedProduct, plusPurchaseWallet.getLocalInAppManagedProduct(InAppPurchase.OcrScans50)); assertEquals(plusPurchaseWallet.getActiveLocalInAppPurchases(), Collections.singleton(managedProduct)); assertEquals(preferences.getStringSet("key_sku_set", Collections.<String>emptySet()), Collections.singleton(InAppPurchase.OcrScans50.getSku())); assertEquals(preferences.getString("ocr_purchase_1_purchaseData", null), this.purchaseData); assertEquals(preferences.getString("ocr_purchase_1_inAppDataSignature", null), IN_APP_DATA_SIGNATURE); }
@Test public void updatePurchases() { plusPurchaseWallet.updateLocalInAppPurchasesInWallet(Collections.singleton(managedProduct)); assertTrue(plusPurchaseWallet.hasActivePurchase(InAppPurchase.SmartReceiptsPlus)); assertTrue(plusPurchaseWallet.hasActivePurchase(InAppPurchase.OcrScans50)); assertEquals(plusPurchaseWallet.getActiveLocalInAppPurchases(), Collections.singleton(managedProduct)); assertEquals(preferences.getStringSet("key_sku_set", Collections.<String>emptySet()), Collections.singleton(InAppPurchase.OcrScans50.getSku())); assertEquals(preferences.getString("ocr_purchase_1_purchaseData", null), this.purchaseData); assertEquals(preferences.getString("ocr_purchase_1_inAppDataSignature", null), IN_APP_DATA_SIGNATURE); }
@Test public void ensureAddedPurchaseIsPersistedAndPlusRemains() { plusPurchaseWallet.addLocalInAppPurchaseToWallet(managedProduct); final PurchaseWallet newWallet = new PlusPurchaseWallet(sharedPreferencesLazy); assertTrue(newWallet.hasActivePurchase(InAppPurchase.SmartReceiptsPlus)); assertNull(newWallet.getLocalInAppManagedProduct(InAppPurchase.SmartReceiptsPlus)); assertTrue(plusPurchaseWallet.hasActivePurchase(InAppPurchase.SmartReceiptsPlus)); assertNull(plusPurchaseWallet.getLocalInAppManagedProduct(InAppPurchase.SmartReceiptsPlus)); assertTrue(newWallet.hasActivePurchase(InAppPurchase.OcrScans50)); assertEquals(managedProduct, newWallet.getLocalInAppManagedProduct(InAppPurchase.OcrScans50)); assertEquals(newWallet.getActiveLocalInAppPurchases(), Collections.singleton(managedProduct)); assertTrue(plusPurchaseWallet.hasActivePurchase(InAppPurchase.OcrScans50)); assertEquals(managedProduct, plusPurchaseWallet.getLocalInAppManagedProduct(InAppPurchase.OcrScans50)); assertEquals(plusPurchaseWallet.getActiveLocalInAppPurchases(), Collections.singleton(managedProduct)); assertEquals(preferences.getStringSet("key_sku_set", Collections.<String>emptySet()), Collections.singleton(InAppPurchase.OcrScans50.getSku())); assertEquals(preferences.getString("ocr_purchase_1_purchaseData", null), this.purchaseData); assertEquals(preferences.getString("ocr_purchase_1_inAppDataSignature", null), IN_APP_DATA_SIGNATURE); }
@Test public void ensureUpdatedPurchaseListIsPersistedAndPlusRemains() { plusPurchaseWallet.addLocalInAppPurchaseToWallet(managedProduct); plusPurchaseWallet.updateLocalInAppPurchasesInWallet(Collections.<ManagedProduct>emptySet()); final PurchaseWallet newWallet = new PlusPurchaseWallet(sharedPreferencesLazy); assertTrue(newWallet.hasActivePurchase(InAppPurchase.SmartReceiptsPlus)); assertNull(newWallet.getLocalInAppManagedProduct(InAppPurchase.SmartReceiptsPlus)); assertTrue(plusPurchaseWallet.hasActivePurchase(InAppPurchase.SmartReceiptsPlus)); assertNull(plusPurchaseWallet.getLocalInAppManagedProduct(InAppPurchase.SmartReceiptsPlus)); assertFalse(newWallet.hasActivePurchase(InAppPurchase.OcrScans50)); assertNull(newWallet.getLocalInAppManagedProduct(InAppPurchase.OcrScans50)); assertFalse(plusPurchaseWallet.hasActivePurchase(InAppPurchase.OcrScans50)); assertNull(plusPurchaseWallet.getLocalInAppManagedProduct(InAppPurchase.OcrScans50)); assertEquals(newWallet.getActiveLocalInAppPurchases(), Collections.emptySet()); assertEquals(plusPurchaseWallet.getActiveLocalInAppPurchases(), Collections.emptySet()); assertEquals(preferences.getStringSet("key_sku_set", Collections.<String>emptySet()), Collections.emptySet()); assertFalse(preferences.contains("ocr_purchase_1_purchaseData")); assertFalse(preferences.contains("ocr_purchase_1_inAppDataSignature")); }