package org.junit.jupiter.engine.descriptor;
import static java.util.Collections.emptySet;
import static org.apiguardian.api.API.Status.INTERNAL;
import java.lang.reflect.Method;
import java.util.Set;
import org.apiguardian.api.API;
import org.junit.jupiter.api.extension.TestTemplateInvocationContext;
import org.junit.jupiter.engine.config.JupiterConfiguration;
import org.junit.jupiter.engine.execution.JupiterEngineExecutionContext;
import org.junit.jupiter.engine.extension.ExtensionRegistry;
import org.junit.platform.engine.TestDescriptor;
import org.junit.platform.engine.UniqueId;
import org.junit.platform.engine.support.hierarchical.ExclusiveResource;
@API(status = INTERNAL, since = "5.0")
public class TestTemplateInvocationTestDescriptor extends TestMethodTestDescriptor {
public static final String SEGMENT_TYPE = "test-template-invocation";
private TestTemplateInvocationContext invocationContext;
private final int index;
TestTemplateInvocationTestDescriptor(UniqueId uniqueId, Class<?> testClass, Method templateMethod,
TestTemplateInvocationContext invocationContext, int index, JupiterConfiguration configuration) {
super(uniqueId, invocationContext.getDisplayName(index), testClass, templateMethod, configuration);
this.invocationContext = invocationContext;
this.index = index;
}
@Override
public Set<ExclusiveResource> getExclusiveResources() {
return emptySet();
}
@Override
public String getLegacyReportingName() {
return super.getLegacyReportingName() + "[" + index + "]";
}
@Override
protected ExtensionRegistry populateNewExtensionRegistry(JupiterEngineExecutionContext context) {
ExtensionRegistry registry = super.populateNewExtensionRegistry(context);
invocationContext.getAdditionalExtensions().forEach(
extension -> registry.registerExtension(extension, invocationContext));
return registry;
}
@Override
public void after(JupiterEngineExecutionContext context) {
invocationContext = null;
}
}