### Question:
StopWatch { public String formatTaskDurations() { ensureTasksListExists(); StringBuilder b = new StringBuilder(); if (myTasks.size() > 0) { long delta = myTasks.getFirst().getStart() - myStarted; if (delta > 10) { addNewlineIfContentExists(b); b.append("Before first task"); b.append(": "); b.append(formatMillis(delta)); } } else { b.append("No tasks"); } TaskTiming last = null; for (TaskTiming nextTask : myTasks) { if (last != null) { long delta = nextTask.getStart() - last.getEnd(); if (delta > 10) { addNewlineIfContentExists(b); b.append("Between"); b.append(": "); b.append(formatMillis(delta)); } } addNewlineIfContentExists(b); b.append(nextTask.getTaskName()); b.append(": "); long delta = nextTask.getMillis(); b.append(formatMillis(delta)); last = nextTask; } if (myTasks.size() > 0) { long delta = now() - myTasks.getLast().getEnd(); if (delta > 10) { addNewlineIfContentExists(b); b.append("After last task"); b.append(": "); b.append(formatMillis(delta)); } } return b.toString(); } StopWatch();  StopWatch(Date theStart);  StopWatch(long theStart); void endCurrentTask(); String formatMillisPerOperation(long theNumOperations); String formatTaskDurations(); String formatThroughput(long theNumOperations, TimeUnit theUnit); String getEstimatedTimeRemaining(double theCompleteToDate, double theTotal); long getMillis(Date theNow); long getMillis(); long getMillisAndRestart(); long getMillisPerOperation(long theNumOperations); Date getStartedDate(); double getThroughput(long theNumOperations, TimeUnit theUnit); void restart(); void startTask(String theTaskName); @Override String toString(); static String formatMillis(long theMillis); static String formatMillis(double theMillis);  }### Answer:
@Test public void testFormatTaskDurations() { StopWatch sw = new StopWatch(); StopWatch.setNowForUnitTestForUnitTest(1000L); sw.startTask("TASK1"); StopWatch.setNowForUnitTestForUnitTest(1500L); sw.startTask("TASK2"); StopWatch.setNowForUnitTestForUnitTest(1600L); String taskDurations = sw.formatTaskDurations(); ourLog.info(taskDurations); assertEquals("TASK1: 500ms\nTASK2: 100ms", taskDurations); }
@Test public void testFormatTaskDurationsNoTasks() { StopWatch sw = new StopWatch(0); String taskDurations = sw.formatTaskDurations(); ourLog.info(taskDurations); assertEquals("No tasks", taskDurations); }