/** * Makes {@link Inventory} to load SKU details for the given list of <var>skus</var>. As * SKU identifier is unique only in product <var>product</var> id must be also provided to * this method. * @param product product * @param skus list of SKU identifiers for which SKU details should be loaded * @return this request */ @Nonnull public Request loadSkus(@Nonnull String product, @Nonnull List<String> skus) { for (String sku : skus) { loadSkus(product, sku); } return this; }
/** * Same as {@link #loadSkus(String, List)}. */ @Nonnull public Request loadSkus(@Nonnull String product, @Nonnull String... skus) { Check.isTrue(skus.length > 0, "No SKUs listed, can't load them"); return loadSkus(product, Arrays.asList(skus)); }
@Before public void setUp() throws Exception { mBilling = newBilling(); mRequest = Inventory.Request.create() .loadAllPurchases() .loadSkus(IN_APP, asList("1", "2", "3", "4", "6")) .loadSkus(SUBSCRIPTION, asList("sub1", "sub2", "sub3", "sub4")); mCheckout = Checkout.forApplication(mBilling); mInventory = newInventory(mCheckout); }
@Test public void testIsLoadedWithEmptySkusList() throws Exception { populatePurchases(); populateSkus(); final Inventory.Request request = Inventory.Request.create() .loadAllPurchases() .loadSkus(IN_APP, "in_app_01") .loadSkus(SUBSCRIPTION, "sub_01"); final Checkout checkout = Checkout.forApplication(mBilling); final CheckoutInventory inventory = new CheckoutInventory(checkout); final TestCallback listener = new TestCallback(); checkout.start(); inventory.load(request, listener); Tests.waitWhileLoading(inventory); final Inventory.Product app = listener.mProducts.get(IN_APP); Assert.assertTrue(app.getSkus().isEmpty()); Assert.assertFalse(app.getPurchases().isEmpty()); final Inventory.Product sub = listener.mProducts.get(SUBSCRIPTION); Assert.assertTrue(sub.getSkus().isEmpty()); Assert.assertFalse(sub.getPurchases().isEmpty()); }
@Test public void testShouldContinueAfterListenerException() throws Exception { populatePurchases(); final Inventory.Request request = Inventory.Request.create() .loadSkus(IN_APP, "in_app_01") .loadSkus(SUBSCRIPTION, "sub_01"); final Checkout checkout = Checkout.forApplication(mBilling); final CrashingCallback listener = new CrashingCallback(); final CheckoutInventory inventory = new CheckoutInventory(checkout); checkout.start(); inventory.load(request, listener); Tests.waitWhileLoading(inventory); Assert.assertTrue(listener.exceptionThrown); }
@Test public void testShouldLoadSeveralTasksAsynchronously() throws Exception { populatePurchases(); populateSkus(); mCheckout.start(); final CountingCallback c = new CountingCallback(); mInventory.load(Inventory.Request.create().loadPurchases(IN_APP), c); mInventory.load(Inventory.Request.create().loadPurchases(SUBSCRIPTION), c); mInventory.load(Inventory.Request.create().loadSkus(SUBSCRIPTION, asList("sub1", "sub2", "sub3", "sub4")), c); mInventory.load(Inventory.Request.create().loadSkus(IN_APP, asList("1", "2", "3", "4", "6")), c); mInventory.load(mRequest, c); Tests.waitWhileLoading(mInventory); assertEquals(5, c.mCount); }
@Test public void testShouldLoadSkus() throws Exception { populateSkus(); mCheckout.start(); final TestCallback c1 = new TestCallback(); mInventory.load(Inventory.Request.create().loadSkus(SUBSCRIPTION, asList("subX", "sub2", "sub3")), c1); final TestCallback c2 = new TestCallback(); mInventory.load(Inventory.Request.create().loadSkus(IN_APP, asList("1", "2", "5")), c2); Tests.waitWhileLoading(mInventory); assertEquals(2, c1.mProducts.get(SUBSCRIPTION).getSkus().size()); assertEquals(2, c2.mProducts.get(IN_APP).getSkus().size()); }
@Before public void setUp() throws Exception { mFailingCache = new FailingCache(); mBilling = newBilling(); mRequest = Inventory.Request.create() .loadAllPurchases() .loadSkus(IN_APP, asList("1", "2", "3", "4", "6")) .loadSkus(SUBSCRIPTION, asList("sub1", "sub2", "sub3", "sub4")); mCheckout = Checkout.forApplication(mBilling); }
private void reloadInventory() { final Inventory.Request request = Inventory.Request.create(); request.loadPurchases(SUBSCRIPTION); request.loadSkus(SUBSCRIPTION, SKUS); mCheckout.loadInventory(request, new Inventory.Callback() { @Override public void onLoaded(@Nonnull Inventory.Products products) { for (Inventory.Callback callback : mInventoryCallbacks) { callback.onLoaded(products); } } }); }
@Test public void testShouldLoadSkus() throws Exception { populateSkus(); mCheckout.start(); final TestCallback c1 = new TestCallback(); mInventory.load(Inventory.Request.create().loadSkus(SUBSCRIPTION, asList("subX", "sub2", "sub3")), c1); final TestCallback c2 = new TestCallback(); mInventory.load(Inventory.Request.create().loadSkus(IN_APP, asList("1", "2", "5")), c2); Tests.waitWhileLoading(mInventory); assertEquals(0, c1.mProducts.get(SUBSCRIPTION).getSkus().size()); assertEquals(2, c2.mProducts.get(IN_APP).getSkus().size()); }
private void reloadInventory() { final Inventory.Request request = Inventory.Request.create(); // load purchase info request.loadAllPurchases(); // load SKU details request.loadSkus(ProductTypes.IN_APP, getInAppSkus()); mCheckout.loadInventory(request, mInventoryCallback); }
@Before public void setUp() throws Exception { final Billing billing = Tests.newBilling(); billing.setMainThread(sameThreadExecutor()); mRequest = Inventory.Request.create().loadSkus(IN_APP, asList("sku_0", "sku_1", "sku_2", "sku_3", "sku_4", "sku_6")).loadAllPurchases(); mCheckout = Checkout.forApplication(billing); mDb = new BillingDB(RuntimeEnvironment.application); }