ProjectDAO { public Project getByID(User user, Long projectId) throws NotFoundException { final Project project = projectRepository.findById(projectId).orElse(null); checkAccess(user, project); loadLazyRelations(project); return project; } @Autowired  ProjectDAO(ProjectRepository projectRepository,
                      LearnerResultRepository learnerResultRepository,
                      TestReportRepository testReportRepository,
                      @Lazy FileDAO fileDAO,
                      ParameterizedSymbolRepository parameterizedSymbolRepository,
                      SymbolStepRepository symbolStepRepository,
                      SymbolActionRepository symbolActionRepository,
                      @Lazy ProjectEnvironmentDAO projectEnvironmentDAO,
                      ProjectUrlRepository projectUrlRepository,
                      TestExecutionConfigRepository testExecutionConfigRepository,
                      @Lazy TestDAO testDAO,
                      @Lazy UserDAO userDAO,
                      ProjectEnvironmentRepository environmentRepository,
                      @Lazy SymbolGroupDAO symbolGroupDAO,
                      TestRepository testRepository,
                      SymbolParameterRepository symbolParameterRepository,
                      UploadableFileRepository uploadableFileRepository,
                      LearnerSetupRepository learnerSetupRepository); Project create(final User user, final CreateProjectForm projectForm); List<Project> getAll(User user); Project getByID(User user, Long projectId); Project update(User user, Long projectId, Project project); void delete(User user, Long projectId); void delete(User user, List<Long> projectIds); Project importProject(User user, ProjectExportableEntity projectExportableEntity); void checkAccess(User user, Project project); Project addOwners(User user, Long projectId, List<Long> ownerIds); Project addMembers(User user, Long projectId, List<Long> memberIds); Project removeOwners(User user, Long projectId, List<Long> ownerIds); Project removeMembers(User user, Long projectId, List<Long> memberIds);  }
@Test public void shouldGetAProjectByItsID() throws NotFoundException { User user = new User(USER_ID); Project project = new Project(); project.addOwner(user); given(projectRepository.findById(PROJECT_ID)).willReturn(Optional.of(project)); Project p = projectDAO.getByID(user, PROJECT_ID); assertThat(p, is(equalTo(project))); }
@Test(expected = NotFoundException.class) public void shouldThrowAnExceptionIfTheProjectCanNotFoundByID() throws NotFoundException { given(projectRepository.findById(PROJECT_ID)).willReturn(Optional.empty()); projectDAO.getByID(user, PROJECT_ID); }