### Question:
TaskExecutor { public void submit(final Collection<Callable<T>> callables) throws Exception { Validate.notNull(callables); final StopWatch watch = new StopWatch(); watch.start("init"); final long start = System.currentTimeMillis(); final AtomicLong totalTime = new AtomicLong(); LOG.debug("running {} tasks", callables.size()); if (callables.size() == 1) { final T result = callables.iterator().next().call(); onResultAvailable(result); } else { LOG.debug("Running tasks in parallel"); watch.stop(); watch.start("submit tasks"); for (final Callable<T> callable : callables) { getCompletionService().submit(decorate(callable, totalTime)); } watch.stop(); watch.start("consume results"); for (int i = 0; i < callables.size(); i++) { doConsumeResult(); } } watch.stop(); destroy(); LOG.debug("Number of Tasks: {}", callables.size()); final long averageExecutionTime = callables.size() != 0 ? totalTime.longValue() / callables.size() : 0; LOG.debug("Average Execution Time: {}", averageExecutionTime); LOG.debug("Total Task Time: {}", totalTime); LOG.debug("Grand Total Execution Time: {}", System.currentTimeMillis() - start); LOG.debug(watch.prettyPrint()); }  void submit(final Collection<Callable<T>> callables); void destroy();  }### Answer:
@Test(expected = NullPointerException.class) public void cannotSubmitNullCallables() throws Exception { final Collection<Callable<Void>> callables = null; victim.submit(callables); }
@Test public void shouldHaveMinimalOverheadWhenRunningASingleTask() throws Exception { final Collection<Callable<Void>> callables = new ArrayList<Callable<Void>>(); final long delay = 100; callables.add(createSlowCallable(delay)); final long start = System.currentTimeMillis(); victim.submit(callables); final long end = System.currentTimeMillis(); final long delta = end - start; LOG.debug("Execution took: {}", delta); final long overhead = 40; assertTrue(delta < delay + overhead); }
@Test public void shouldBeFasterWhenRunningMultipleSlowTasks() throws Exception { final Collection<Callable<Void>> callables = new ArrayList<Callable<Void>>(); final long delay = 100; final int times = 10; for (int i = 0; i < times; i++) { callables.add(createSlowCallable(delay)); } final long start = System.currentTimeMillis(); victim.submit(callables); final long end = System.currentTimeMillis(); final long delta = end - start; LOG.debug("Execution took: {}", delta); assertTrue(delta < delay * times); }
@Test(expected = WroRuntimeException.class) public void shouldPropagateOriginalException() throws Exception { final List<Callable<Void>> tasks = new ArrayList<Callable<Void>>(); tasks.add(createFailingCallable()); tasks.add(createFailingCallable()); victim.submit(tasks); }