SymbolGroupDAO { public void update(User user, SymbolGroup group) throws NotFoundException, ValidationException { final Project project = projectRepository.findById(group.getProjectId()).orElse(null); final SymbolGroup groupInDB = symbolGroupRepository.findById(group.getId()).orElse(null); checkAccess(user, project, groupInDB); if (!group.getName().equals(groupInDB.getName())) { group.setName(createGroupName(project, group)); } if (group.getParentId() != null && group.getParentId().equals(groupInDB.getId())) { throw new ValidationException("A group cannot have itself as child."); } final SymbolGroup defaultGroup = symbolGroupRepository.findFirstByProject_IdOrderByIdAsc(project.getId()); if (defaultGroup.equals(groupInDB) && group.getParentId() != null) { throw new ValidationException("The default group cannot be a child of another group."); } groupInDB.setProject(project); groupInDB.setName(group.getName()); symbolGroupRepository.save(groupInDB); } @Autowired  SymbolGroupDAO(ProjectRepository projectRepository, ProjectDAO projectDAO,
                          SymbolGroupRepository symbolGroupRepository, SymbolRepository symbolRepository,
                          @Lazy SymbolDAO symbolDAO, ObjectMapper objectMapper); List<SymbolGroup> importGroups(User user, Long projectId, SymbolGroupsImportableEntity importableEntity); List<SymbolGroup> importGroups(User user, Project project, List<SymbolGroup> groups, Map<String, SymbolImportConflictResolutionStrategy> conflictResolutions); void create(User user, SymbolGroup group); List<SymbolGroup> create(User user, Long projectId, List<SymbolGroup> groups); List<SymbolGroup> getAll(User user, long projectId); SymbolGroup get(User user, long projectId, Long groupId); void update(User user, SymbolGroup group); SymbolGroup move(User user, SymbolGroup group); void delete(User user, long projectId, Long groupId); void checkAccess(User user, Project project, SymbolGroup group);  }
@Test public void shouldUpdateAGroup() throws NotFoundException { User user = new User(); user.setId(USER_ID); Project project = new Project(); project.setId(PROJECT_ID); project.addOwner(user); SymbolGroup group = new SymbolGroup(); group.setName("A group"); group.setId(GROUP_ID); group.setProject(project); SymbolGroup defaultGroup = new SymbolGroup(); defaultGroup.setId(GROUP_ID + 1); given(projectRepository.findById(PROJECT_ID)).willReturn(Optional.of(project)); given(symbolGroupRepository.findById(GROUP_ID)).willReturn(Optional.of(group)); given(symbolGroupRepository.findFirstByProject_IdOrderByIdAsc(PROJECT_ID)).willReturn(defaultGroup); symbolGroupDAO.update(user, group); verify(symbolGroupRepository).save(group); }