@Test public void testShouldNotifyErrorIfCantConnect() throws Exception { final Billing.ServiceConnector connector = mock(Billing.ServiceConnector.class); when(connector.connect()).thenReturn(false); mBilling.setConnector(connector); final RequestListener<Object> l = mock(RequestListener.class); mBilling.getRequests().isBillingSupported("p", l); verify(l, times(1)).onError(eq(ResponseCodes.SERVICE_NOT_CONNECTED), any(BillingException.class)); verify(l, times(0)).onSuccess(any()); }
@Test public void testShouldExecuteRequestIfConnected() throws Exception { final Billing.ServiceConnector connector = mock(Billing.ServiceConnector.class); final IInAppBillingService service = mock(IInAppBillingService.class); when(service.isBillingSupported(anyInt(), anyString(), anyString())).thenReturn(OK); when(connector.connect()).then(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { mBilling.setService(service, true); return true; } }); mBilling.setConnector(connector); final RequestListener<Object> l = mock(RequestListener.class); mBilling.getRequests().isBillingSupported("p", l); verify(l, times(0)).onError(anyInt(), any(BillingException.class)); verify(l, times(1)).onSuccess(any()); }
@Test public void testShouldNotifyErrorIfConnectorReturnedNull() throws Exception { final Billing.ServiceConnector connector = mock(Billing.ServiceConnector.class); when(connector.connect()).then(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { mBilling.setService(null, true); return true; } }); mBilling.setConnector(connector); final RequestListener<Object> l = mock(RequestListener.class); mBilling.getRequests().isBillingSupported("p", l); verify(l, times(1)).onError(eq(ResponseCodes.SERVICE_NOT_CONNECTED), any(BillingException.class)); verify(l, times(0)).onSuccess(any()); }