### Question:
BasePurchaseVerifier implements PurchaseVerifier { @Override public final void verify(@Nonnull final List<Purchase> purchases, @Nonnull final RequestListener<List<Purchase>> listener) { if (MainThread.isMainThread()) { mBackground.execute(new Runnable() { @Override public void run() { doVerify(purchases, new MainThreadRequestListener(listener)); } }); } else { doVerify(purchases, listener); } } protected  BasePurchaseVerifier(); protected  BasePurchaseVerifier(@Nonnull Handler handler); protected  BasePurchaseVerifier(@Nonnull Handler handler, int threadCount, @Nonnull ThreadFactory threadFactory); @Override final void verify(@Nonnull final List<Purchase> purchases, @Nonnull final RequestListener<List<Purchase>> listener);  }### Answer:
@Test public void testVerifierIsCalledOnBackgroundThreadFromMainThread() throws Exception { final ThreadAwareVerifier verifier = new ThreadAwareVerifier(); final CountDownLatchRequestListener listener = new CountDownLatchRequestListener(); verifier.verify(new ArrayList<Purchase>(), listener); listener.mLatch.await(1, TimeUnit.SECONDS); assertEquals("TestThread", verifier.mThreadName); }
@Test public void testVerifierIsCalledOnTheSameBackgroundThread() throws Exception { final ThreadAwareVerifier verifier = new ThreadAwareVerifier(); final CountDownLatchRequestListener listener = new CountDownLatchRequestListener(); new Thread(new Runnable() { @Override public void run() { verifier.verify(new ArrayList<Purchase>(), listener); } }, "BackgroundThread").start(); listener.mLatch.await(1, TimeUnit.SECONDS); assertEquals("BackgroundThread", verifier.mThreadName); }
@Test public void testVerifierCallsListenerMethodsOnMainThreadFromMainThread() throws Exception { final ThreadAwareVerifier verifier = new ThreadAwareVerifier(); final ThreadAwareRequestListener listener = new ThreadAwareRequestListener(); verifier.verify(new ArrayList<Purchase>(), listener); listener.mLatch.await(1, TimeUnit.SECONDS); }
@Test public void testVerifierCallsListenerMethodsOnTheSameBackgroundThread() throws Exception { final ThreadAwareVerifier verifier = new ThreadAwareVerifier(); final ThreadAwareRequestListener listener = new ThreadAwareRequestListener(); new Thread(new Runnable() { @Override public void run() { verifier.verify(new ArrayList<Purchase>(), listener); } }, "BackgroundThread").start(); listener.mLatch.await(1, TimeUnit.SECONDS); assertEquals("BackgroundThread", listener.mThreadName); }