### Question:
ExecutorServiceWithRegistry { public void submitIfAbsent(EvaluatorExecutor evaluatorExecutor, long clusterId) { if (evaluatorExecutorRegistry.putIfAbsent(evaluatorExecutor, clusterId)) { try { executorService.submit(evaluatorExecutor); } catch (RejectedExecutionException e) { evaluatorExecutorRegistry.remove(evaluatorExecutor, clusterId); throw e; } } else { LOGGER.info("Evaluator {} is not accepted for cluster {}", evaluatorExecutor.getName(), clusterId); } }  void submitIfAbsent(EvaluatorExecutor evaluatorExecutor, long clusterId); void finished(EvaluatorExecutor evaluator, long clusterId); int activeCount();  }### Answer:
@Test public void testSubmitIfAbsent() { when(evaluatorExecutorRegistry.putIfAbsent(any(), eq(CLUSTER_ID))).thenReturn(true); executorServiceWithRegistry.submitIfAbsent(getEvaluatorExecutor(), CLUSTER_ID); verify(executorService).submit((Runnable) any()); verify(evaluatorExecutorRegistry, never()).remove(any(), anyLong()); }
@Test public void testSubmitIfAbsentWhenAlreadyPresent() { when(evaluatorExecutorRegistry.putIfAbsent(any(), eq(CLUSTER_ID))).thenReturn(false); executorServiceWithRegistry.submitIfAbsent(getEvaluatorExecutor(), CLUSTER_ID); verify(evaluatorExecutorRegistry, never()).remove(any(), anyLong()); verify(executorService, never()).submit((Runnable) any()); }
@Test public void testSubmitIfAbsentWhenExecutorServiceThrows() { when(evaluatorExecutorRegistry.putIfAbsent(any(), eq(CLUSTER_ID))).thenReturn(true); when(executorService.submit((Runnable) any())).thenThrow(new RejectedExecutionException("")); try { executorServiceWithRegistry.submitIfAbsent(getEvaluatorExecutor(), CLUSTER_ID); fail("Expected rejectedExecutionException"); } catch (RejectedExecutionException ignored) { } verify(executorService).submit((Runnable) any()); verify(evaluatorExecutorRegistry).remove(any(), eq(CLUSTER_ID)); }