@Override
    public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
        if (executor.isShutdown()) {
            return;
        }
        BlockingQueue<Runnable> workQueue = executor.getQueue();
        Runnable firstWork = workQueue.poll();
        boolean newTaskAdd = workQueue.offer(r);
        if (firstWork != null) {
            firstWork.run();
        }
        if (!newTaskAdd) {
            executor.execute(r);
        }
    }
@Test
    public void testRejectedExecutionWhenATaskIsInTheQueueTheExecutorShouldNotExecute() {
        when(threadPoolExecutor.isShutdown()).thenReturn(false);
        when(threadPoolExecutor.getQueue()).thenReturn(workQueue);
        when(workQueue.poll()).thenReturn(runnableInTheQueue);
        when(workQueue.offer(runnable)).thenReturn(true);

        runsOldestTaskPolicy.rejectedExecution(runnable, threadPoolExecutor);

        verify(runnableInTheQueue).run();
        verify(threadPoolExecutor, never()).execute(runnable);
        verify(runnable, never()).run();
    }