CheckedRejectionExecutorService { public <T> Future<T> submit(Callable<T> callable) throws CheckedRejectedExecutionException { try { return underlying.submit(callable); } catch (RejectedExecutionException ex) { throw new CheckedRejectedExecutionException(ex); } } CheckedRejectionExecutorService(ExecutorService underlying); void execute(Runnable runnable); Future<T> submit(Callable<T> callable);  }
@Test public void passesCallThroughSubmit() throws CheckedRejectedExecutionException { when(delegate.submit(RETURN_ONE)).thenReturn(Futures.immediateFuture(1)); assertThat(Futures.getUnchecked(checkedRejectionExecutor.submit(RETURN_ONE))).isEqualTo(1); verify(delegate, times(1)).submit(RETURN_ONE); }
@Test @SuppressWarnings("unchecked") public void propagatesRejectionThroughSubmit() { doThrow(REJECTED_EXECUTION_EXCEPTION).when(delegate).submit(any(Callable.class)); assertThatThrownBy(() -> checkedRejectionExecutor.submit(RETURN_ONE)) .isInstanceOf(CheckedRejectedExecutionException.class) .hasCause(REJECTED_EXECUTION_EXCEPTION); }