Skip to content

Commit

Permalink
Rename requireArguments to allowZeroInvocations (#4149)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anmavel authored Nov 23, 2024
1 parent 945e4b9 commit 6527613
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
* <p>Set this attribute to {@code false} if the absence of arguments is
* <p>Set this attribute to {@code true} if the absence of arguments is
* expected in some cases and should not cause a test failure.
*
* <p>Defaults to {@code true}.
* <p>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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ public Stream<TestTemplateInvocationContext> 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
}

@Override
public boolean mayReturnZeroTestTemplateInvocationContexts(ExtensionContext extensionContext) {
ParameterizedTestMethodContext methodContext = getMethodContext(extensionContext);
return !methodContext.annotation.requireArguments();
return methodContext.annotation.allowZeroInvocations();
}

private ParameterizedTestMethodContext getMethodContext(ExtensionContext extensionContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ void method() {

static class TestCaseAllowNoArgumentsMethod {

@ParameterizedTest(requireArguments = false)
@ParameterizedTest(allowZeroInvocations = true)
void method() {
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down

0 comments on commit 6527613

Please sign in to comment.