@Test void getInfoAboutUserHabitsOneTest() { CalendarUsefulHabitsDto calendarUsefulHabitsDto = new CalendarUsefulHabitsDto(); calendarUsefulHabitsDto.setAllItemsPerMonth(Collections.singletonList( new HabitLogItemDto(null, 0))); calendarUsefulHabitsDto.setCreationDate(zonedDateTime); calendarUsefulHabitsDto.setDifferenceUnTakenItemsWithPreviousDay( Collections.singletonList(new HabitLogItemDto(null, 0))); when(habitRepo.findAllByUserId(anyLong())).thenReturn(Optional.of(Collections.singletonList(habit))); when(dateService.getDatasourceZonedDateTime()).thenReturn(zonedDateTime); when(habitStatisticRepo.getSumOfAllItemsPerMonth(1L, zonedDateTime)) .thenReturn(Optional.of(0)); assertEquals(calendarUsefulHabitsDto, habitStatisticService.getInfoAboutUserHabits(anyLong())); }
@Override public CalendarUsefulHabitsDto getInfoAboutUserHabits(Long userId) { List<Habit> allHabitsByUserId = findAllHabitsByStatus(userId, true); List<HabitLogItemDto> statisticByHabitsPerMonth = getAmountOfUnTakenItemsPerMonth(allHabitsByUserId); List<HabitLogItemDto> statisticUnTakenItemsWithPrevMonth = getDifferenceItemsWithPrevDay(allHabitsByUserId); CalendarUsefulHabitsDto dto = new CalendarUsefulHabitsDto(); dto.setCreationDate(allHabitsByUserId.get(0).getCreateDate()); dto.setAllItemsPerMonth(statisticByHabitsPerMonth); dto.setDifferenceUnTakenItemsWithPreviousDay(statisticUnTakenItemsWithPrevMonth); return dto; }
HabitStatisticServiceImpl implements HabitStatisticService { @Override public CalendarUsefulHabitsDto getInfoAboutUserHabits(Long userId) { List<Habit> allHabitsByUserId = findAllHabitsByStatus(userId, true); List<HabitLogItemDto> statisticByHabitsPerMonth = getAmountOfUnTakenItemsPerMonth(allHabitsByUserId); List<HabitLogItemDto> statisticUnTakenItemsWithPrevMonth = getDifferenceItemsWithPrevDay(allHabitsByUserId); CalendarUsefulHabitsDto dto = new CalendarUsefulHabitsDto(); dto.setCreationDate(allHabitsByUserId.get(0).getCreateDate()); dto.setAllItemsPerMonth(statisticByHabitsPerMonth); dto.setDifferenceUnTakenItemsWithPreviousDay(statisticUnTakenItemsWithPrevMonth); return dto; } }
HabitStatisticServiceImpl implements HabitStatisticService { @Override public CalendarUsefulHabitsDto getInfoAboutUserHabits(Long userId) { List<Habit> allHabitsByUserId = findAllHabitsByStatus(userId, true); List<HabitLogItemDto> statisticByHabitsPerMonth = getAmountOfUnTakenItemsPerMonth(allHabitsByUserId); List<HabitLogItemDto> statisticUnTakenItemsWithPrevMonth = getDifferenceItemsWithPrevDay(allHabitsByUserId); CalendarUsefulHabitsDto dto = new CalendarUsefulHabitsDto(); dto.setCreationDate(allHabitsByUserId.get(0).getCreateDate()); dto.setAllItemsPerMonth(statisticByHabitsPerMonth); dto.setDifferenceUnTakenItemsWithPreviousDay(statisticUnTakenItemsWithPrevMonth); return dto; } @Autowired  HabitStatisticServiceImpl(HabitStatisticRepo habitStatisticRepo,
                                     HabitRepo habitRepo,
                                     HabitService habitService, ModelMapper modelMapper,
                                     DateService dateService); }
HabitStatisticServiceImpl implements HabitStatisticService { @Override public CalendarUsefulHabitsDto getInfoAboutUserHabits(Long userId) { List<Habit> allHabitsByUserId = findAllHabitsByStatus(userId, true); List<HabitLogItemDto> statisticByHabitsPerMonth = getAmountOfUnTakenItemsPerMonth(allHabitsByUserId); List<HabitLogItemDto> statisticUnTakenItemsWithPrevMonth = getDifferenceItemsWithPrevDay(allHabitsByUserId); CalendarUsefulHabitsDto dto = new CalendarUsefulHabitsDto(); dto.setCreationDate(allHabitsByUserId.get(0).getCreateDate()); dto.setAllItemsPerMonth(statisticByHabitsPerMonth); dto.setDifferenceUnTakenItemsWithPreviousDay(statisticUnTakenItemsWithPrevMonth); return dto; } @Autowired  HabitStatisticServiceImpl(HabitStatisticRepo habitStatisticRepo,
                                     HabitRepo habitRepo,
                                     HabitService habitService, ModelMapper modelMapper,
                                     DateService dateService); @Transactional @CacheEvict(value = CacheConstants.HABIT_ITEM_STATISTIC_CACHE, allEntries = true) @Override AddHabitStatisticDto save(AddHabitStatisticDto dto); @Transactional @CacheEvict(value = CacheConstants.HABIT_ITEM_STATISTIC_CACHE, allEntries = true) @Override UpdateHabitStatisticDto update(Long habitStatisticId, UpdateHabitStatisticDto dto); @Override HabitStatistic findById(Long id); @Override List<Habit> findAllHabitsByUserId(Long userId); @Override List<Habit> findAllHabitsByStatus(Long userId, Boolean status); @Override List<HabitDto> findAllHabitsAndTheirStatistics(Long id, Boolean status, String language); @Override CalendarUsefulHabitsDto getInfoAboutUserHabits(Long userId); @Override List<HabitStatisticDto> findAllByHabitId(Long habitId); @Cacheable(value = CacheConstants.HABIT_ITEM_STATISTIC_CACHE, key = "#language") @Override List<HabitItemsAmountStatisticDto> getTodayStatisticsForAllHabitItems(String language); @Override Long getAmountOfHabitsInProgressByUserId(Long id); @Override Long getAmountOfAcquiredHabitsByUserId(Long id); }
HabitStatisticServiceImpl implements HabitStatisticService { @Override public CalendarUsefulHabitsDto getInfoAboutUserHabits(Long userId) { List<Habit> allHabitsByUserId = findAllHabitsByStatus(userId, true); List<HabitLogItemDto> statisticByHabitsPerMonth = getAmountOfUnTakenItemsPerMonth(allHabitsByUserId); List<HabitLogItemDto> statisticUnTakenItemsWithPrevMonth = getDifferenceItemsWithPrevDay(allHabitsByUserId); CalendarUsefulHabitsDto dto = new CalendarUsefulHabitsDto(); dto.setCreationDate(allHabitsByUserId.get(0).getCreateDate()); dto.setAllItemsPerMonth(statisticByHabitsPerMonth); dto.setDifferenceUnTakenItemsWithPreviousDay(statisticUnTakenItemsWithPrevMonth); return dto; } @Autowired  HabitStatisticServiceImpl(HabitStatisticRepo habitStatisticRepo,
                                     HabitRepo habitRepo,
                                     HabitService habitService, ModelMapper modelMapper,
                                     DateService dateService); @Transactional @CacheEvict(value = CacheConstants.HABIT_ITEM_STATISTIC_CACHE, allEntries = true) @Override AddHabitStatisticDto save(AddHabitStatisticDto dto); @Transactional @CacheEvict(value = CacheConstants.HABIT_ITEM_STATISTIC_CACHE, allEntries = true) @Override UpdateHabitStatisticDto update(Long habitStatisticId, UpdateHabitStatisticDto dto); @Override HabitStatistic findById(Long id); @Override List<Habit> findAllHabitsByUserId(Long userId); @Override List<Habit> findAllHabitsByStatus(Long userId, Boolean status); @Override List<HabitDto> findAllHabitsAndTheirStatistics(Long id, Boolean status, String language); @Override CalendarUsefulHabitsDto getInfoAboutUserHabits(Long userId); @Override List<HabitStatisticDto> findAllByHabitId(Long habitId); @Cacheable(value = CacheConstants.HABIT_ITEM_STATISTIC_CACHE, key = "#language") @Override List<HabitItemsAmountStatisticDto> getTodayStatisticsForAllHabitItems(String language); @Override Long getAmountOfHabitsInProgressByUserId(Long id); @Override Long getAmountOfAcquiredHabitsByUserId(Long id);  }