@Nullable @Override protected Bundle request(@Nonnull IInAppBillingService service, @Nonnull String packageName) throws RemoteException { return service.getPurchaseHistory(mApiVersion, packageName, mProduct, mContinuationToken, mExtraParams); }
private void prepareMultiPurchasesService(@Nonnull Billing billing) throws RemoteException, JSONException { final IInAppBillingService service = mock(IInAppBillingService.class); when(service.getPurchases(anyInt(), anyString(), anyString(), isNull(String.class))).thenReturn(newPurchasesBundle(0, true)); when(service.getPurchases(anyInt(), anyString(), anyString(), eq("1"))).thenReturn(newPurchasesBundle(1, true)); when(service.getPurchases(anyInt(), anyString(), anyString(), eq("2"))).thenReturn(newPurchasesBundle(2, true)); when(service.getPurchases(anyInt(), anyString(), anyString(), eq("3"))).thenReturn(newPurchasesBundle(3, true)); when(service.getPurchases(anyInt(), anyString(), anyString(), eq("4"))).thenReturn(newPurchasesBundle(4, false)); when(service.getPurchaseHistory(anyInt(), anyString(), anyString(), isNull(String.class), any(Bundle.class))).thenReturn(newPurchasesBundle(0, true, true)); when(service.getPurchaseHistory(anyInt(), anyString(), anyString(), eq("1"), any(Bundle.class))).thenReturn(newPurchasesBundle(1, true, true)); when(service.getPurchaseHistory(anyInt(), anyString(), anyString(), eq("2"), any(Bundle.class))).thenReturn(newPurchasesBundle(2, true, true)); when(service.getPurchaseHistory(anyInt(), anyString(), anyString(), eq("3"), any(Bundle.class))).thenReturn(newPurchasesBundle(3, true, true)); when(service.getPurchaseHistory(anyInt(), anyString(), anyString(), eq("4"), any(Bundle.class))).thenReturn(newPurchasesBundle(4, false, true)); Tests.setService(billing, service); }
@Test public void testShouldError() throws Exception { final Request request = newRequest(); final RequestListener l = mock(RequestListener.class); request.setListener(l); final Bundle bundle = newBundle(BILLING_UNAVAILABLE); final IInAppBillingService service = mock(IInAppBillingService.class); when(service.isBillingSupported(anyInt(), anyString(), anyString())).thenReturn(BILLING_UNAVAILABLE); when(service.consumePurchase(anyInt(), anyString(), anyString())).thenReturn(BILLING_UNAVAILABLE); when(service.getPurchases(anyInt(), anyString(), anyString(), anyString())).thenReturn(bundle); when(service.getPurchaseHistory(anyInt(), anyString(), anyString(), anyString(), any(Bundle.class))).thenReturn(bundle); when(service.getSkuDetails(anyInt(), anyString(), anyString(), any(Bundle.class))).thenReturn(bundle); when(service.getBuyIntent(anyInt(), anyString(), anyString(), anyString(), anyString())).thenReturn(bundle); request.start(service, "testse"); verify(l).onError(eq(BILLING_UNAVAILABLE), any(Exception.class)); verify(l, never()).onSuccess(any()); }
@Test public void testShouldSuccess() throws Exception { final Request r = newRequest(); final RequestListener l = mock(RequestListener.class); r.setListener(l); final IInAppBillingService service = mock(IInAppBillingService.class); when(service.isBillingSupported(anyInt(), anyString(), anyString())).thenReturn(OK); when(service.consumePurchase(anyInt(), anyString(), anyString())).thenReturn(OK); final Bundle purchases = new Bundle(); purchases.putStringArrayList("INAPP_PURCHASE_DATA_LIST", new ArrayList<String>()); when(service.getPurchases(anyInt(), anyString(), anyString(), anyString())).thenReturn(purchases); when(service.getPurchaseHistory(anyInt(), anyString(), anyString(), anyString(), any(Bundle.class))).thenReturn(purchases); final Bundle skuDetails = new Bundle(); skuDetails.putStringArrayList("DETAILS_LIST", new ArrayList<String>()); when(service.getSkuDetails(anyInt(), anyString(), anyString(), any(Bundle.class))).thenReturn(skuDetails); final Bundle buyIntent = new Bundle(); buyIntent.putParcelable("BUY_INTENT", PendingIntent.getActivity(RuntimeEnvironment.application, 100, new Intent(), 0)); when(service.getBuyIntent(anyInt(), anyString(), anyString(), anyString(), anyString())).thenReturn(buyIntent); r.start(service, ""); verify(l).onSuccess(anyObject()); verify(l, never()).onError(anyInt(), any(Exception.class)); }