@Test void sendWeeklyReportTest() { EmailNotification emailNotification = EmailNotification.WEEKLY; Category category = ModelUtils.getCategory(); User user = ModelUtils.getUser(); user.setEmailNotification(emailNotification); Place testPlace1 = ModelUtils.getPlace(); testPlace1.setCategory(category); testPlace1.setId(1L); Place testPlace2 = ModelUtils.getPlace(); testPlace1.setCategory(category); testPlace1.setId(2L); List<Place> testPlaces = Arrays.asList(testPlace1, testPlace2); when(userRepo.findAllByEmailNotification(emailNotification)) .thenReturn(Collections.singletonList(user)); when(modelMapper.map(user, PlaceAuthorDto.class)) .thenReturn(new PlaceAuthorDto(1L, "dto", "email")); when(placeRepo.findAllByModifiedDateBetweenAndStatus(any(LocalDateTime.class), any(LocalDateTime.class), any())) .thenReturn(testPlaces); when(modelMapper.map(testPlace1, PlaceNotificationDto.class)) .thenReturn(new PlaceNotificationDto("name", new CategoryDto("category"))); when(modelMapper.map(testPlace2, PlaceNotificationDto.class)) .thenReturn(new PlaceNotificationDto("name1", new CategoryDto("category1"))); when(modelMapper.map(testPlace1.getCategory(), CategoryDto.class)) .thenReturn(new CategoryDto("category")); when(modelMapper.map(testPlace2.getCategory(), CategoryDto.class)) .thenReturn(new CategoryDto("category1")); notificationService.sendWeeklyReport(); verify(rabbitTemplate, Mockito.times(1)) .convertAndSend(any(), anyString(), any(SendReportEmailMessage.class)); }
@Scheduled(cron = "0 0 12 ? * MON", zone = AppConstant.UKRAINE_TIMEZONE) @Override public void sendWeeklyReport() { log.info(LogMessage.IN_SEND_WEEKLY_REPORT, LocalDateTime.now(ZONE_ID)); LocalDateTime startDate = LocalDateTime.now(ZONE_ID).minusWeeks(1); sendReport(EmailNotification.WEEKLY, startDate); }
NotificationServiceImpl implements NotificationService { @Scheduled(cron = "0 0 12 ? * MON", zone = AppConstant.UKRAINE_TIMEZONE) @Override public void sendWeeklyReport() { log.info(LogMessage.IN_SEND_WEEKLY_REPORT, LocalDateTime.now(ZONE_ID)); LocalDateTime startDate = LocalDateTime.now(ZONE_ID).minusWeeks(1); sendReport(EmailNotification.WEEKLY, startDate); } }
NotificationServiceImpl implements NotificationService { @Scheduled(cron = "0 0 12 ? * MON", zone = AppConstant.UKRAINE_TIMEZONE) @Override public void sendWeeklyReport() { log.info(LogMessage.IN_SEND_WEEKLY_REPORT, LocalDateTime.now(ZONE_ID)); LocalDateTime startDate = LocalDateTime.now(ZONE_ID).minusWeeks(1); sendReport(EmailNotification.WEEKLY, startDate); } @Autowired  NotificationServiceImpl(UserRepo userRepo, PlaceRepo placeRepo,
                                   RabbitTemplate rabbitTemplate,
                                   ModelMapper modelMapper); }
NotificationServiceImpl implements NotificationService { @Scheduled(cron = "0 0 12 ? * MON", zone = AppConstant.UKRAINE_TIMEZONE) @Override public void sendWeeklyReport() { log.info(LogMessage.IN_SEND_WEEKLY_REPORT, LocalDateTime.now(ZONE_ID)); LocalDateTime startDate = LocalDateTime.now(ZONE_ID).minusWeeks(1); sendReport(EmailNotification.WEEKLY, startDate); } @Autowired  NotificationServiceImpl(UserRepo userRepo, PlaceRepo placeRepo,
                                   RabbitTemplate rabbitTemplate,
                                   ModelMapper modelMapper); @Override void sendImmediatelyReport(Place newPlace); @Scheduled(cron = "0 0 12 ? * *", zone = AppConstant.UKRAINE_TIMEZONE) @Override void sendDailyReport(); @Scheduled(cron = "0 0 12 ? * MON", zone = AppConstant.UKRAINE_TIMEZONE) @Override void sendWeeklyReport(); @Scheduled(cron = "0 0 12 1 * ?", zone = AppConstant.UKRAINE_TIMEZONE) @Override void sendMonthlyReport(); }
NotificationServiceImpl implements NotificationService { @Scheduled(cron = "0 0 12 ? * MON", zone = AppConstant.UKRAINE_TIMEZONE) @Override public void sendWeeklyReport() { log.info(LogMessage.IN_SEND_WEEKLY_REPORT, LocalDateTime.now(ZONE_ID)); LocalDateTime startDate = LocalDateTime.now(ZONE_ID).minusWeeks(1); sendReport(EmailNotification.WEEKLY, startDate); } @Autowired  NotificationServiceImpl(UserRepo userRepo, PlaceRepo placeRepo,
                                   RabbitTemplate rabbitTemplate,
                                   ModelMapper modelMapper); @Override void sendImmediatelyReport(Place newPlace); @Scheduled(cron = "0 0 12 ? * *", zone = AppConstant.UKRAINE_TIMEZONE) @Override void sendDailyReport(); @Scheduled(cron = "0 0 12 ? * MON", zone = AppConstant.UKRAINE_TIMEZONE) @Override void sendWeeklyReport(); @Scheduled(cron = "0 0 12 1 * ?", zone = AppConstant.UKRAINE_TIMEZONE) @Override void sendMonthlyReport();  }