TaskQueue extends LinkedBlockingQueue<Runnable> { @Override public boolean offer(Runnable runnable) { if (executor == null) { throw new RejectedExecutionException("The task queue does not have executor!"); } int currentPoolThreadSize = executor.getPoolSize(); if (executor.getSubmittedTaskCount() < currentPoolThreadSize) { return super.offer(runnable); } if (currentPoolThreadSize < executor.getMaximumPoolSize()) { return false; } return super.offer(runnable); } TaskQueue(int capacity); void setExecutor(EagerThreadPoolExecutor exec); @Override boolean offer(Runnable runnable); boolean retryOffer(Runnable o, long timeout, TimeUnit unit);  }
@Test(expected = RejectedExecutionException.class) public void testOffer1() throws Exception { TaskQueue<Runnable> queue = new TaskQueue<Runnable>(1); queue.offer(mock(Runnable.class)); }
@Test public void testOffer1() throws Exception { Assertions.assertThrows(RejectedExecutionException.class, () -> { TaskQueue<Runnable> queue = new TaskQueue<Runnable>(1); queue.offer(mock(Runnable.class)); }); }