BackgroundThreadPoster { public void post(Runnable runnable) { mThreadPoolExecutor.execute(runnable); } BackgroundThreadPoster(); void post(Runnable runnable);  }
@Test public void execute_singleRunnable_executionSuccessful() throws Exception { final Semaphore semaphore = new Semaphore(0); Runnable runnable = new Runnable() { @Override public void run() { semaphore.release(); } }; SUT.post(runnable); semaphore.acquireUninterruptibly(); }
@Test public void execute_multipleRunnablesIndependent_executionSuccessful() throws Exception { final Semaphore semaphore = new Semaphore(-1); Runnable runnable1 = new Runnable() { @Override public void run() { semaphore.release(); } }; Runnable runnable2 = new Runnable() { @Override public void run() { semaphore.release(); } }; SUT.post(runnable1); SUT.post(runnable2); semaphore.acquireUninterruptibly(); }
@Test public void execute_multipleRunnablesInterdependent_executionSuccessful() throws Exception { final Semaphore semaphore1 = new Semaphore(0); final Semaphore semaphore2 = new Semaphore(0); Runnable runnable1 = new Runnable() { @Override public void run() { semaphore1.acquireUninterruptibly(); semaphore2.release(); } }; Runnable runnable2 = new Runnable() { @Override public void run() { semaphore1.release(); } }; SUT.post(runnable1); SUT.post(runnable2); semaphore2.acquireUninterruptibly(); }