Skip to content

Commit

Permalink
add small ArgumentCountValidator perf optimisations
Browse files Browse the repository at this point in the history
Issue #3708
  • Loading branch information
JonasJebing committed Nov 14, 2024
1 parent 1151f6b commit 906881c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@

package org.junit.jupiter.params;

import static org.junit.platform.commons.support.AnnotationSupport.findAnnotation;

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.Optional;

import org.junit.jupiter.api.extension.ExtensionConfigurationException;
Expand All @@ -30,10 +27,14 @@ class ArgumentCountValidator implements InvocationInterceptor {
private static final Logger logger = LoggerFactory.getLogger(ArgumentCountValidator.class);

static final String ARGUMENT_COUNT_VALIDATION_KEY = "junit.jupiter.params.argumentCountValidation";
private static final ExtensionContext.Namespace NAMESPACE = ExtensionContext.Namespace.create(
ArgumentCountValidator.class);

private final ParameterizedTestMethodContext methodContext;
private final Arguments arguments;

ArgumentCountValidator(Arguments arguments) {
ArgumentCountValidator(ParameterizedTestMethodContext methodContext, Arguments arguments) {
this.methodContext = methodContext;
this.arguments = arguments;
}

Expand All @@ -45,7 +46,7 @@ public void interceptTestTemplateMethod(InvocationInterceptor.Invocation<Void> i
}

private ExtensionContext.Store getStore(ExtensionContext context) {
return context.getRoot().getStore(ExtensionContext.Namespace.create(getClass()));
return context.getRoot().getStore(NAMESPACE);
}

private void validateArgumentCount(ExtensionContext extensionContext, Arguments arguments) {
Expand All @@ -68,9 +69,7 @@ private void validateArgumentCount(ExtensionContext extensionContext, Arguments
}

private ArgumentCountValidationMode getArgumentCountValidationMode(ExtensionContext extensionContext) {
ParameterizedTest parameterizedTest = findAnnotation(//
extensionContext.getRequiredTestMethod(), ParameterizedTest.class//
).orElseThrow(NoSuchElementException::new);
ParameterizedTest parameterizedTest = methodContext.annotation;
if (parameterizedTest.argumentCountValidation() != ArgumentCountValidationMode.DEFAULT) {
return parameterizedTest.argumentCountValidation();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public String getDisplayName(int invocationIndex) {
public List<Extension> getAdditionalExtensions() {
return Arrays.asList(
new ParameterizedTestParameterResolver(this.methodContext, this.consumedArguments, this.invocationIndex),
new ArgumentCountValidator(this.arguments));
new ArgumentCountValidator(this.methodContext, this.arguments));
}

private static Object[] consumedArguments(ParameterizedTestMethodContext methodContext, Object[] arguments) {
Expand Down

0 comments on commit 906881c

Please sign in to comment.