Skip to content

Commit

Permalink
Add failing test for issue #539
Browse files Browse the repository at this point in the history
  • Loading branch information
kristofarkas committed Oct 4, 2022
1 parent d87ab28 commit 31129ff
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/test/java/com/cronutils/Issue539Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.cronutils;

import com.cronutils.model.Cron;
import com.cronutils.model.definition.CronDefinitionBuilder;
import com.cronutils.model.time.ExecutionTime;
import com.cronutils.parser.CronParser;
import org.junit.jupiter.api.Test;

import java.time.ZonedDateTime;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class Issue539Test {

private final CronParser parser = new CronParser(CronDefinitionBuilder.defineCron()
.withMinutes().and()
.withHours().and()
.withDayOfMonth().supportsL().and()
.withMonth().and()
.withDayOfWeek().and()
.instance());

@Test
public void testDOMWithListIncludingLastOfMonth() {
Cron cron = parser.parse("0 0 L,15 * *").validate();

ZonedDateTime thirdOfMonth = ZonedDateTime.parse("2022-04-03T00:00:00+00:00");
ZonedDateTime fifteenthOfMonth = ZonedDateTime.parse("2022-04-15T00:00:00+00:00");
ZonedDateTime twentiethOfMonth = ZonedDateTime.parse("2022-04-20T00:00:00+00:00");
ZonedDateTime thirtiethOfMonth = ZonedDateTime.parse("2022-04-30T00:00:00+00:00");


assertEquals(ExecutionTime.forCron(cron).nextExecution(thirdOfMonth).get(), fifteenthOfMonth);

// Fails
assertEquals(ExecutionTime.forCron(cron).nextExecution(twentiethOfMonth).get(), thirtiethOfMonth);
}

@Test
public void testDOMWithLastOfMonth() {
Cron cron = parser.parse("0 0 L * *").validate();

ZonedDateTime thirdOfMonth = ZonedDateTime.parse("2022-04-03T00:00:00+00:00");
ZonedDateTime twentiethOfMonth = ZonedDateTime.parse("2022-04-20T00:00:00+00:00");
ZonedDateTime thirtiethOfMonth = ZonedDateTime.parse("2022-04-30T00:00:00+00:00");


assertEquals(ExecutionTime.forCron(cron).nextExecution(thirdOfMonth).get(), thirtiethOfMonth);
assertEquals(ExecutionTime.forCron(cron).nextExecution(twentiethOfMonth).get(), thirtiethOfMonth);
}

}

0 comments on commit 31129ff

Please sign in to comment.