|  | 
|  | 1 | +package com.cronutils; | 
|  | 2 | + | 
|  | 3 | +import com.cronutils.descriptor.CronDescriptor; | 
|  | 4 | +import com.cronutils.mapper.CronMapper; | 
|  | 5 | +import com.cronutils.model.Cron; | 
|  | 6 | +import com.cronutils.model.definition.CronDefinition; | 
|  | 7 | +import com.cronutils.model.definition.CronDefinitionBuilder; | 
|  | 8 | +import com.cronutils.model.time.ExecutionTime; | 
|  | 9 | +import com.cronutils.parser.CronParser; | 
|  | 10 | +import org.junit.jupiter.api.Assertions; | 
|  | 11 | +import org.junit.jupiter.api.Test; | 
|  | 12 | + | 
|  | 13 | +import java.time.ZonedDateTime; | 
|  | 14 | +import java.util.Locale; | 
|  | 15 | +import java.util.Optional; | 
|  | 16 | + | 
|  | 17 | +class Issue528Test { | 
|  | 18 | + | 
|  | 19 | +    static final CronDefinition REBOOT_CRON_DEFINITION = CronDefinitionBuilder.defineCron() | 
|  | 20 | +            .withSupportedNicknameReboot() | 
|  | 21 | +            .instance(); | 
|  | 22 | + | 
|  | 23 | +    @Test | 
|  | 24 | +    void testRebootExecutionTime() { | 
|  | 25 | +        Cron cron = new CronParser(REBOOT_CRON_DEFINITION).parse("@reboot"); | 
|  | 26 | +        ExecutionTime executionTime = ExecutionTime.forCron(cron); | 
|  | 27 | +        Assertions.assertEquals(Optional.empty(), executionTime.nextExecution(ZonedDateTime.now())); | 
|  | 28 | +        Assertions.assertEquals(Optional.empty(), executionTime.lastExecution(ZonedDateTime.now())); | 
|  | 29 | +    } | 
|  | 30 | + | 
|  | 31 | +    @Test | 
|  | 32 | +    void testCronDescriptor() { | 
|  | 33 | +        Cron cron = new CronParser(REBOOT_CRON_DEFINITION).parse("@reboot"); | 
|  | 34 | +        String description = CronDescriptor.instance(Locale.UK).describe(cron); | 
|  | 35 | +        Assertions.assertEquals("on reboot", description); | 
|  | 36 | +    } | 
|  | 37 | + | 
|  | 38 | + | 
|  | 39 | +    @Test | 
|  | 40 | +    void testCronMapper() { | 
|  | 41 | +        Cron cron = new CronParser(REBOOT_CRON_DEFINITION).parse("@reboot"); | 
|  | 42 | +        CronDefinition unix = CronDefinitionBuilder.defineCron() | 
|  | 43 | +                .withMinutes().withValidRange(0, 59).withStrictRange().and() | 
|  | 44 | +                .withHours().withValidRange(0, 23).withStrictRange().and() | 
|  | 45 | +                .withDayOfMonth().withValidRange(1, 31).withStrictRange().and() | 
|  | 46 | +                .withMonth().withValidRange(1, 12).withStrictRange().and() | 
|  | 47 | +                .withDayOfWeek().withValidRange(0, 7).withMondayDoWValue(1).withIntMapping(7, 0).withStrictRange().and() | 
|  | 48 | +                .withSupportedNicknameReboot() | 
|  | 49 | +                .instance(); | 
|  | 50 | +        Cron mapped = CronMapper.sameCron(unix).map(cron); | 
|  | 51 | +        Assertions.assertEquals(cron.asString(), mapped.asString()); | 
|  | 52 | +    } | 
|  | 53 | +} | 
0 commit comments