CleanerSchedulerValidator implements Validator { @Override public void validate(ValidationResultBuilder validationResultBuilder) { validateSchedule(validationResultBuilder); validateRestrictions(validationResultBuilder); } CleanerSchedulerValidator(String schedule, Long keepNVersions, Long removeOlderThan); @Override void validate(ValidationResultBuilder validationResultBuilder);  }
@Test public void validateTest_keepNVersionsNull_expectFalse() { Validator tested = validatorBuilder.setKeepNVersions(null).build(); tested.validate(builder); assertThat(builder.isValid(), is(false)); assertThat(builder.getErrorMessages(), Matchers.hasSize(1)); }
@Test public void validateTest_keepNVersions0() { Validator tested = validatorBuilder.setKeepNVersions(0L).build(); tested.validate(builder); assertThat(builder.isValid(), is(false)); assertThat(builder.getErrorMessages(), Matchers.hasSize(1)); assertThat(builder.getErrorMessages().get(0).getMessage(), is("Leave N Patterns has to be greater than 0")); }
@Test public void validateTest_keepNVersions1() { Validator tested = validatorBuilder.setKeepNVersions(1L).build(); tested.validate(builder); assertThat(builder.isValid(), is(true)); }
@Test public void validateTest_removeOlderThanMinus1() { Validator tested = validatorBuilder.setRemoveOlderThan(-1L).build(); tested.validate(builder); assertThat(builder.isValid(), is(false)); }
@Test public void validateTest_removeOlderThan() { Validator tested = validatorBuilder.setRemoveOlderThan(0L).build(); tested.validate(builder); assertThat(builder.isValid(), is(true)); tested = validatorBuilder.setRemoveOlderThan(1L).build(); tested.validate(builder); assertThat(builder.isValid(), is(true)); }
@Test public void validateTest_emptyKeepNVersions_expectFalse() { Validator tested = validatorBuilder.setKeepNVersions(null).build(); tested.validate(builder); assertThat(builder.isValid(), is(false)); }
@Test public void validateTest_emptySchedule() { Validator tested = validatorBuilder.setSchedule(null).build(); tested.validate(builder); assertThat(builder.isValid(), is(false)); assertThat(builder.getErrorMessages(), Matchers.hasSize(1)); assertThat(builder.getErrorMessages().get(0).getMessage(), is("CRON expression may not be empty")); }