@Test public void onServiceConnected() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); Intent intent = new Intent(Constants.ACTION_BILLING_SERVICE_BIND); intent.setPackage(Constants.VENDING_PACKAGE); final ServiceBinder conn = new ServiceBinder( mDataConverter.newBillingContext(RuntimeEnvironment.application), intent); conn.getServiceAsync(new ServiceBinder.Handler() { @Override public void onBind(IInAppBillingService service) { assertThat(service).isNotNull(); latch.countDown(); } @Override public void onError(BillingException e) { throw new IllegalStateException(e); } }); conn.onServiceConnected(null, mServiceStub.create(new Bundle()).asBinder()); latch.await(15, TimeUnit.SECONDS); }
@Test public void unbindService() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); Intent intent = new Intent(Constants.ACTION_BILLING_SERVICE_BIND); intent.setPackage(Constants.VENDING_PACKAGE); final ServiceBinder conn = new ServiceBinder( mDataConverter.newBillingContext(RuntimeEnvironment.application), intent); conn.getServiceAsync(new ServiceBinder.Handler() { @Override public void onBind(IInAppBillingService service) { conn.unbindService(); latch.countDown(); } @Override public void onError(BillingException e) { throw new IllegalStateException(e); } }); conn.onServiceConnected(null, mServiceStub.create(new Bundle()).asBinder()); latch.await(15, TimeUnit.SECONDS); }
@Test public void onServiceDisconnected() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); Intent intent = new Intent(Constants.ACTION_BILLING_SERVICE_BIND); intent.setPackage(Constants.VENDING_PACKAGE); final ServiceBinder conn = new ServiceBinder( mDataConverter.newBillingContext(RuntimeEnvironment.application), intent); conn.getServiceAsync(new ServiceBinder.Handler() { @Override public void onBind(IInAppBillingService service) { assertThat(service).isNotNull(); conn.onServiceDisconnected(null); latch.countDown(); } @Override public void onError(BillingException e) { throw new IllegalStateException(e); } }); conn.onServiceConnected(null, mServiceStub.create(new Bundle()).asBinder()); latch.await(15, TimeUnit.SECONDS); }
@Test public void callGetServiceAsyncTwice() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); Intent intent = new Intent(Constants.ACTION_BILLING_SERVICE_BIND); intent.setPackage(Constants.VENDING_PACKAGE); final ServiceBinder conn = new ServiceBinder( mDataConverter.newBillingContext(RuntimeEnvironment.application), intent); ServiceBinder.Handler handler = new ServiceBinder.Handler() { @Override public void onBind(IInAppBillingService service) { conn.unbindService(); latch.countDown(); } @Override public void onError(BillingException e) { throw new IllegalStateException(e); } }; conn.getServiceAsync(handler); conn.getServiceAsync(handler); conn.onServiceConnected(null, mServiceStub.create(new Bundle()).asBinder()); latch.await(15, TimeUnit.SECONDS); }