Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translate test cases contributed from foreign project in scala #91

Closed
jmrozanec opened this issue May 27, 2016 · 1 comment
Closed

Translate test cases contributed from foreign project in scala #91

jmrozanec opened this issue May 27, 2016 · 1 comment

Comments

@jmrozanec
Copy link
Owner

@francisdb provided the following tests when discussing issue #89
Tests should be merged into out codebase, to cover a broader set of cases.

"Validating a cron expression" should {
"succeed for a valid cron expression 0 0/15 * * * ?" in {
  CronUtil.validateCronExpression("0 0/15 * * * ?", true)
  success
}

"throw an exception when given an invalid cron expression for quartz" in {
  CronUtil.validateCronExpression("0 30 17 4 1 * 2016", false) must throwA[IllegalArgumentException](
    Pattern.quote("Both, a day-of-week AND a day-of-month parameter, are not supported.")
  )
}

"throw an exception for invalid cron expression with unknown char" in {
  CronUtil.validateCronExpression("* * * * $ ?", false) must throwA[IllegalArgumentException](
    // TODO should be better with https://github.com/jmrozanec/cron-utils/issues/89
    Pattern.quote("""java.lang.NumberFormatException: For input string: "$"""")
  )
}

"for an invalid quartz cron expression throw an exception with message containing the actual expression" in {
  skipped("https://github.com/jmrozanec/cron-utils/issues/90")
  CronUtil.validateCronExpression("0/1 * * * * *", false) must throwA[IllegalArgumentException](
    Pattern.quote("""Invalid cron expression: 0/1 * * * * *. Both, a day-of-week AND a day-of-month parameter, are not supported.""")
  )
 }
}

"Calculating the minimum interval for a cron expression" should {
"be 1 for * * * * * ?" in {
  CronUtil.getShortestPeriodSeconds("* * * * * ?", Duration.ZERO) must be equalTo Duration.ofSeconds(1)
}

"be 1 for *   *    *  *       * ? (ignore whitespace)" in {
  CronUtil.getShortestPeriodSeconds("* * * * * ?", Duration.ZERO) must be equalTo Duration.ofSeconds(1)
}

"be 1 for 0/1 * * * * ?" in {
  CronUtil.getShortestPeriodSeconds("0/1 * * * * ?", Duration.ZERO) must be equalTo Duration.ofSeconds(1)
}

"be 1 for */1 * * * * ?" in {
  CronUtil.getShortestPeriodSeconds("*/1 * * * * ?", Duration.ZERO) must be equalTo Duration.ofSeconds(1)
}

"be 60 for 0 * * * * ?" in {
  CronUtil.getShortestPeriodSeconds("0 * * * * ?", Duration.ZERO) must be equalTo Duration.ofMinutes(1)
}

"be 60 for 0 */1 * * * ?" in {
  CronUtil.getShortestPeriodSeconds("0 */1 * * * ?", Duration.ZERO) must be equalTo Duration.ofMinutes(1)
}

"be 300 for 0 */5 * * * ?" in {
  CronUtil.getShortestPeriodSeconds("0 */5 * * * ?", Duration.ZERO) must be equalTo Duration.ofMinutes(5)
}

"be 3600 for 0 0 * * * ?" in {
  CronUtil.getShortestPeriodSeconds("0 0 * * * ?", Duration.ZERO) must be equalTo Duration.ofHours(1)
}

"be 10800 for 0 0 */3 * * ?" in {
  CronUtil.getShortestPeriodSeconds("0 0 */3 * * ?", Duration.ZERO) must be equalTo Duration.ofHours(3)
}

"be 86400 for 0 0 0 * * ?" in {
  CronUtil.getShortestPeriodSeconds("0 0 0 * * ?", Duration.ofDays(1)) must be equalTo Duration.ofDays(1)
}

"throw an exception for invalid cron expression * *" in {
  CronUtil.getShortestPeriodSeconds("* *", Duration.ZERO) must throwA[IllegalArgumentException](
    Pattern.quote("Cron expression contains 2 parts but we expect one of [6, 7]")
  )
}

"throw an exception for invalid cron expression */ * * * * ?" in {
  CronUtil.getShortestPeriodSeconds("*/ * * * * ?", Duration.ZERO) must throwA[IllegalArgumentException](
    Pattern.quote("Missing steps for expression: */")
  )
}

"throw an exception for invalid cron expression with unknown char" in {
  CronUtil.getShortestPeriodSeconds("* * * * $ ?", Duration.ZERO) must throwA[IllegalArgumentException](
    // TODO should be better with https://github.com/jmrozanec/cron-utils/issues/89
    Pattern.quote("""java.lang.NumberFormatException: For input string: "$"""")
  )
}
@jmrozanec
Copy link
Owner Author

@thachhoang thank you for contributing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant