Search in sources :

Example 1 with JupiterEngineExtensionContext

use of org.junit.jupiter.engine.descriptor.JupiterEngineExtensionContext in project junit5 by junit-team.

the class ExtensionContextTests method configurationParameter.

@TestFactory
Stream<DynamicTest> configurationParameter() throws Exception {
    ConfigurationParameters echo = new EchoParameters();
    String key = "123";
    Optional<String> expected = Optional.of(key);
    UniqueId engineUniqueId = UniqueId.parse("[engine:junit-jupiter]");
    JupiterEngineDescriptor engineDescriptor = new JupiterEngineDescriptor(engineUniqueId);
    UniqueId classUniqueId = UniqueId.parse("[engine:junit-jupiter]/[class:MyClass]");
    ClassTestDescriptor classTestDescriptor = new ClassTestDescriptor(classUniqueId, getClass());
    Method method = getClass().getDeclaredMethod("configurationParameter");
    UniqueId methodUniqueId = UniqueId.parse("[engine:junit-jupiter]/[class:MyClass]/[method:myMethod]");
    TestMethodTestDescriptor methodTestDescriptor = new TestMethodTestDescriptor(methodUniqueId, getClass(), method);
    return // 
    Stream.of(// 
    (ExtensionContext) new JupiterEngineExtensionContext(null, engineDescriptor, echo), // 
    new ClassExtensionContext(null, null, classTestDescriptor, echo, null), // 
    new MethodExtensionContext(null, null, methodTestDescriptor, echo, null, null)).map(context -> dynamicTest(context.getClass().getSimpleName(), () -> assertEquals(expected, context.getConfigurationParameter(key))));
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) Method(java.lang.reflect.Method) ConfigurationParameters(org.junit.platform.engine.ConfigurationParameters) NestedClassTestDescriptor(org.junit.jupiter.engine.descriptor.NestedClassTestDescriptor) ClassTestDescriptor(org.junit.jupiter.engine.descriptor.ClassTestDescriptor) JupiterEngineDescriptor(org.junit.jupiter.engine.descriptor.JupiterEngineDescriptor) MethodExtensionContext(org.junit.jupiter.engine.descriptor.MethodExtensionContext) ClassExtensionContext(org.junit.jupiter.engine.descriptor.ClassExtensionContext) MethodExtensionContext(org.junit.jupiter.engine.descriptor.MethodExtensionContext) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) JupiterEngineExtensionContext(org.junit.jupiter.engine.descriptor.JupiterEngineExtensionContext) ClassExtensionContext(org.junit.jupiter.engine.descriptor.ClassExtensionContext) JupiterEngineExtensionContext(org.junit.jupiter.engine.descriptor.JupiterEngineExtensionContext) TestMethodTestDescriptor(org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor) TestFactory(org.junit.jupiter.api.TestFactory)

Example 2 with JupiterEngineExtensionContext

use of org.junit.jupiter.engine.descriptor.JupiterEngineExtensionContext in project junit5 by junit-team.

the class ExtensionContextTests method fromMethodTestDescriptor.

@Test
@SuppressWarnings("resource")
void fromMethodTestDescriptor() {
    TestMethodTestDescriptor methodTestDescriptor = methodDescriptor();
    ClassTestDescriptor classTestDescriptor = outerClassDescriptor(methodTestDescriptor);
    JupiterEngineDescriptor engineDescriptor = new JupiterEngineDescriptor(UniqueId.forEngine("junit-jupiter"));
    engineDescriptor.addChild(classTestDescriptor);
    Object testInstance = new OuterClass();
    Method testMethod = methodTestDescriptor.getTestMethod();
    JupiterEngineExtensionContext engineExtensionContext = new JupiterEngineExtensionContext(null, engineDescriptor, configParams);
    ClassExtensionContext classExtensionContext = new ClassExtensionContext(engineExtensionContext, null, classTestDescriptor, configParams, null);
    MethodExtensionContext methodExtensionContext = new MethodExtensionContext(classExtensionContext, null, methodTestDescriptor, configParams, testInstance, new ThrowableCollector());
    // @formatter:off
    assertAll("methodContext", () -> assertThat(methodExtensionContext.getElement()).contains(testMethod), () -> assertThat(methodExtensionContext.getTestClass()).contains(OuterClass.class), () -> assertThat(methodExtensionContext.getTestInstance()).contains(testInstance), () -> assertThat(methodExtensionContext.getTestMethod()).contains(testMethod), () -> assertThat(methodExtensionContext.getRequiredTestClass()).isEqualTo(OuterClass.class), () -> assertThat(methodExtensionContext.getRequiredTestInstance()).isEqualTo(testInstance), () -> assertThat(methodExtensionContext.getRequiredTestMethod()).isEqualTo(testMethod), () -> assertThat(methodExtensionContext.getDisplayName()).isEqualTo(methodTestDescriptor.getDisplayName()), () -> assertThat(methodExtensionContext.getParent()).contains(classExtensionContext), () -> assertThat(methodExtensionContext.getRoot()).isSameAs(engineExtensionContext));
// @formatter:on
}
Also used : MethodExtensionContext(org.junit.jupiter.engine.descriptor.MethodExtensionContext) ClassExtensionContext(org.junit.jupiter.engine.descriptor.ClassExtensionContext) Method(java.lang.reflect.Method) NestedClassTestDescriptor(org.junit.jupiter.engine.descriptor.NestedClassTestDescriptor) ClassTestDescriptor(org.junit.jupiter.engine.descriptor.ClassTestDescriptor) JupiterEngineExtensionContext(org.junit.jupiter.engine.descriptor.JupiterEngineExtensionContext) TestMethodTestDescriptor(org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor) JupiterEngineDescriptor(org.junit.jupiter.engine.descriptor.JupiterEngineDescriptor) DynamicTest.dynamicTest(org.junit.jupiter.api.DynamicTest.dynamicTest) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest)

Example 3 with JupiterEngineExtensionContext

use of org.junit.jupiter.engine.descriptor.JupiterEngineExtensionContext in project junit5 by junit-team.

the class ExtensionContextTests method fromJupiterEngineDescriptor.

@Test
void fromJupiterEngineDescriptor() {
    JupiterEngineDescriptor engineTestDescriptor = new JupiterEngineDescriptor(UniqueId.root("engine", "junit-jupiter"));
    JupiterEngineExtensionContext engineContext = new JupiterEngineExtensionContext(null, engineTestDescriptor, configParams);
    // @formatter:off
    assertAll("engineContext", () -> assertThat(engineContext.getElement()).isEmpty(), () -> assertThat(engineContext.getTestClass()).isEmpty(), () -> assertThat(engineContext.getTestInstance()).isEmpty(), () -> assertThat(engineContext.getTestMethod()).isEmpty(), () -> assertThrows(PreconditionViolationException.class, () -> engineContext.getRequiredTestClass()), () -> assertThrows(PreconditionViolationException.class, () -> engineContext.getRequiredTestInstance()), () -> assertThrows(PreconditionViolationException.class, () -> engineContext.getRequiredTestMethod()), () -> assertThat(engineContext.getDisplayName()).isEqualTo(engineTestDescriptor.getDisplayName()), () -> assertThat(engineContext.getParent()).isEmpty(), () -> assertThat(engineContext.getRoot()).isSameAs(engineContext));
// @formatter:on
}
Also used : JupiterEngineExtensionContext(org.junit.jupiter.engine.descriptor.JupiterEngineExtensionContext) PreconditionViolationException(org.junit.platform.commons.util.PreconditionViolationException) JupiterEngineDescriptor(org.junit.jupiter.engine.descriptor.JupiterEngineDescriptor) DynamicTest.dynamicTest(org.junit.jupiter.api.DynamicTest.dynamicTest) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest)

Aggregations

JupiterEngineDescriptor (org.junit.jupiter.engine.descriptor.JupiterEngineDescriptor)3 JupiterEngineExtensionContext (org.junit.jupiter.engine.descriptor.JupiterEngineExtensionContext)3 Method (java.lang.reflect.Method)2 DynamicTest (org.junit.jupiter.api.DynamicTest)2 DynamicTest.dynamicTest (org.junit.jupiter.api.DynamicTest.dynamicTest)2 Test (org.junit.jupiter.api.Test)2 ClassExtensionContext (org.junit.jupiter.engine.descriptor.ClassExtensionContext)2 ClassTestDescriptor (org.junit.jupiter.engine.descriptor.ClassTestDescriptor)2 MethodExtensionContext (org.junit.jupiter.engine.descriptor.MethodExtensionContext)2 NestedClassTestDescriptor (org.junit.jupiter.engine.descriptor.NestedClassTestDescriptor)2 TestMethodTestDescriptor (org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor)2 TestFactory (org.junit.jupiter.api.TestFactory)1 ExtensionContext (org.junit.jupiter.api.extension.ExtensionContext)1 PreconditionViolationException (org.junit.platform.commons.util.PreconditionViolationException)1 ConfigurationParameters (org.junit.platform.engine.ConfigurationParameters)1 UniqueId (org.junit.platform.engine.UniqueId)1