-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Use PreconditionAssertions
wherever feasible
#5019
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
Conversation
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.
Thanks for the PR!
I requested a few categories of changes, and I'll try to find time to look into the 7 files you mentioned.
...ter-tests/src/test/java/org/junit/jupiter/params/provider/CsvFileArgumentsProviderTests.java
Outdated
Show resolved
Hide resolved
jupiter-tests/src/test/java/org/junit/jupiter/api/AssertAllAssertionsTests.java
Outdated
Show resolved
Hide resolved
jupiter-tests/src/test/java/org/junit/jupiter/api/AssertLinesMatchAssertionsTests.java
Outdated
Show resolved
Hide resolved
I think it's fine to leave those 7 files as-is, especially the ones that make use of the |
PreconditionAssertions
wherever feasible
I’ll commit the changes again as soon as I can after applying all the suggestions you mentioned above :) I have one additional question. @SuppressWarnings("DataFlowIssue")
@Test
void includeClassNamePatternsChecksPreconditions() {
assertPreconditionViolationFor(() -> ClassNameFilter.includeClassNamePatterns((String[]) null)).withMessage(
"patterns array must not be null or empty");
assertPreconditionViolationFor(() -> ClassNameFilter.includeClassNamePatterns(new String[0])).withMessage(
"patterns array must not be null or empty");
assertPreconditionViolationFor(
() -> ClassNameFilter.includeClassNamePatterns(new String[] { null })).withMessage(
"patterns array must not contain null elements");
} Also, in the @Test
void throwsExceptionIfResourcesAndFilesAreEmpty() {
var annotation = csvFileSource()//
.resources()//
.files()//
.build();
assertPreconditionViolationFor(
() -> provideArguments(new CsvFileArgumentsProvider(), annotation).toArray()).withMessageContaining(
"Resources or files must not be empty");
} Currently, the public static void assertPreconditionViolationNotNullFor(String name, ThrowingCallable throwingCallable) {
assertPreconditionViolationFor(throwingCallable).withMessage("%s must not be null", name);
}
public static void assertPreconditionViolationNotNullOrBlankFor(String name, ThrowingCallable throwingCallable) {
assertPreconditionViolationFor(throwingCallable).withMessage("%s must not be null or blank", name);
} Would it be acceptable to add the following method and use it for these cases? public static void assertPreconditionViolationNotNullOrEmptyFor(String name, ThrowingCallable throwingCallable) {
assertPreconditionViolationFor(throwingCallable).withMessage("%s must not be null or empty", name);
}
public static void assertPreconditionViolationNotEmptyFor(String name, ThrowingCallable throwingCallable) {
assertPreconditionViolationFor(throwingCallable).withMessage("%s must not be empty", name);
} Also, I found that there are some tests using the message Or would it be acceptable to create a new helper method for this as well? |
👍
Yes, definitely. The whole point of this exercise is to ensure consistent and simplified use of assertions for precondition violations.
If you find that there is duplication, feel free to introduce new global assertion methods and use them. |
I just made two commits.
Is this acceptable? My intention was simply to bring the branch up to date before adding my work. If there’s any problem with this approach, please let me know—and if so, I’d appreciate guidance on how to resolve it. |
It wasn't a problem. Since those exact same commits were already on
I suppose there are two ways to approach that. If you see that changes to Another option is to rebase on top of main. That will avoid inclusion of the new commits on top of your work, but it will require you to "force push" your changes to your PR's branch, which can sometimes cause issues with comments left on the previous state of your PR. So, in the end, it depends. 😉
No reason to apologize. Git is a great tool, but it is challenging to master. TBH, I am not a Git expert either. |
Thank you so much for your kind and detailed explanation. I’m truly happy to contribute to I’ll continue contributing whenever I can!👍 |
Issue: #4943
Overview
PreconditionAssertions
, replacing remaining uses ofPreconditionViolationException.class
.Summary
PreconditionViolationException.class
withPreconditionAssertions
.PreconditionViolationException.class
.Due to their structural constraints, refactoring them to use
PreconditionAssertions
is not straightforward,so they have been intentionally left unchanged.
Please review the 7 files below to confirm whether keeping them as-is is acceptable.
Files Not Refactored (7)
jupiter-tests/src/test/java/org/junit/jupiter/engine/discovery/DiscoverySelectorResolverTests.java
jupiter-tests/src/test/java/org/junit/jupiter/engine/extension/CloseablePathTests.java
jupiter-tests/src/test/java/org/junit/jupiter/engine/extension/ExtensionRegistrationViaParametersAndFieldsTests.java
jupiter-tests/src/test/java/org/junit/jupiter/engine/extension/ProgrammaticExtensionRegistrationTests.java
jupiter-tests/src/test/java/org/junit/jupiter/engine/extension/TempDirectoryTests.java
jupiter-tests/src/test/java/org/junit/jupiter/engine/extension/TimeoutExtensionTests.java
jupiter-tests/src/test/java/org/junit/jupiter/params/ParameterizedTestIntegrationTests.java
I hereby agree to the terms of the JUnit Contributor License Agreement.
Definition of Done
@API
annotations