MaintenanceScheduleHelper { public static void validateMaintenanceSchedule(final String cronSchedule, final String duration, final String timezone) { if (allNotEmpty(cronSchedule, duration, timezone)) { validateCronSchedule(cronSchedule); validateDuration(duration); if (!getNextMaintenanceWindow(cronSchedule, duration, timezone).isPresent()) { throw new InvalidMaintenanceScheduleException( "No valid maintenance window available after current time"); } } else if (atLeastOneNotEmpty(cronSchedule, duration, timezone)) { throw new InvalidMaintenanceScheduleException( "All of schedule, duration and timezone should either be null or non empty."); } } private  MaintenanceScheduleHelper(); @SuppressWarnings("squid:S1166") static Optional<ZonedDateTime> getNextMaintenanceWindow(final String cronSchedule, final String duration,
            final String timezone); static Cron getCronFromExpression(final String cronSchedule); static void validateMaintenanceSchedule(final String cronSchedule, final String duration,
            final String timezone); static Duration convertToISODuration(final String timeInterval); static void validateDuration(final String duration); static void validateCronSchedule(final String cronSchedule);  }
@Test @Description("Verifies the maintenance schedule when only one required field is present") public void validateMaintenanceScheduleAtLeastOneNotEmpty() { final String duration = "00:10"; assertThatThrownBy(() -> MaintenanceScheduleHelper.validateMaintenanceSchedule(null, duration, null)) .isInstanceOf(InvalidMaintenanceScheduleException.class) .hasMessage("All of schedule, duration and timezone should either be null or non empty."); }
@Test @Description("Verifies that there is no valid maintenance window available, scheduled before current time") public void validateMaintenanceScheduleBeforeCurrentTime() { ZonedDateTime currentTime = ZonedDateTime.now(); currentTime = currentTime.plusMinutes(-30); final String cronSchedule = String.format("0 %d %d %d %d ? %d", currentTime.getMinute(), currentTime.getHour(), currentTime.getDayOfMonth(), currentTime.getMonthValue(), currentTime.getYear()); final String duration = "00:10"; final String timezone = ZonedDateTime.now().getOffset().getId().replace("Z", "+00:00"); assertThatThrownBy( () -> MaintenanceScheduleHelper.validateMaintenanceSchedule(cronSchedule, duration, timezone)) .isInstanceOf(InvalidMaintenanceScheduleException.class) .hasMessage("No valid maintenance window available after current time"); }