static void mockGetPurchases(@Nonnull Billing billing, @Nonnull String product, @Nonnull List<Purchase> purchases) throws RemoteException { final Bundle bundle = newBundle(OK); final ArrayList<String> list = new ArrayList<String>(); for (Purchase purchase : purchases) { list.add(purchase.toJson()); } bundle.putStringArrayList(Purchases.BUNDLE_DATA_LIST, list); final IInAppBillingService service = ((TestServiceConnector) billing.getConnector()).mService; when(service.getPurchases(anyInt(), anyString(), eq(product), isNull(String.class))) .thenReturn(bundle); }
static void mockGetSkuDetails(@Nonnull Billing billing, @Nonnull String product, @Nonnull final List<Sku> skus) throws RemoteException { final IInAppBillingService service = ((TestServiceConnector) billing.getConnector()).mService; when(service.getSkuDetails(anyInt(), anyString(), eq(product), any(Bundle.class))) .thenAnswer(new Answer<Bundle>() { @Override public Bundle answer(InvocationOnMock invocation) throws Throwable { final Bundle in = (Bundle) invocation.getArguments()[3]; final ArrayList<String> skuIds = in.getStringArrayList("ITEM_ID_LIST"); final Bundle bundle = newBundle(OK); final ArrayList<String> list = new ArrayList<String>(); for (Sku sku : skus) { if (skuIds.contains(sku.id.code)) { list.add(sku.toJson()); } } bundle.putStringArrayList(Skus.BUNDLE_LIST, list); return bundle; } }); } }
@Before public void setUp() throws Exception { Billing billing = newBilling(); billing.connect(); mService = ((TestServiceConnector) billing.getConnector()).mService; when(mService.isBillingSupported(eq(3), anyString(), eq(IN_APP))).thenReturn(OK); when(mService.isBillingSupported(eq(3), anyString(), eq(SUBSCRIPTION))).thenReturn(OK); mCheckout = Checkout.forApplication(billing); }
@Override @Before public void setUp() throws Exception { SQLiteDatabase db = RuntimeEnvironment.application.openOrCreateDatabase(RobotmediaDatabase.NAME, 0, null); db.close(); super.setUp(); final IInAppBillingService service = ((TestServiceConnector) mBilling.getConnector()).mService; when(service.isBillingSupported(anyInt(), anyString(), eq(SUBSCRIPTION))).thenReturn(ResponseCodes.ERROR); }