### Question:
NamedThreadFactory implements ThreadFactory { @Override public Thread newThread(Runnable r) { String name = prefix + "_" + counter.incrementAndGet(); if (totalSize > 1) { name += "_" + totalSize; } Thread thread = new FastThreadLocalThread(r, name); thread.setDaemon(makeDaemons); if (thread.getPriority() != Thread.NORM_PRIORITY) { thread.setPriority(Thread.NORM_PRIORITY); } return thread; } NamedThreadFactory(String prefix, int totalSize, boolean makeDaemons);  NamedThreadFactory(String prefix, boolean makeDaemons);  NamedThreadFactory(String prefix, int totalSize); @Override Thread newThread(Runnable r);  }### Answer:
@Test public void testNewThread() { NamedThreadFactory namedThreadFactory = new NamedThreadFactory("testNameThread", 5); Thread testNameThread = namedThreadFactory .newThread(() -> { try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } }); assertThat(testNameThread.getName()).startsWith("testNameThread"); assertThat(testNameThread.isDaemon()).isTrue(); }
@Test public void testConstructorWithPrefixAndDaemons() { NamedThreadFactory factory = new NamedThreadFactory("prefix", true); Thread thread = factory.newThread(() -> {}); assertThat(thread.getName()).startsWith("prefix"); assertThat(thread.isDaemon()).isTrue(); }
@Test public void testThreadNameHasCounterWithPrefixCounter() { NamedThreadFactory factory = new NamedThreadFactory("prefix", THREAD_TOTAL_SIZE, true); for (int i = 0; i < THREAD_TOTAL_SIZE; i ++) { Thread thread = factory.newThread(() -> {}); assertThat("prefix_" + DEFAULT_THREAD_PREFIX_COUNTER + "_" + (i + 1) + "_" + THREAD_TOTAL_SIZE) .isEqualTo(thread.getName()); } }