ExecutorServiceWithTracing implements ExecutorService { protected <T> List<Callable<T>> convertToCallableWithTracingList(Collection<? extends Callable<T>> tasks) { if (tasks == null) { return null; } List<Callable<T>> tasksWithTracing = new ArrayList<>(tasks.size()); for (Callable<T> task : tasks) { Callable<T> taskWithTracing = (task == null) ? null : new CallableWithTracing<>(task); tasksWithTracing.add(taskWithTracing); } return tasksWithTracing; } ExecutorServiceWithTracing(ExecutorService delegate); static ExecutorServiceWithTracing withTracing(ExecutorService delegate); @Override void shutdown(); @Override List<Runnable> shutdownNow(); @Override boolean isShutdown(); @Override boolean isTerminated(); @Override boolean awaitTermination(long timeout, TimeUnit unit); @Override Future<T> submit(Callable<T> task); @Override Future<T> submit(Runnable task, T result); @Override Future<?> submit(Runnable task); @Override List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks); @Override List<Future<T>> invokeAll(
        Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit
    ); @Override T invokeAny(Collection<? extends Callable<T>> tasks); @Override T invokeAny(
        Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit
    ); @Override void execute(Runnable command);  }
@Test public void convertToCallableWithTracingList_works_as_expected() { List<Callable<Object>> origCallables = Arrays.asList( mock(Callable.class), null, mock(Callable.class) ); TracingState expectedTracingState = generateTracingStateOnCurrentThread(); List<Callable<Object>> results = instance.convertToCallableWithTracingList(origCallables); assertThat(results).hasSameSizeAs(origCallables); for (int i = 0; i < results.size(); i++) { Callable<Object> actualTask = results.get(i); Callable<Object> origTaskMock = origCallables.get(i); if (origTaskMock == null) { assertThat(actualTask).isNull(); } else { verifyCallableWithTracingWrapper(actualTask, origTaskMock, expectedTracingState); } } }
@Test public void convertToCallableWithTracingList_returns_null_if_passed_null() { assertThat(instance.convertToCallableWithTracingList(null)).isNull(); }