### Question:
DelegateAndSaveCommand extends PlanningCommand { @Override public Void execute(Context context) { super.execute(context); final Task task = taskContext.getPersistenceContext().findTask(planningItem.getTaskId()); if (task == null) { throw new PlanningException(String.format(TASK_MODIFIED_ERROR_MSG_1, planningItem.getTaskId()), planningItem.getContainerId(), PlanningExecutionResult.ErrorCode.TASK_MODIFIED_SINCE_PLAN_CALCULATION_ERROR); } final org.kie.api.task.model.TaskData taskData = task.getTaskData(); final Status status = taskData.getStatus(); if (!(Ready == status || Reserved == status)) { throw new PlanningException(String.format(TASK_MODIFIED_ERROR_MSG, planningItem.getTaskId(), status, Arrays.toString(new Status[]{Ready, Reserved})), planningItem.getContainerId(), PlanningExecutionResult.ErrorCode.TASK_MODIFIED_SINCE_PLAN_CALCULATION_ERROR); } final OrganizationalEntity existingPotentialOwner = findPotentialOwner(task, planningItem.getPlanningTask().getAssignedUser()); DelegateTaskCommand delegateTaskCommand = createDelegateCommand(planningItem.getTaskId(), getUserId(), planningItem.getPlanningTask().getAssignedUser()); delegateTaskCommand.execute(context); if (existingPotentialOwner == null) { OrganizationalEntity addedPotentialOwner = findPotentialOwner(task, planningItem.getPlanningTask().getAssignedUser()); if (addedPotentialOwner != null) { task.getPeopleAssignments().getPotentialOwners().remove(addedPotentialOwner); } } saveOrUpdatePlanningTask(planningItem); return null; } DelegateAndSaveCommand(PlanningItem planningItem, String userId); @Override Void execute(Context context);  }### Answer:
@Test public void execute() { if (statusIsValid) { executeWithValidStatus(status, potentialOwnerBelongsToTask, previousPlanningTask); if (potentialOwnerBelongsToTask) { assertThat(potentialOwners).contains(organizationalEntity); } else { assertThat(potentialOwners).doesNotContain(organizationalEntity); } } else { executeWithInvalidStatus(status, previousPlanningTask); } }
@Test public void executeWithDeletedTask() { when(persistenceContext.findTask(TASK_ID)).thenReturn(null); Assertions.assertThatThrownBy(() -> command.execute(taskContext)).hasMessage(String.format(TASK_MODIFIED_ERROR_MSG_1, TASK_ID)); }