CounterDAO { public List<Counter> getAll(User user, Long projectId) throws NotFoundException { final Project project = projectRepository.findById(projectId).orElse(null); projectDAO.checkAccess(user, project); return counterRepository.findAllByProject(project); } @Autowired  CounterDAO(ProjectDAO projectDAO,
                      CounterRepository counterRepository,
                      ProjectRepository projectRepository); void create(User user, Counter counter); List<Counter> getAll(User user, Long projectId); Counter update(User user, Counter counter); void delete(User user, Long projectId, List<Long> counterIds); void checkAccess(User user, Project project, Counter counter);  }
@Test public void shouldGetAllCounterOfAProject() throws NotFoundException { User user = new User(); user.setId(USER_ID); Project project = new Project(); List<Counter> counters = createCounterList(); given(projectRepository.findById(PROJECT_ID)).willReturn(Optional.of(project)); given(counterRepository.findAllByProject(project)).willReturn(counters); List<Counter> allCounters = counterDAO.getAll(user, PROJECT_ID); MatcherAssert.assertThat(allCounters.size(), is(equalTo(counters.size()))); for (Counter c : allCounters) { assertTrue(counters.contains(c)); } }