ExecutorUtil { public static boolean isTerminated(Executor executor) { if (executor instanceof ExecutorService) { if (((ExecutorService) executor).isTerminated()) { return true; } } return false; }  static boolean isTerminated(Executor executor); static void gracefulShutdown(Executor executor, int timeout); static void shutdownNow(Executor executor, final int timeout); static URL setThreadName(URL url, String defaultName); static void cancelScheduledFuture(ScheduledFuture<?> scheduledFuture);  }
@Test public void testIsTerminated() throws Exception { ExecutorService executor = Mockito.mock(ExecutorService.class); when(executor.isTerminated()).thenReturn(true); assertThat(ExecutorUtil.isTerminated(executor), is(true)); Executor executor2 = Mockito.mock(Executor.class); assertThat(ExecutorUtil.isTerminated(executor2), is(false)); }