@Nonnull @Override protected Inventory newInventory(@Nonnull Checkout checkout) { return new RobotmediaInventory(checkout, sameThreadExecutor()); }
@Nonnull @Override protected Billing newBilling() { final Billing billing = super.newBilling(); billing.setMainThread(sameThreadExecutor()); return billing; }
@Nonnull @Override protected Billing newBilling() { final Billing billing = super.newBilling(); billing.setMainThread(sameThreadExecutor()); return billing; }
@Test public void testShouldCallOnError() throws Exception { final RequestListener l = mock(RequestListener.class); final MainThreadRequestListener mtl = new MainThreadRequestListener(Tests.sameThreadExecutor(), l); final Exception e = new Exception(); mtl.onError(3, e); verify(l).onError(eq(3), eq(e)); }
@Nonnull @Override protected FallingBackInventory newInventory(@Nonnull Checkout checkout) { return new FallingBackInventory(checkout, new RobotmediaInventory(checkout, sameThreadExecutor())); }
@Test public void testShouldCallOnSuccess() throws Exception { final RequestListener l = mock(RequestListener.class); final MainThreadRequestListener mtl = new MainThreadRequestListener(Tests.sameThreadExecutor(), l); final Object o = new Object(); mtl.onSuccess(o); verify(l).onSuccess(eq(o)); }
@Test public void testShouldReadEmptyList() throws Exception { final RobotmediaInventory inventory = new RobotmediaInventory(mCheckout, sameThreadExecutor(), sameThreadExecutor()); final CountDownCallback l = new CountDownCallback(); inventory.load(mRequest, l); final Inventory.Products products = l.waitProducts(); final Inventory.Product product = products.get(IN_APP); assertTrue(product.supported); final List<Purchase> purchases = product.getPurchases(); assertEquals(0, purchases.size()); }
@Nonnull static Billing newSynchronousBilling() { final Billing billing = new Billing(RuntimeEnvironment.application, newConfiguration(true, false)); billing.setPurchaseVerifier(Tests.newMockVerifier(true)); final IInAppBillingService service = mock(IInAppBillingService.class); final CancellableExecutor sameThreadExecutor = sameThreadExecutor(); billing.setBackground(sameThreadExecutor); billing.setMainThread(sameThreadExecutor); setService(billing, service); return billing; }
@Test public void testShouldCreateEmptyProductsIfError() throws Exception { mDb.close(); RuntimeEnvironment.application.deleteDatabase(RobotmediaDatabase.NAME); final RobotmediaInventory inventory = new RobotmediaInventory(mCheckout, sameThreadExecutor(), sameThreadExecutor()); final CountDownCallback l = new CountDownCallback(); inventory.load(mRequest, l); final Inventory.Products products = l.waitProducts(); final Inventory.Product product = products.get(IN_APP); assertNotNull(product); assertTrue(product.getPurchases().isEmpty()); }
@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); }
@Test public void testShouldRunAllRequests() throws Exception { final int REQUESTS = 100; final int SLEEP = 10; final Billing b = Tests.newBilling(false); b.setMainThread(Tests.sameThreadExecutor()); final AsyncServiceConnector c = new AsyncServiceConnector(b); b.setConnector(c); final CountDownLatch latch = new CountDownLatch(REQUESTS); final RequestListener l = new CountDownListener(latch); for (int i = 0; i < REQUESTS; i++) { if (i % 10 == 0) { if (mRandom.nextBoolean()) { b.connect(); } else { // connector is called directly in order to avoid cancelling the pending // requests c.disconnect(); } } b.runWhenConnected(new SleepingRequest(mRandom.nextInt(SLEEP)), l, null); } b.connect(); assertTrue(latch.await(SLEEP * REQUESTS, TimeUnit.MILLISECONDS)); }
@Test public void testShouldReadTransactions() throws Exception { mDb.insert(newTransaction(0)); mDb.insert(newTransaction(1)); mDb.insert(newTransaction(2)); mDb.insert(newTransaction(3)); mDb.insert(newTransaction(4)); mDb.insert(newTransaction(5)); final RobotmediaInventory inventory = new RobotmediaInventory(mCheckout, sameThreadExecutor(), sameThreadExecutor()); final CountDownCallback l = new CountDownCallback(); inventory.load(mRequest, l); final Inventory.Products products = l.waitProducts(); final Inventory.Product product = products.get(IN_APP); assertTrue(product.supported); final List<Purchase> purchases = product.getPurchases(); assertEquals(5, purchases.size()); verifyPurchase(purchases, 0); verifyPurchase(purchases, 1); verifyPurchase(purchases, 2); verifyPurchase(purchases, 3); verifyPurchase(purchases, 4); }