### Question:
StateContext { @VisibleForTesting public boolean isThreadPoolAvailable(ExecutorService executor) { if (!(executor instanceof ThreadPoolExecutor)) { return true; } ThreadPoolExecutor ex = (ThreadPoolExecutor) executor; if (ex.getQueue().size() == 0) { return true; } return false; } StateContext(ConfigurationSource conf,
      DatanodeStateMachine.DatanodeStates
          state, DatanodeStateMachine parent); DatanodeStateMachine getParent(); DatanodeStateMachine.DatanodeStates getState(); void setState(DatanodeStateMachine.DatanodeStates state); boolean getShutdownOnError(); void addReport(GeneratedMessage report); void putBackReports(List<GeneratedMessage> reportsToPutBack,
                             InetSocketAddress endpoint); List<GeneratedMessage> getAllAvailableReports(
      InetSocketAddress endpoint); List<GeneratedMessage> getReports(InetSocketAddress endpoint,
                                           int maxLimit); void addContainerAction(ContainerAction containerAction); void addContainerActionIfAbsent(ContainerAction containerAction); List<ContainerAction> getAllPendingContainerActions(
      InetSocketAddress endpoint); List<ContainerAction> getPendingContainerAction(
      InetSocketAddress endpoint,
      int maxLimit); void addPipelineActionIfAbsent(PipelineAction pipelineAction); List<PipelineAction> getPendingPipelineAction(
      InetSocketAddress endpoint,
      int maxLimit); @SuppressWarnings("unchecked") DatanodeState<DatanodeStateMachine.DatanodeStates> getTask(); @VisibleForTesting boolean isThreadPoolAvailable(ExecutorService executor); void execute(ExecutorService service, long time, TimeUnit unit); SCMCommand getNextCommand(); void addCommand(SCMCommand command); long getExecutionCount(); CommandStatus getCmdStatus(Long key); void addCmdStatus(Long key, CommandStatus status); void addCmdStatus(SCMCommand cmd); Map<Long, CommandStatus> getCommandStatusMap(); boolean updateCommandStatus(Long cmdId,
      Consumer<CommandStatus> cmdStatusUpdater); void configureHeartbeatFrequency(); long getHeartbeatFrequency(); void addEndpoint(InetSocketAddress endpoint);  }### Answer:
@Test public void testIsThreadPoolAvailable() throws Exception { StateContext stateContext = new StateContext(null, null, null); int threadPoolSize = 2; ExecutorService executorService = Executors.newFixedThreadPool( threadPoolSize); CompletableFuture<String> futureOne = new CompletableFuture<>(); CompletableFuture<String> futureTwo = new CompletableFuture<>(); for (int i = 0; i < threadPoolSize; i++) { executorService.submit(() -> futureOne.get()); } executorService.submit(() -> futureTwo.get()); Assert.assertFalse(stateContext.isThreadPoolAvailable(executorService)); futureOne.complete("futureOne"); LambdaTestUtils.await(1000, 100, () -> stateContext.isThreadPoolAvailable(executorService)); futureTwo.complete("futureTwo"); executorService.shutdown(); }