-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Introduce from and to attributes on @EnumSource (#4185) #4221
base: main
Are you sure you want to change the base?
Conversation
@@ -63,6 +63,8 @@ | |||
* first parameter of the {@code @ParameterizedTest} method is used. | |||
* | |||
* @see #names | |||
* @see #from | |||
* @see #to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe also add it to the mode()
method javadoc
@@ -164,6 +172,15 @@ void testWithEnumSourceRegex(ChronoUnit unit) { | |||
} | |||
// end::EnumSource_regex_example[] | |||
|
|||
// tag::EnumSource_range_exclude_example[] | |||
@ParameterizedTest | |||
@EnumSource(mode = EXCLUDE, from = "HOURS", to = "DAYS", names = { "HALF_DAYS" }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test exemple will depend on the JDK. So, if the order is change, it can impact your test. is it not better to use a home made enum for the test exemple ?
@EnumSource(from = "HOURS", to = "DAYS") | ||
void testWithEnumSourceRange(ChronoUnit unit) { | ||
assertTrue(EnumSet.of(ChronoUnit.HOURS, ChronoUnit.HALF_DAYS, ChronoUnit.DAYS).contains(unit)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | |
assertFalse(EnumSet.of(ChronoUnit.SECONDS).contains(unit)); | |
} |
} | ||
E from = enumSource.from().isEmpty() ? constants[0] : Enum.valueOf(enumClass, enumSource.from()); | ||
E to = enumSource.to().isEmpty() ? constants[constants.length - 1] : Enum.valueOf(enumClass, enumSource.to()); | ||
return EnumSet.range(from, to); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happen if from > to
or if from == to
?
It maybe need to be specify somewhere in the doc, and have a test on this cases
Resolves #4185.
Overview
I hereby agree to the terms of the JUnit Contributor License Agreement.
Definition of Done
@API
annotations