ExecutorService { public void cancelExecution(Execution execution, String userRequest) throws MonitorException { Executor executor = getExecutor(execution); if (executor == null) { throw new MonitorException( "Can't find executor for: {}", execution.getIri()); } this.restClient.cancel(executor, userRequest); } @Autowired  ExecutorService(
            ExecutionSource executions,
            ExecutorEventListener eventListener,
            Configuration configuration,
            ExecutorRestClient restClient,
            CheckExecutor checker); @PostConstruct void onInit(); @Scheduled(fixedDelay = 2000, initialDelay = 500) void checkExecutors(); @Async void asyncStartExecutions(); void cancelExecution(Execution execution, String userRequest);  }
@Test public void cancelExecution() throws MonitorException { ExecutionSource executions = Mockito.mock(ExecutionSource.class); Execution execution = Mockito.mock(Execution.class); Mockito.when(execution.getStatus()).thenReturn(ExecutionStatus.RUNNING); Mockito.when(executions.getExecution(Mockito.any(Executor.class))) .thenReturn(execution); ExecutorEventListener eventListener = null; Configuration configuration = Mockito.mock(Configuration.class); Mockito.when(configuration.getExecutorUri()).thenReturn("iri"); ExecutorRestClient restClient = Mockito.mock(ExecutorRestClient.class); CheckExecutor checker = Mockito.mock(CheckExecutor.class); ExecutorService service = new ExecutorService( executions, eventListener, configuration, restClient, checker); service.onInit(); service.cancelExecution(execution, "request"); Mockito.verify(restClient, Mockito.times(1)) .cancel(Mockito.any(), Mockito.eq("request")); }