title: Unit test for throwing RejectedExecutionException by Java thread pool
body: <p>I am new to using Java thread pool. Now i have a use case for unit test when a new task comes and current thread number is max number and queue is full. I know in this case <code>RejectedExecutionException</code> will be thrown. But how to best produce this scenario, what i can think of now is something like this:</p>
  
  <pre><code>LinkedBlockingQueue&lt;Runnable&gt; queue = new LinkedBlockingQueue&lt;Runnable&gt;(1);
  ExecutorService ex = new ThreadPoolExecutor(2, 2, 60L, TimeUnit.MILLISECONDS, queue);
  int rejected = 0;
  try{
      while (true){
          ex.submit(() -&gt; {
              System.out.println("Queue remaining size: " + queue.remainingCapacity());
              System.out.println("Thread amount in pool: " + ((ThreadPoolExecutor)ex).getPoolSize() + "\n");
          });
      }
  }
  catch (RejectedExecutionException e){
      System.out.println(++rejected);
  }
  </code></pre>
  
  <p>This is basic idea and i need to convert this using EasyMock if it is right way. I wonder if there is better way if using EasyMock instead of keep submitting task until thread and queue is full. </p>