// TaskService
InternalTaskService injectedTaskServiceMock = mock(InternalTaskService.class);
// - set task instance
InternalTask task = new TaskImpl();
task.setId(TASK_ID);
task.setTaskData(new TaskDataImpl());
doThrow(new IllegalStateException("Use the getTaskById() method, which should already have been called!"))
.when(injectedTaskServiceMock).execute(any(GetTaskCommand.class));
doReturn(task).when(injectedTaskServiceMock).getTaskById(TASK_ID);
// task is independent
if (independentTask) {
// no deployment id == independent task
((InternalTaskData) task.getTaskData()).setDeploymentId(null);
// runtime task engine should not be used
doThrow(new IllegalStateException("The runtime engine TaskService should not be used here!")).when(runtimeEngineMock).getTaskService();
// - injected task service should execute commands
doReturn(null).when(injectedTaskServiceMock).execute(any(ClaimTaskCommand.class));
doReturn(null).when(injectedTaskServiceMock).execute(any(StartTaskCommand.class));
doReturn(null).when(injectedTaskServiceMock).execute(any(CompleteTaskCommand.class));
doReturn(null).when(injectedTaskServiceMock).execute(any(ReleaseTaskCommand.class));
doReturn(null).when(injectedTaskServiceMock).execute(any(ExitTaskCommand.class));
doReturn(null).when(injectedTaskServiceMock).execute(any(SkipTaskCommand.class));
} else {
// deployment id available == process task
((InternalTaskData) task.getTaskData()).setDeploymentId(DEPLOYMENT_ID);
// - injected task service should only be used to retrieve task
doReturn(runtimeTaskServiceMock).when(runtimeEngineMock).getTaskService();
// - runtime engine should execute commands affecting kiesssions