CounterDAO { public Counter update(User user, Counter counter) throws NotFoundException, ValidationException { final Counter counterIdDb = doGet(user, counter.getProjectId(), counter.getId()); if (!counterIdDb.getName().equals(counter.getName())) { throw new ValidationException("counters cannot be renamed"); } counterIdDb.setValue(counter.getValue()); return counterRepository.save(counterIdDb); } @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 shouldUpdateACounter() throws NotFoundException { final Long counterId = 1L; User user = new User(); user.setId(USER_ID); Project project = new Project(); project.setId(PROJECT_ID); Counter counter = new Counter(); counter.setProject(project); counter.setName(COUNTER_NAME); counter.setId(counterId); given(projectRepository.findById(PROJECT_ID)).willReturn(Optional.of(project)); given(counterRepository.findById(counterId)).willReturn(Optional.of(counter)); counterDAO.update(user, counter); verify(counterRepository).save(counter); }