use of com.cronutils.model.field.definition.FieldDefinition in project cron-utils by jmrozanec.
the class FieldDefinitionTest method testCreateFieldDefinitionComparatorGreater.
@Test
public void testCreateFieldDefinitionComparatorGreater() {
final CronFieldName name1 = CronFieldName.DAY_OF_MONTH;
final CronFieldName name2 = CronFieldName.SECOND;
final FieldDefinition fieldDefinition1 = new FieldDefinition(name1, mockConstraints);
final FieldDefinition fieldDefinition2 = new FieldDefinition(name2, mock(FieldConstraints.class));
assertNotEquals(name1.getOrder(), name2.getOrder());
assertTrue(FieldDefinition.createFieldDefinitionComparator().compare(fieldDefinition1, fieldDefinition2) > 0);
}
use of com.cronutils.model.field.definition.FieldDefinition in project cron-utils by jmrozanec.
the class FieldDefinitionTest method testCreateFieldDefinitionComparatorEqual.
@Test
public void testCreateFieldDefinitionComparatorEqual() {
final CronFieldName name = CronFieldName.DAY_OF_MONTH;
final FieldDefinition fieldDefinition1 = new FieldDefinition(name, mockConstraints);
final FieldDefinition fieldDefinition2 = new FieldDefinition(name, mock(FieldConstraints.class));
assertEquals(name.getOrder(), name.getOrder());
assertEquals(0, FieldDefinition.createFieldDefinitionComparator().compare(fieldDefinition1, fieldDefinition2));
}
use of com.cronutils.model.field.definition.FieldDefinition in project cron-utils by jmrozanec.
the class FieldDefinitionBuilderTest method testAnd.
@Test
public void testAnd() {
final FieldConstraints constraints = mock(FieldConstraints.class);
when(mockConstraintsBuilder.createConstraintsInstance()).thenReturn(constraints);
final ArgumentCaptor<FieldDefinition> argument = ArgumentCaptor.forClass(FieldDefinition.class);
fieldDefinitionBuilder.and();
verify(mockParserBuilder).register(argument.capture());
assertEquals(testFieldName, argument.getValue().getFieldName());
verify(mockConstraintsBuilder).createConstraintsInstance();
}
use of com.cronutils.model.field.definition.FieldDefinition in project cron-utils by jmrozanec.
the class CronBuilder method addField.
@VisibleForTesting
CronBuilder addField(final CronFieldName name, final FieldExpression expression) {
checkState(definition != null, "CronBuilder not initialized.");
final FieldDefinition fieldDefinition = definition.getFieldDefinition(name);
checkState(fieldDefinition != null, "Cron field definition does not exist: %s", name);
final FieldConstraints constraints = fieldDefinition.getConstraints();
expression.accept(new ValidationFieldExpressionVisitor(constraints));
fields.put(name, new CronField(name, expression, constraints));
return this;
}
use of com.cronutils.model.field.definition.FieldDefinition in project cron-utils by jmrozanec.
the class CronDefinitionBuilderTest method testRegister.
@Test
public void testRegister() {
final FieldDefinition testFieldDefinition = new FieldDefinition(CronFieldName.SECOND, new FieldConstraints(Collections.emptyMap(), Collections.emptyMap(), Collections.emptySet(), 0, 1, true));
builder.register(testFieldDefinition);
final Set<FieldDefinition> definitions = builder.instance().getFieldDefinitions();
assertNotNull(definitions);
assertEquals(1, definitions.size());
assertEquals(testFieldDefinition, definitions.iterator().next());
}
Aggregations