@Test(timeout = 10000) public void shutdownShouldNotLeadToThreadInitialization() throws InterruptedException { DaemonThreadFactory factory = new DaemonThreadFactory("42"); util.setThreadFactory(factory); util.shutdownBackgroundExecutor(); assertEquals(0, factory.getCreatedThreads()); }
@Test(timeout = 10000) public void shouldCorrectlyStopBackgroundExecutor() throws InterruptedException { CountDownLatch latch = new CountDownLatch(1); Thread[] executorThread = new Thread[1]; Runnable task = () -> { executorThread[0] = Thread.currentThread(); latch.countDown(); }; Executor executor = util.getBackgroundExecutor(); util.execute(executor, task); latch.await(); util.shutdownBackgroundExecutor(); executorThread[0].join(); }