diff --git a/documentation/src/docs/asciidoc/release-notes/release-notes-5.12.0-M1.adoc b/documentation/src/docs/asciidoc/release-notes/release-notes-5.12.0-M1.adoc index 92c97ce8dab6..559a9a288649 100644 --- a/documentation/src/docs/asciidoc/release-notes/release-notes-5.12.0-M1.adoc +++ b/documentation/src/docs/asciidoc/release-notes/release-notes-5.12.0-M1.adoc @@ -85,7 +85,7 @@ JUnit repository on GitHub. * Extensions based on `TestTemplateInvocationContextProvider` can now allow returning zero invocation contexts by overriding the new `mayReturnZeroTestTemplateInvocationContexts` method. -* The new `@ParameterizedTest(requireArguments = false)` attribute allows to specify that +* The new `@ParameterizedTest(allowZeroInvocations = true)` attribute allows to specify that the absence of arguments is expected in some cases and should not cause a test failure. * Allow determining "shared resources" at runtime via the new `@ResourceLock#providers` attribute that accepts implementations of `ResourceLocksProvider`. diff --git a/junit-jupiter-params/src/main/java/org/junit/jupiter/params/ParameterizedTest.java b/junit-jupiter-params/src/main/java/org/junit/jupiter/params/ParameterizedTest.java index 03741d19f1fd..a14309deb7eb 100644 --- a/junit-jupiter-params/src/main/java/org/junit/jupiter/params/ParameterizedTest.java +++ b/junit-jupiter-params/src/main/java/org/junit/jupiter/params/ParameterizedTest.java @@ -293,18 +293,18 @@ boolean autoCloseArguments() default true; /** - * Configure whether at least one set of arguments is required for this + * Configure whether zero invocations are allowed for this * parameterized test. * - *

Set this attribute to {@code false} if the absence of arguments is + *

Set this attribute to {@code true} if the absence of arguments is * expected in some cases and should not cause a test failure. * - *

Defaults to {@code true}. + *

Defaults to {@code false}. * * @since 5.12 */ @API(status = EXPERIMENTAL, since = "5.12") - boolean requireArguments() default true; + boolean allowZeroInvocations() default false; /** * Configure how the number of arguments provided by an {@link ArgumentsSource} are validated. diff --git a/junit-jupiter-params/src/main/java/org/junit/jupiter/params/ParameterizedTestExtension.java b/junit-jupiter-params/src/main/java/org/junit/jupiter/params/ParameterizedTestExtension.java index 74ff653e15cc..8aed7644f2d8 100644 --- a/junit-jupiter-params/src/main/java/org/junit/jupiter/params/ParameterizedTestExtension.java +++ b/junit-jupiter-params/src/main/java/org/junit/jupiter/params/ParameterizedTestExtension.java @@ -86,7 +86,7 @@ public Stream provideTestTemplateInvocationContex return createInvocationContext(formatter, methodContext, arguments, invocationCount.intValue()); }) .onClose(() -> - Preconditions.condition(invocationCount.get() > 0 || !methodContext.annotation.requireArguments(), + Preconditions.condition(invocationCount.get() > 0 || methodContext.annotation.allowZeroInvocations(), "Configuration error: You must configure at least one set of arguments for this @ParameterizedTest")); // @formatter:on } @@ -94,7 +94,7 @@ public Stream provideTestTemplateInvocationContex @Override public boolean mayReturnZeroTestTemplateInvocationContexts(ExtensionContext extensionContext) { ParameterizedTestMethodContext methodContext = getMethodContext(extensionContext); - return !methodContext.annotation.requireArguments(); + return methodContext.annotation.allowZeroInvocations(); } private ParameterizedTestMethodContext getMethodContext(ExtensionContext extensionContext) { diff --git a/jupiter-tests/src/test/java/org/junit/jupiter/params/ParameterizedTestExtensionTests.java b/jupiter-tests/src/test/java/org/junit/jupiter/params/ParameterizedTestExtensionTests.java index f8d6dee01831..fcdd5a0a7583 100644 --- a/jupiter-tests/src/test/java/org/junit/jupiter/params/ParameterizedTestExtensionTests.java +++ b/jupiter-tests/src/test/java/org/junit/jupiter/params/ParameterizedTestExtensionTests.java @@ -325,7 +325,7 @@ void method() { static class TestCaseAllowNoArgumentsMethod { - @ParameterizedTest(requireArguments = false) + @ParameterizedTest(allowZeroInvocations = true) void method() { } } diff --git a/jupiter-tests/src/test/java/org/junit/jupiter/params/ParameterizedTestIntegrationTests.java b/jupiter-tests/src/test/java/org/junit/jupiter/params/ParameterizedTestIntegrationTests.java index 50c131c449b3..13739ea4e018 100644 --- a/jupiter-tests/src/test/java/org/junit/jupiter/params/ParameterizedTestIntegrationTests.java +++ b/jupiter-tests/src/test/java/org/junit/jupiter/params/ParameterizedTestIntegrationTests.java @@ -2422,7 +2422,7 @@ void testThatRequiresArguments(String argument) { fail("This test should not be executed, because no arguments are provided."); } - @ParameterizedTest(requireArguments = false) + @ParameterizedTest(allowZeroInvocations = true) @MethodSource("zeroArgumentsProvider") void testThatDoesNotRequireArguments(String argument) { fail("This test should not be executed, because no arguments are provided.");