@Test
 public void testCreateFieldDefinitionComparatorEqual() throws Exception {
   CronFieldName name = CronFieldName.DAY_OF_MONTH;
   FieldDefinition fieldDefinition1 = new FieldDefinition(name, mockConstraints);
   FieldDefinition fieldDefinition2 = new FieldDefinition(name, mock(FieldConstraints.class));
   assertEquals(name.getOrder(), name.getOrder());
   assertEquals(
       0,
       FieldDefinition.createFieldDefinitionComparator()
           .compare(fieldDefinition1, fieldDefinition2));
 }
 @Test
 public void testCreateFieldDefinitionComparatorLesser() throws Exception {
   CronFieldName name1 = CronFieldName.DAY_OF_MONTH;
   CronFieldName name2 = CronFieldName.SECOND;
   FieldDefinition fieldDefinition1 = new FieldDefinition(name1, mockConstraints);
   FieldDefinition fieldDefinition2 = new FieldDefinition(name2, mock(FieldConstraints.class));
   assertNotEquals(name1.getOrder(), name2.getOrder());
   assertTrue(
       FieldDefinition.createFieldDefinitionComparator()
               .compare(fieldDefinition2, fieldDefinition1)
           < 0);
 }
Exemple #3
0
 /**
  * Creates execution time for given Cron
  *
  * @param cron - Cron instance
  * @return ExecutionTime instance
  */
 public static ExecutionTime forCron(Cron cron) {
   Map<CronFieldName, CronField> fields = cron.retrieveFieldsAsMap();
   ExecutionTimeBuilder executionTimeBuilder = new ExecutionTimeBuilder(cron.getCronDefinition());
   for (CronFieldName name : CronFieldName.values()) {
     if (fields.get(name) != null) {
       switch (name) {
         case SECOND:
           executionTimeBuilder.forSecondsMatching(fields.get(name));
           break;
         case MINUTE:
           executionTimeBuilder.forMinutesMatching(fields.get(name));
           break;
         case HOUR:
           executionTimeBuilder.forHoursMatching(fields.get(name));
           break;
         case DAY_OF_WEEK:
           executionTimeBuilder.forDaysOfWeekMatching(fields.get(name));
           break;
         case DAY_OF_MONTH:
           executionTimeBuilder.forDaysOfMonthMatching(fields.get(name));
           break;
         case MONTH:
           executionTimeBuilder.forMonthsMatching(fields.get(name));
           break;
         case YEAR:
           executionTimeBuilder.forYearsMatching(fields.get(name));
           break;
       }
     }
   }
   return executionTimeBuilder.build();
 }