AnnotatedCallable implements Callable<T> { public static <T> Callable<T> replaceThreadNameWith(String threadName, Callable<T> delegate) { return wrapWithThreadName(AnnotationType.REPLACE, threadName, delegate); } private  AnnotatedCallable(Callable<T> delegate, String name, AnnotationType type); static Callable<T> replaceThreadNameWith(String threadName, Callable<T> delegate); static Callable<T> wrapWithThreadName(AnnotationType type, String threadName, Callable<T> delegate); @Override T call();  }
@Test public void replaceThreadNameWith() throws Exception { Callable<String> callable = AnnotatedCallable.replaceThreadNameWith( "test", () -> { assertThat(Thread.currentThread().getName(), is("test")); return "Hello, world!"; }); String result = callable.call(); assertThat(result, is("Hello, world!")); }