NamedDaemonThreadFactory implements ThreadFactory { @Override public Thread newThread(final Runnable runnable) { Thread thread = new Thread(runnable); thread.setName(name); thread.setPriority(Thread.MIN_PRIORITY); thread.setDaemon(true); return thread; } NamedDaemonThreadFactory(final String name); @Override Thread newThread(final Runnable runnable);  }
@Test public void newThread() { Runnable runnable = mock(Runnable.class); Thread thread = new NamedDaemonThreadFactory("foo").newThread(runnable); assertThat(thread).isNotNull(); assertThat(thread.getName()).isEqualTo("foo"); assertThat(thread.getPriority()).isEqualTo(Thread.MIN_PRIORITY); assertThat(thread.isDaemon()).isTrue(); assertThat(thread.getState()).isEqualTo(Thread.State.NEW); verify(runnable, never()).run(); }