Skip to content

Commit

Permalink
Cleanup after pull-request review #3890
Browse files Browse the repository at this point in the history
Updated `since` tag values, improved naming.
  • Loading branch information
nskvortsov committed Oct 2, 2024
1 parent 17bb46b commit 140a55d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,20 @@ public interface TestTemplateInvocationContextProvider extends Extension {
Stream<TestTemplateInvocationContext> 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}.
*
* <p>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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -150,11 +150,11 @@ private void validateWasAtLeastInvokedOnce(int invocationIndex, ExtensionContext
List<TestTemplateInvocationContextProvider> 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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContex
}

@Override
public boolean mayReturnEmptyInvocationContext(ExtensionContext extensionContext) {
public boolean mayReturnZeroInvocationContexts(ExtensionContext extensionContext) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ public Stream<TestTemplateInvocationContext> 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")
Expand Down

0 comments on commit 140a55d

Please sign in to comment.