### Question:
ActiveThreadSet { public void addThread(Thread thread) { cleanUp(); threads.add(thread); } ActiveThreadSet(); void addThread(Thread thread); void joinAll();  }### Answer:
@Test public void newThreadIsAddedToSet() { Thread thread = mock(Thread.class); set.addThread(thread); assertEquals(1, getThreads().size()); }
@Test public void newThreadIsAddedToSetWhenThereAlreadyIsAThreadThatIsNotTerminated() { Thread thread = mock(Thread.class); when(thread.getState()).thenReturn(Thread.State.RUNNABLE); set.addThread(thread); thread = mock(Thread.class); set.addThread(thread); assertEquals(2, getThreads().size()); }
@Test public void whenNewThreadIsAddedToSetTerminatedThreadsAreRemoved() { Thread thread = mock(Thread.class); when(thread.getState()).thenReturn(Thread.State.TERMINATED); set.addThread(thread); Thread thread2 = mock(Thread.class); set.addThread(thread2); assertEquals(1, getThreads().size()); assertEquals(thread2, getThreads().get(0)); }