SymbolGroupDAO { public void create(User user, SymbolGroup group) throws NotFoundException, ValidationException { LOGGER.traceEntry("create({})", group); final Project project = projectRepository.findById(group.getProjectId()).orElse(null); projectDAO.checkAccess(user, project); group.setId(null); group.setName(createGroupName(project, group)); project.addGroup(group); beforePersistGroup(group); if (group.getParentId() != null) { final SymbolGroup parent = symbolGroupRepository.findById(group.getParentId()).orElse(null); checkAccess(user, project, parent); group.setParent(parent); parent.getGroups().add(parent); symbolGroupRepository.save(parent); } symbolGroupRepository.save(group); LOGGER.traceExit(group); } @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 shouldCreateAValidGroup() 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.setProject(project); given(projectRepository.findById(PROJECT_ID)).willReturn(Optional.of(project)); given(symbolGroupRepository.save(group)).willReturn(group); symbolGroupDAO.create(user, group); verify(symbolGroupRepository).save(group); }