ExecutorService { private void startExecution(Execution execution, Executor executor) { try { this.restClient.start(executor, execution); this.eventListener.onExecutorHasExecution(execution, executor); } catch (Exception ex) { LOG.error("Can't start execution.", ex); } } @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 startExecution() throws MonitorException { ExecutionSource executions = Mockito.mock(ExecutionSource.class); Execution execution = Mockito.mock(Execution.class); Mockito.when(execution.getStatus()).thenReturn(ExecutionStatus.QUEUED); Mockito.when(executions.getExecutions()) .thenReturn(Arrays.asList(execution)); ExecutorEventListener eventListener = Mockito .mock(ExecutorEventListener.class); Configuration configuration = Mockito.mock(Configuration.class); Mockito.when(configuration.getExecutorUri()).thenReturn("iri"); ExecutorRestClient restClient = Mockito.mock(ExecutorRestClient.class); CheckExecutor checker = Mockito.mock(CheckExecutor.class); Mockito.doAnswer((call) -> { call.getArgument(0, Executor.class).setAlive(true); return null; }).when(checker).check(Mockito.any()); ExecutorService service = new ExecutorService( executions, eventListener, configuration, restClient, checker); service.onInit(); service.checkExecutors(); Mockito.verify(restClient, Mockito.times(1)) .start(Mockito.any(), Mockito.eq(execution)); Mockito.verify(eventListener, Mockito.times(1)) .onExecutorHasExecution(Mockito.eq(execution), Mockito.any()); }