@Test public void findAllByUserWithExistentIdTest() { CustomGoal customGoal = new CustomGoal(1L, "foo", user, null); CustomGoalResponseDto customGoalResponseDto = new CustomGoalResponseDto(customGoal.getId(), customGoal.getText()); when(customGoalRepo.findAllByUserId(user.getId())).thenReturn(Collections.singletonList(customGoal)); when(modelMapper.map(customGoal, CustomGoalResponseDto.class)) .thenReturn(customGoalResponseDto); List<CustomGoalResponseDto> findAllByUserResult = customGoalService.findAllByUser(user.getId()); assertEquals(findAllByUserResult.get(0).getId(), customGoalResponseDto.getId()); assertEquals(findAllByUserResult.get(0).getText(), customGoalResponseDto.getText()); }
@Transactional @Override public List<CustomGoalResponseDto> findAllByUser(Long userId) { List<CustomGoalResponseDto> customGoals = customGoalRepo.findAllByUserId(userId).stream() .map(customGoal -> modelMapper.map(customGoal, CustomGoalResponseDto.class)) .collect(Collectors.toList()); if (!customGoals.isEmpty()) { return customGoals; } else { throw new NotFoundException(CUSTOM_GOAL_NOT_FOUND); } }
CustomGoalServiceImpl implements CustomGoalService { @Transactional @Override public List<CustomGoalResponseDto> findAllByUser(Long userId) { List<CustomGoalResponseDto> customGoals = customGoalRepo.findAllByUserId(userId).stream() .map(customGoal -> modelMapper.map(customGoal, CustomGoalResponseDto.class)) .collect(Collectors.toList()); if (!customGoals.isEmpty()) { return customGoals; } else { throw new NotFoundException(CUSTOM_GOAL_NOT_FOUND); } } }
CustomGoalServiceImpl implements CustomGoalService { @Transactional @Override public List<CustomGoalResponseDto> findAllByUser(Long userId) { List<CustomGoalResponseDto> customGoals = customGoalRepo.findAllByUserId(userId).stream() .map(customGoal -> modelMapper.map(customGoal, CustomGoalResponseDto.class)) .collect(Collectors.toList()); if (!customGoals.isEmpty()) { return customGoals; } else { throw new NotFoundException(CUSTOM_GOAL_NOT_FOUND); } }  }
CustomGoalServiceImpl implements CustomGoalService { @Transactional @Override public List<CustomGoalResponseDto> findAllByUser(Long userId) { List<CustomGoalResponseDto> customGoals = customGoalRepo.findAllByUserId(userId).stream() .map(customGoal -> modelMapper.map(customGoal, CustomGoalResponseDto.class)) .collect(Collectors.toList()); if (!customGoals.isEmpty()) { return customGoals; } else { throw new NotFoundException(CUSTOM_GOAL_NOT_FOUND); } }  @Transactional @Override List<CustomGoalResponseDto> save(BulkSaveCustomGoalDto bulkSave, User user); @Transactional @Override List<CustomGoalResponseDto> findAll(); @Transactional @Override CustomGoalResponseDto findById(Long id); @Transactional @Override List<CustomGoalResponseDto> updateBulk(BulkCustomGoalDto bulkCustomGoalDto); @Transactional @Override List<CustomGoalResponseDto> findAllByUser(Long userId); @Transactional @Override List<Long> bulkDelete(String ids); }
CustomGoalServiceImpl implements CustomGoalService { @Transactional @Override public List<CustomGoalResponseDto> findAllByUser(Long userId) { List<CustomGoalResponseDto> customGoals = customGoalRepo.findAllByUserId(userId).stream() .map(customGoal -> modelMapper.map(customGoal, CustomGoalResponseDto.class)) .collect(Collectors.toList()); if (!customGoals.isEmpty()) { return customGoals; } else { throw new NotFoundException(CUSTOM_GOAL_NOT_FOUND); } }  @Transactional @Override List<CustomGoalResponseDto> save(BulkSaveCustomGoalDto bulkSave, User user); @Transactional @Override List<CustomGoalResponseDto> findAll(); @Transactional @Override CustomGoalResponseDto findById(Long id); @Transactional @Override List<CustomGoalResponseDto> updateBulk(BulkCustomGoalDto bulkCustomGoalDto); @Transactional @Override List<CustomGoalResponseDto> findAllByUser(Long userId); @Transactional @Override List<Long> bulkDelete(String ids);  }