diff --git a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/extension/TestTemplateInvocationContextProvider.java b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/extension/TestTemplateInvocationContextProvider.java index 04c921719db4..5fae0f7463a9 100644 --- a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/extension/TestTemplateInvocationContextProvider.java +++ b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/extension/TestTemplateInvocationContextProvider.java @@ -88,20 +88,20 @@ public interface TestTemplateInvocationContextProvider extends Extension { Stream provideTestTemplateInvocationContexts(ExtensionContext context); /** - * Signals that in the given {@linkplain ExtensionContext extension context} the provider may return zero - * {@linkplain TestTemplateInvocationContext invocation contexts} + * Signals that in the supplied {@linkplain ExtensionContext context} the provider may return zero + * {@linkplain TestTemplateInvocationContext invocation contexts}. * *

If provider returns empty stream from {@link #provideTestTemplateInvocationContexts(ExtensionContext)} * this will be considered an execution error. Override this method to ignore the absence of invocation contexts. * - * @param extensionContext the extension context for the test template method about + * @param context the extension context for the test template method about * to be invoked; never {@code null} * @return {@code true} to allow zero contexts, {@code false} (default) to fail execution in case of zero contexts. * - * @since 5.11 + * @since 5.12 */ - @API(status = EXPERIMENTAL, since = "5.11") - default boolean mayReturnEmptyInvocationContext(ExtensionContext extensionContext) { + @API(status = EXPERIMENTAL, since = "5.12") + default boolean mayReturnZeroInvocationContexts(ExtensionContext context) { return false; } diff --git a/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/TestTemplateTestDescriptor.java b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/TestTemplateTestDescriptor.java index e10d6eeb45ef..13bdca117103 100644 --- a/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/TestTemplateTestDescriptor.java +++ b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/TestTemplateTestDescriptor.java @@ -110,7 +110,7 @@ public JupiterEngineExecutionContext execute(JupiterEngineExecutionContext conte .forEach(invocationTestDescriptor -> execute(dynamicTestExecutor, invocationTestDescriptor)); // @formatter:on boolean allProvidersMayBeEmpty = providers.stream().allMatch( - p -> p.mayReturnEmptyInvocationContext(extensionContext)); + p -> p.mayReturnZeroInvocationContexts(extensionContext)); if (!allProvidersMayBeEmpty) { validateWasAtLeastInvokedOnce(invocationIndex.get(), extensionContext, providers); } @@ -150,11 +150,11 @@ private void validateWasAtLeastInvokedOnce(int invocationIndex, ExtensionContext List providers) { boolean allMayReturnEmptyContext = providers.stream().allMatch( - p -> p.mayReturnEmptyInvocationContext(extensionContext)); + p -> p.mayReturnZeroInvocationContexts(extensionContext)); Preconditions.condition(invocationIndex > 0 || allMayReturnEmptyContext, () -> "None of the supporting " + TestTemplateInvocationContextProvider.class.getSimpleName() + "s " - + providers.stream().filter(p -> !p.mayReturnEmptyInvocationContext(extensionContext)).map( + + providers.stream().filter(p -> !p.mayReturnZeroInvocationContexts(extensionContext)).map( provider -> provider.getClass().getSimpleName()).collect(joining(", ", "[", "]")) + " provided a non-empty stream"); } diff --git a/junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/TestTemplateInvocationTests.java b/junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/TestTemplateInvocationTests.java index 3a01f371f82f..182ffdade131 100644 --- a/junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/TestTemplateInvocationTests.java +++ b/junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/TestTemplateInvocationTests.java @@ -825,7 +825,7 @@ public Stream provideTestTemplateInvocationContex } @Override - public boolean mayReturnEmptyInvocationContext(ExtensionContext extensionContext) { + public boolean mayReturnZeroInvocationContexts(ExtensionContext extensionContext) { return true; } } 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 3dbc34fd5fb6..231f2a1dc183 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 @@ -100,11 +100,11 @@ public Stream provideTestTemplateInvocationContex } @Override - public boolean mayReturnEmptyInvocationContext(ExtensionContext extensionContext) { + public boolean mayReturnZeroInvocationContexts(ExtensionContext extensionContext) { Method templateMethod = extensionContext.getRequiredTestMethod(); - return findAnnotation(templateMethod, ParameterizedTest.class).map( - parameterizedTest -> !parameterizedTest.requireArguments()).orElse( - TestTemplateInvocationContextProvider.super.mayReturnEmptyInvocationContext(extensionContext)); + return findAnnotation(templateMethod, ParameterizedTest.class) // + .map(parameterizedTest -> !parameterizedTest.requireArguments()) // + .orElse(false); } @SuppressWarnings("ConstantConditions")