### Question:
EditGroupsVm extends AbstractDialogVm { @GlobalCommand(SAVE_CHANGES) @NotifyChange(SHOW_DIALOG) public void saveChanges() { List<Group> userGroups = userToEdit.getGroups(); boolean changed = false; for (GroupBooleanPair group : groups) { Group currentGroup = group.getGroup(); if (group.isChanged()) { if (group.isEnable()) { userGroups.add(group.getGroup()); currentGroup.getUsers().add(userToEdit); } else { userGroups.remove(group.getGroup()); currentGroup.getUsers().remove(userToEdit); } groupService.saveGroup(currentGroup); changed = true; } } if (changed) { userService.updateUser(userToEdit); } closeDialog(); } EditGroupsVm(UsersVm usersVm, UserService userService, GroupService groupService); @GlobalCommand(EDIT_GROUPS) @NotifyChange({SHOW_DIALOG, GROUPS, USER_TO_EDIT, CHOSEN, NOT_CHOSEN}) void editGroups(); @GlobalCommand(FILTER_GROUPS) @NotifyChange(GROUPS) void filterGroups(); @GlobalCommand(SAVE_CHANGES) @NotifyChange(SHOW_DIALOG) void saveChanges(); boolean isChosen(); void setChosen(boolean chosen); boolean isNotChosen(); void setNotChosen(boolean notChosen); List<GroupBooleanPair> getGroups(); User getUserToEdit(); List<GroupBooleanPair> getGroupsToShow();  }### Answer:
@Test public void saveChangesTest() throws NotFoundException { int expectedSizeAllGroups = allGroups.size(); int expectedSizeUserGroups = 3; vm.editGroups(); vm.getGroups().get(0).setEnable(false); vm.getGroups().get(1).setEnable(true); vm.getGroups().get(4).setEnable(true); vm.saveChanges(); Assert.assertTrue(vm.isChosen()); Assert.assertTrue(vm.isNotChosen()); Assert.assertEquals(expectedSizeUserGroups, userGroups.size()); Assert.assertEquals(expectedSizeAllGroups, allGroups.size()); Assert.assertNotSame("A", userGroups.get(0).getName()); verify(userService).updateUser((PoulpeUser) vm.getUserToEdit()); verify(groupService).saveGroup(vm.getGroups().get(0).getGroup()); verify(groupService).saveGroup(vm.getGroups().get(1).getGroup()); verify(groupService, times(0)).saveGroup(vm.getGroups().get(2).getGroup()); verify(groupService, times(0)).saveGroup(vm.getGroups().get(3).getGroup()); verify(groupService).saveGroup(vm.getGroups().get(4).getGroup()); }