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

Introduce from and to attributes on @EnumSource (#4185) #4221

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yhkuo41
Copy link
Contributor

@yhkuo41 yhkuo41 commented Dec 24, 2024

Resolves #4185.

Overview


I hereby agree to the terms of the JUnit Contributor License Agreement.


Definition of Done

@@ -63,6 +63,8 @@
* first parameter of the {@code @ParameterizedTest} method is used.
*
* @see #names
* @see #from
* @see #to

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" })

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));
}

Choose a reason for hiding this comment

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

Suggested change
}
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);

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

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.

Support range filter in @EnumSource
2 participants