### Question:
ThreadRenamingRunnable implements Runnable { public static void setThreadNameDeterminer(ThreadNameDeterminer threadNameDeterminer) { if (threadNameDeterminer == null) { throw new NullPointerException("threadNameDeterminer"); } ThreadRenamingRunnable.threadNameDeterminer = threadNameDeterminer; } ThreadRenamingRunnable(Runnable runnable, String proposedThreadName, ThreadNameDeterminer determiner);  ThreadRenamingRunnable(Runnable runnable, String proposedThreadName); static ThreadNameDeterminer getThreadNameDeterminer(); static void setThreadNameDeterminer(ThreadNameDeterminer threadNameDeterminer); void run();  }### Answer:
@Test public void testThreadNameDeterminer() { final String oldThreadName = Thread.currentThread().getName(); final String newThreadName = "new"; final String proposed = "proposed"; ThreadNameDeterminer determiner = new ThreadNameDeterminer() { public String determineThreadName(String currentThreadName, String proposedThreadName) throws Exception { assertEquals(proposed, proposedThreadName); assertEquals(oldThreadName, currentThreadName); return newThreadName; } }; ThreadRenamingRunnable.setThreadNameDeterminer(new ThreadNameDeterminer() { public String determineThreadName(String currentThreadName, String proposedThreadName) throws Exception { assertEquals(proposed, proposedThreadName); assertEquals(oldThreadName, currentThreadName); return proposed; } }); Executor e = new ImmediateExecutor(); try { e.execute(new ThreadRenamingRunnable(new Runnable() { public void run() { assertEquals("Should use the given ThreadNameDEterminer", newThreadName, Thread.currentThread().getName()); } }, proposed, determiner)); } finally { assertEquals(oldThreadName, Thread.currentThread().getName()); } try { e.execute(new ThreadRenamingRunnable(new Runnable() { public void run() { assertEquals("Should use the static set ThreadNameDeterminer", proposed, Thread.currentThread().getName()); } }, proposed)); } finally { assertEquals(oldThreadName, Thread.currentThread().getName()); } }