package org.junit.jupiter.engine.descriptor;
import static org.apiguardian.api.API.Status.INTERNAL;
import static org.junit.jupiter.engine.descriptor.JupiterTestDescriptor.toExecutionMode;
import org.apiguardian.api.API;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.engine.config.JupiterConfiguration;
import org.junit.jupiter.engine.execution.JupiterEngineExecutionContext;
import org.junit.jupiter.engine.extension.MutableExtensionRegistry;
import org.junit.platform.engine.EngineExecutionListener;
import org.junit.platform.engine.UniqueId;
import org.junit.platform.engine.support.descriptor.EngineDescriptor;
import org.junit.platform.engine.support.hierarchical.Node;
@API(status = INTERNAL, since = "5.0")
public class JupiterEngineDescriptor extends EngineDescriptor implements Node<JupiterEngineExecutionContext> {
public static final String ENGINE_ID = "junit-jupiter";
private final JupiterConfiguration configuration;
public JupiterEngineDescriptor(UniqueId uniqueId, JupiterConfiguration configuration) {
super(uniqueId, "JUnit Jupiter");
this.configuration = configuration;
}
public JupiterConfiguration getConfiguration() {
return configuration;
}
@Override
public ExecutionMode getExecutionMode() {
return toExecutionMode(configuration.getDefaultExecutionMode());
}
@Override
public JupiterEngineExecutionContext prepare(JupiterEngineExecutionContext context) {
MutableExtensionRegistry extensionRegistry = MutableExtensionRegistry.createRegistryWithDefaultExtensions(
context.getConfiguration());
EngineExecutionListener executionListener = context.getExecutionListener();
ExtensionContext extensionContext = new JupiterEngineExtensionContext(executionListener, this,
context.getConfiguration());
return context.extend()
.withExtensionRegistry(extensionRegistry)
.withExtensionContext(extensionContext)
.build();
}
@Override
public void cleanUp(JupiterEngineExecutionContext context) throws Exception {
context.close();
}
}