LearnerResultDAO { public List<LearnerResult> getAll(User user, Long projectId) throws NotFoundException { projectDAO.getByID(user, projectId); final List<LearnerResult> results = learnerResultRepository.findByProject_Id(projectId); results.forEach(this::initializeLazyRelations); return results; } @Autowired  LearnerResultDAO(ProjectDAO projectDAO, LearnerResultRepository learnerResultRepository,
                            LearnerResultStepRepository learnerResultStepRepository, EntityManager entityManager,
                            LearnerSetupDAO learnerSetupDAO); LearnerResult create(User user, Project project, LearnerResult learnerResult); List<LearnerResult> getAll(User user, Long projectId); List<LearnerResult> getAll(User user, Long projectId, List<Long> testNos); Page<LearnerResult> getAll(User user, Long projectId, PageRequest pr); LearnerResult getLatest(User user, Long projectId); LearnerResult get(User user, Long projectId, Long testNo); LearnerResultStep createStep(LearnerResult result); LearnerResult copy(User user, Long projectId, Long testNo); LearnerResultStep createStep(LearnerResult result, LearnerResultStep step); LearnerResultStep updateStep(LearnerResultStep step); void deleteAll(User user, Long projectId, List<Long> testNos); void initializeLazyRelations(LearnerResult result); void checkAccess(User user, Project project, LearnerResult learnerResult);  }
@Test public void shouldGetAllResultsOfOneProject() throws NotFoundException { User user = new User(); List<LearnerResult> results = createLearnerResultsList(); given(learnerResultRepository.findByProject_Id(PROJECT_ID)).willReturn(results); List<LearnerResult> resultsFromDAO = learnerResultDAO.getAll(user, PROJECT_ID); assertThat(results.size(), is(equalTo(resultsFromDAO.size()))); for (LearnerResult r : resultsFromDAO) { assertTrue(results.contains(r)); } }
@Test public void ensureThatGettingAllResultsReturnsAnEmptyListIfNoLearnerResultCouldBeFound() throws NotFoundException { User user = new User(); given(learnerResultRepository.findByProject_Id(PROJECT_ID)) .willReturn(Collections.emptyList()); List<LearnerResult> results = learnerResultDAO.getAll(user, PROJECT_ID); assertEquals(results.size(), 0); }
@Test public void shouldGetMultipleResults() throws NotFoundException { User user = new User(); List<LearnerResult> results = createLearnerResultsList(); List<Long> testNos = Arrays.asList(0L, 1L, 2L); given(learnerResultRepository.findByProject_IdAndTestNoIn(PROJECT_ID, testNos)) .willReturn(results); List<LearnerResult> resultsFromDAO = learnerResultDAO.getAll(user, PROJECT_ID, testNos); assertThat(results.size(), is(equalTo(resultsFromDAO.size()))); for (LearnerResult r : resultsFromDAO) { assertTrue(results.contains(r)); } }