Repository: jmrozanec/cron-utils
Pull request #347 (2018-10-03 10:02:00)

Issue 281
I've unify logic in building quartz for dayOfMonth and month with dayOfWeek.


Patch:
diff --git a/src/main/java/com/cronutils/model/definition/CronDefinitionBuilder.java b/src/main/java/com/cronutils/model/definition/CronDefinitionBuilder.java
index b8570de..1b05014 100755
--- a/src/main/java/com/cronutils/model/definition/CronDefinitionBuilder.java
+++ b/src/main/java/com/cronutils/model/definition/CronDefinitionBuilder.java
@@ -273,8 +273,8 @@ public class CronDefinitionBuilder {
                 .withSeconds().and()
                 .withMinutes().and()
                 .withHours().and()
-                .withDayOfMonth().supportsL().supportsW().supportsLW().supportsQuestionMark().and()
-                .withMonth().and()
+                .withDayOfMonth().withValidRange(1, 32).supportsL().supportsW().supportsLW().supportsQuestionMark().and()
+                .withMonth().withValidRange(1, 13).and()
                 .withDayOfWeek().withValidRange(1, 7).withMondayDoWValue(2).supportsHash().supportsL().supportsQuestionMark().and()
                 .withYear().withValidRange(1970, 2099).optional().and()
                 .withCronValidation(CronConstraintsFactory.ensureEitherDayOfWeekOrDayOfMonth())


Test patch:
diff --git a/src/test/java/com/cronutils/utils/descriptor/Issue281Test.java b/src/test/java/com/cronutils/utils/descriptor/Issue281Test.java
index aaca5db..283c66f 100644
--- a/src/test/java/com/cronutils/utils/descriptor/Issue281Test.java
+++ b/src/test/java/com/cronutils/utils/descriptor/Issue281Test.java
@@ -13,28 +13,49 @@
 
 package com.cronutils.utils.descriptor;
 
-import org.junit.Ignore;
-import org.junit.Test;
-
 import com.cronutils.model.Cron;
 import com.cronutils.model.CronType;
 import com.cronutils.model.definition.CronDefinition;
 import com.cronutils.model.definition.CronDefinitionBuilder;
 import com.cronutils.parser.CronParser;
+import org.junit.Test;
 
 import static org.hamcrest.MatcherAssert.assertThat;
 
-//FIXME
-@Ignore ("Ignore this until someone is working on a fix")
 public class Issue281Test {
 
-    private static final String ISSUE_EXPRESSION = "0 0 0 24 1/12 ?";
+    @Test
+    public void shouldAcceptLastMonth() {
+        final Cron cron = buildCron("0 0 0 24 1/12 ?");
+        assertThat("cron is not null", cron != null);
+    }
+
+    @Test
+    public void shouldAcceptFirstMonth() {
+        final Cron cron = buildCron("0 0 0 24/1 1/12 ?");
+        assertThat("cron is not null", cron != null);
+    }
+
+    @Test
+    public void shouldAcceptLastDayOfMonth() {
+        final Cron cron = buildCron("0 0 0 1/31 7 ?");
+        assertThat("cron is not null", cron != null);
+    }
 
     @Test
-    public void testCronTypeQuartz() {
+    public void shouldAcceptFirstDayOfMonth() {
+        final Cron cron = buildCron("0 0 0 24/1 1/12 ?");
+        assertThat("cron is not null", cron != null);
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void shouldThrowExceptionWhenMonthExceeded() {
+        final Cron cron = buildCron("0 0 0 24 1/13 ?");
+    }
+
+    private Cron buildCron(String expression) {
         final CronDefinition cronDefinition = CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ);
         final CronParser parser = new CronParser(cronDefinition);
-        final Cron cron = parser.parse(ISSUE_EXPRESSION);
-        assertThat("cron is not null", cron != null);
+        return parser.parse(expression);
     }
 }