Ejemplo n.º 1
0
 @Test
 public void testStarField() {
   try {
     CronMonthField field = new CronMonthField("*");
   } catch (CronTimeFieldException e) {
     fail("Couldn't create new CronMonthField with \"*\" param");
     e.printStackTrace();
   }
 }
Ejemplo n.º 2
0
 @Test
 public void testInRange() {
   try {
     CronMonthField field = new CronMonthField();
     for (int i = 1; i < 13; i++) {
       assertEquals(i, field.validateValue(String.valueOf(i)));
     }
     assertEquals(1, field.validateValue("01"));
     assertEquals(12, field.validateValue("12"));
   } catch (CronTimeFieldException e) {
     fail("Exception thrown checking valid values");
     e.printStackTrace();
   }
 }
Ejemplo n.º 3
0
 @Test
 public void testValidNonNumeric() {
   try {
     CronMonthField field = new CronMonthField();
     assertEquals(1, field.validateValue("Jan"));
     assertEquals(1, field.validateValue("jan"));
     assertEquals(2, field.validateValue("Feb"));
     assertEquals(3, field.validateValue("Mar"));
     assertEquals(4, field.validateValue("Apr"));
     assertEquals(5, field.validateValue("May"));
     assertEquals(6, field.validateValue("Jun"));
     assertEquals(7, field.validateValue("Jul"));
     assertEquals(8, field.validateValue("Aug"));
     assertEquals(9, field.validateValue("Sep"));
     assertEquals(10, field.validateValue("Oct"));
     assertEquals(11, field.validateValue("Nov"));
     assertEquals(12, field.validateValue("Dec"));
   } catch (CronTimeFieldException e) {
     e.printStackTrace();
     fail();
   }
 }
Ejemplo n.º 4
0
  @Test
  public void testConstructor() {
    try {
      CronMonthField field = new CronMonthField("01");
      assertEquals("1", field.toString());
      field = new CronMonthField("1,6,12");
      assertEquals("1,6,12", field.toString());
      assertTrue("field does not match 1", field.matches(1));
      assertTrue("field does not match 6", field.matches(6));
      assertTrue("field does not match 12", field.matches(12));
      assertFalse("field matches 0", field.matches(0));
      assertFalse("field matches 8", field.matches(8));

      field = new CronMonthField("1-12");
      assertEquals("1-12", field.toString());
      assertTrue("field does not match 3", field.matches(3));
      assertTrue(field.matches(1));
      assertFalse(field.matches(24));

      field = new CronMonthField("1-12/2");
      assertEquals("1-12/2", field.toString());
      assertTrue("field does not match 1", field.matches(1));
      assertTrue("field does not match 3", field.matches(3));
      assertTrue("field does not match 5", field.matches(5));
      assertTrue("field does not match 7", field.matches(7));
      assertTrue("field does not match 9", field.matches(9));
      assertTrue("field does not match 11", field.matches(11));
      assertFalse(field.matches(0));
      assertFalse(field.matches(2));
      assertFalse(field.matches(4));
      assertFalse(field.matches(6));
      assertFalse(field.matches(12));

      field = new CronMonthField("2-4,6-7");
      assertEquals("2-4,6-7", field.toString());
      assertFalse(field.matches(0));
      assertFalse(field.matches(1));
      assertTrue("field does not match 2", field.matches(2));
      assertTrue("field does not match 3", field.matches(3));
      assertTrue("field does not match 4", field.matches(4));
      assertFalse(field.matches(5));
      assertTrue("field does not match 6", field.matches(6));
      assertTrue("field does not match 7", field.matches(7));
      assertFalse(field.matches(8));

      field = new CronMonthField("*/3");
      assertEquals("1-12/3", field.toString());
      assertTrue("field does not match 1", field.matches(1));
      assertFalse(field.matches(2));
      assertFalse(field.matches(3));
      assertTrue("field does not match 4", field.matches(4));
      assertTrue("field does not match 7", field.matches(7));
      assertTrue("field does not match 10", field.matches(10));

      field = new CronMonthField("Jan-May");
      assertEquals("1-5", field.toString());
      assertTrue("field does not match 1", field.matches(1));
      assertTrue("field does not match 2", field.matches(2));
      assertTrue("field does not match 3", field.matches(3));
      assertTrue("field does not match 4", field.matches(4));
      assertTrue("field does not match 5", field.matches(5));
      assertFalse(field.matches(6));
      assertFalse(field.matches(7));

      field = new CronMonthField("Feb-May,Jul,Nov");
      assertEquals("2-5,7,11", field.toString());
      assertFalse(field.matches(1));
      assertTrue("field does not match 2", field.matches(2));
      assertTrue("field does not match 3", field.matches(3));
      assertTrue("field does not match 4", field.matches(4));
      assertTrue("field does not match 5", field.matches(5));
      assertFalse(field.matches(6));
      assertTrue("field does not match 7", field.matches(7));
      assertTrue("field does not match 11", field.matches(11));
    } catch (CronTimeFieldException e) {
      fail("Exception thrown checking valid values");
      e.printStackTrace();
    }
  }