### Question:
TransactionalGroupService extends AbstractTransactionalEntityService<Group, GroupDao> implements GroupService { @Override public void saveOrUpdate(GroupAdministrationDto dto) throws NotFoundException { assertGroupNameUnique(dto); Group group = dto.getId() != null ? dao.get(dto.getId()) : new Group(); if (group == null) { throw new NotFoundException("Group with id " + dto.getId() + " is not found"); } if (!isGroupEditable(group.getName())) { logger.warn("Attempt to edit pre-defined usergoup {}", group.getName()); throw new OperationIsNotAllowedException("Pre-defined usergoup " + group.getName() + " is not editable"); } dao.saveOrUpdate(dto.fillEntity(group)); } TransactionalGroupService(GroupDao groupDao,
                                     AclManager manager,
                                     UserDao userDao,
                                     SecurityService securityService); @Override List<Group> getAll(); @Override SecurityGroupList getSecurityGroups(); @Override List<Group> getByNameContains(String name); @Override List<Group> getByName(String name); @Override Page<UserDto> getPagedGroupUsers(long id, PageRequest pageRequest); @Override void deleteGroup(Group group); @Override void saveGroup(Group group); @Override void saveOrUpdate(GroupAdministrationDto dto); @Override List<GroupAdministrationDto> getGroupNamesWithCountOfUsers();  }### Answer:
@Test(expectedExceptions = NotFoundException.class) public void throwsIfEditingNonExistingGroup() throws NotFoundException { when(groupDao.get(anyLong())).thenReturn(null); groupService.saveOrUpdate(new GroupAdministrationDto(100500L, "not exist", "not exists", 0)); }
@Test(expectedExceptions = ValidationException.class) public void throwsIfSavingNewGroupWithNotUniqueName() throws NotFoundException { when(groupDao.getGroupByName("existing name")).thenReturn(new Group("existing name")); groupService.saveOrUpdate(new GroupAdministrationDto(null, "existing name", "some description", 100)); }
@Test(expectedExceptions = OperationIsNotAllowedException.class) public void throwsIfEditingPredefinedGroup() throws NotFoundException { when(groupDao.get(1L)).thenReturn(new Group(sample(PREDEFINED_GROUP_NAMES))); groupService.saveOrUpdate(new GroupAdministrationDto(1L, "new group name", "some description", 100)); }