### Question:
AddUserProblemFactChange implements ProblemFactChange<TaskAssigningSolution> { @Override public void doChange(ScoreDirector<TaskAssigningSolution> scoreDirector) { final TaskAssigningSolution workingSolution = scoreDirector.getWorkingSolution(); final User workingUser = scoreDirector.lookUpWorkingObjectOrReturnNull(user); if (workingUser != null) { throw new TaskAssigningRuntimeException(String.format("A user with the given identifier id: %s already exists", user.getEntityId())); } workingSolution.setUserList(new ArrayList<>(workingSolution.getUserList())); scoreDirector.beforeProblemFactAdded(user); workingSolution.getUserList().add(user); scoreDirector.afterProblemFactAdded(user); scoreDirector.triggerVariableListeners(); } AddUserProblemFactChange(User user); User getUser(); @Override void doChange(ScoreDirector<TaskAssigningSolution> scoreDirector);  }### Answer:
@Test public void doChange() { change.doChange(scoreDirector); verify(scoreDirector).beforeProblemFactAdded(user); verify(scoreDirector).afterProblemFactAdded(user); verify(scoreDirector).triggerVariableListeners(); assertThat(workingSolution.getUserList()).contains(user); }
@Test public void doChangeUserAlreadyExists() { when(scoreDirector.lookUpWorkingObjectOrReturnNull(user)).thenReturn(user); assertThatThrownBy(() -> change.doChange(scoreDirector)) .hasMessage(String.format("A user with the given identifier id: %s already exists", USER_ID)); }