@Test public void doChange() { List<Task> workingUserTasks = Arrays.asList(mockTask(TASK_ID1, true), mockTask(TASK_ID2, true), mockTask(TASK_ID3, false), mockTask(TASK_ID4, false)); User workingUser = mockUser(USER_ID_1, workingUserTasks); workingUser.setEnabled(true); workingSolution.getUserList().add(workingUser); int originalUsersSize = workingSolution.getUserList().size(); when(scoreDirector.lookUpWorkingObjectOrReturnNull(user)).thenReturn(workingUser); change.doChange(scoreDirector); verify(scoreDirector).beforeProblemPropertyChanged(workingUser); verify(scoreDirector).afterProblemPropertyChanged(workingUser); verify(scoreDirector).triggerVariableListeners(); assertThat(workingUser.isEnabled()).isFalse(); workingUserTasks.forEach(task -> assertTaskWasReleased(task, scoreDirector)); verify(scoreDirector).beforeProblemFactRemoved(workingUser); verify(scoreDirector).afterProblemFactRemoved(workingUser); assertThat(workingSolution.getUserList().size()).isEqualTo(originalUsersSize - 1); assertThat(workingSolution.getUserList()).contains(user2, user3); assertThat(workingSolution.getUserList()).doesNotContain(workingUser); }
@Override public void doChange(ScoreDirector<TaskAssigningSolution> scoreDirector) { final TaskAssigningSolution workingSolution = scoreDirector.getWorkingSolution(); final User workingUser = scoreDirector.lookUpWorkingObjectOrReturnNull(user); if (workingUser == null) { return; } if (workingUser.isEnabled()) { scoreDirector.beforeProblemPropertyChanged(workingUser); workingUser.setEnabled(false); scoreDirector.afterProblemPropertyChanged(workingUser); } releaseAllTasks(workingUser, scoreDirector); workingSolution.setUserList(new ArrayList<>(workingSolution.getUserList())); scoreDirector.beforeProblemFactRemoved(workingUser); workingSolution.getUserList().remove(workingUser); scoreDirector.afterProblemFactRemoved(workingUser); scoreDirector.triggerVariableListeners(); }
RemoveUserProblemFactChange implements ProblemFactChange<TaskAssigningSolution> { @Override public void doChange(ScoreDirector<TaskAssigningSolution> scoreDirector) { final TaskAssigningSolution workingSolution = scoreDirector.getWorkingSolution(); final User workingUser = scoreDirector.lookUpWorkingObjectOrReturnNull(user); if (workingUser == null) { return; } if (workingUser.isEnabled()) { scoreDirector.beforeProblemPropertyChanged(workingUser); workingUser.setEnabled(false); scoreDirector.afterProblemPropertyChanged(workingUser); } releaseAllTasks(workingUser, scoreDirector); workingSolution.setUserList(new ArrayList<>(workingSolution.getUserList())); scoreDirector.beforeProblemFactRemoved(workingUser); workingSolution.getUserList().remove(workingUser); scoreDirector.afterProblemFactRemoved(workingUser); scoreDirector.triggerVariableListeners(); } }
RemoveUserProblemFactChange implements ProblemFactChange<TaskAssigningSolution> { @Override public void doChange(ScoreDirector<TaskAssigningSolution> scoreDirector) { final TaskAssigningSolution workingSolution = scoreDirector.getWorkingSolution(); final User workingUser = scoreDirector.lookUpWorkingObjectOrReturnNull(user); if (workingUser == null) { return; } if (workingUser.isEnabled()) { scoreDirector.beforeProblemPropertyChanged(workingUser); workingUser.setEnabled(false); scoreDirector.afterProblemPropertyChanged(workingUser); } releaseAllTasks(workingUser, scoreDirector); workingSolution.setUserList(new ArrayList<>(workingSolution.getUserList())); scoreDirector.beforeProblemFactRemoved(workingUser); workingSolution.getUserList().remove(workingUser); scoreDirector.afterProblemFactRemoved(workingUser); scoreDirector.triggerVariableListeners(); } RemoveUserProblemFactChange(User user); }
RemoveUserProblemFactChange implements ProblemFactChange<TaskAssigningSolution> { @Override public void doChange(ScoreDirector<TaskAssigningSolution> scoreDirector) { final TaskAssigningSolution workingSolution = scoreDirector.getWorkingSolution(); final User workingUser = scoreDirector.lookUpWorkingObjectOrReturnNull(user); if (workingUser == null) { return; } if (workingUser.isEnabled()) { scoreDirector.beforeProblemPropertyChanged(workingUser); workingUser.setEnabled(false); scoreDirector.afterProblemPropertyChanged(workingUser); } releaseAllTasks(workingUser, scoreDirector); workingSolution.setUserList(new ArrayList<>(workingSolution.getUserList())); scoreDirector.beforeProblemFactRemoved(workingUser); workingSolution.getUserList().remove(workingUser); scoreDirector.afterProblemFactRemoved(workingUser); scoreDirector.triggerVariableListeners(); } RemoveUserProblemFactChange(User user); User getUser(); @Override void doChange(ScoreDirector<TaskAssigningSolution> scoreDirector); }
RemoveUserProblemFactChange implements ProblemFactChange<TaskAssigningSolution> { @Override public void doChange(ScoreDirector<TaskAssigningSolution> scoreDirector) { final TaskAssigningSolution workingSolution = scoreDirector.getWorkingSolution(); final User workingUser = scoreDirector.lookUpWorkingObjectOrReturnNull(user); if (workingUser == null) { return; } if (workingUser.isEnabled()) { scoreDirector.beforeProblemPropertyChanged(workingUser); workingUser.setEnabled(false); scoreDirector.afterProblemPropertyChanged(workingUser); } releaseAllTasks(workingUser, scoreDirector); workingSolution.setUserList(new ArrayList<>(workingSolution.getUserList())); scoreDirector.beforeProblemFactRemoved(workingUser); workingSolution.getUserList().remove(workingUser); scoreDirector.afterProblemFactRemoved(workingUser); scoreDirector.triggerVariableListeners(); } RemoveUserProblemFactChange(User user); User getUser(); @Override void doChange(ScoreDirector<TaskAssigningSolution> scoreDirector);  }