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

feat: Add cron expression assertion, Related to #3212 #3220

Open
wants to merge 1 commit into
base: 3.x
Choose a base branch
from

Conversation

neilwangweili
Copy link

It contains following apis:

CronExpression cronExpression = new CronExpression("* * * * * *"); 
assertThat(cronExpression).isValid();
assertThat(cronExpression).containsExactlySeconds(...); 
assertThat(cronExpression).containsExactlyMinutes(...); 
assertThat(cronExpression).containsExactlyHours(...); 
assertThat(cronExpression).containsExactlyDayOfMonth(...); 
assertThat(cronExpression).containsExactlyMonth(...); 
assertThat(cronExpression).containsExactlyDayOfWeek(...); 
assertThat(cronExpression).containsExactlyYear(...);

Check List:

Following the contributing guidelines will make it easier for us to review and accept your PR.

It contains following apis:
CronExpression cronExpression = new CronExpression("* * * * * *");
assertThat(cronExpression).isValid();
assertThat(cronExpression).containsExactlySeconds(...);
assertThat(cronExpression).containsExactlyMinutes(...);
assertThat(cronExpression).containsExactlyHours(...);
assertThat(cronExpression).containsExactlyDayOfMonth(...);
assertThat(cronExpression).containsExactlyMonth(...);
assertThat(cronExpression).containsExactlyDayOfWeek(...);
assertThat(cronExpression).containsExactlyYear(...);
@scordio
Copy link
Member

scordio commented Oct 13, 2023

Thanks, @neilwangweili! We'll review it shortly.

Two initial thoughts:

  • I'd avoid additions to the internal package and I'd rather favor package-private classes in the api package, if they are required
  • I'm not sure we should expose CronExpression publicly, I'd rather keep it as an implementation detail so CronExpressionAssert and the abstract parent would be applied to String values instead of CronExpression objects. This should give good interoperability with CronExpression types from third parties, like the one from Spring, where a toString. However, this would trigger the addition of a navigation method to AbstractCharSequenceAssert (maybe asCronExpression), similar to AbstractStringAssert::asBase64Decoded.

WDYT?

* CronExpression contains a cronable string that to set up a scheduled task.
* @author Neil Wang
*/
public class CronExpression {
Copy link
Member

@scordio scordio Oct 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to my comment, having this new type in the internal package and exposing it as part of the public API like in assertThat(CronExpression) will cause trouble in module-path and OSGi based applications.

@neilwangweili
Copy link
Author

Thanks, @neilwangweili! We'll review it shortly.

Two initial thoughts:

  • I'd avoid additions to the internal package and I'd rather favor package-private classes in the api package, if they are required
  • I'm not sure we should expose CronExpression publicly, I'd rather keep it as an implementation detail so CronExpressionAssert and the abstract parent would be applied to String values instead of CronExpression objects. This should give good interoperability with CronExpression types from third parties, like the one from Spring, where a toString. However, this would trigger the addition of a navigation method to AbstractCharSequenceAssert (maybe asCronExpression), similar to AbstractStringAssert::asBase64Decoded.

WDYT?

Okay, I'll look into it and do what you want. I don't have time this week so I'll do it next week.

@scordio
Copy link
Member

scordio commented Oct 13, 2023

No worries, take your time of course, and let's also wait for some thoughts from @joel-costigliola.

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

Successfully merging this pull request may close these issues.

Add cron expression assertion support in assertj-core
2 participants