Search in sources :

Example 6 with ClassExtensionContext

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

the class ExtensionContextTests method tagsCanBeRetrievedInExtensionContext.

@Test
@SuppressWarnings("resource")
void tagsCanBeRetrievedInExtensionContext() {
    ClassTestDescriptor nestedClassDescriptor = nestedClassDescriptor();
    ClassTestDescriptor outerClassDescriptor = outerClassDescriptor(nestedClassDescriptor);
    TestMethodTestDescriptor methodTestDescriptor = methodDescriptor();
    outerClassDescriptor.addChild(methodTestDescriptor);
    ClassExtensionContext outerExtensionContext = new ClassExtensionContext(null, null, outerClassDescriptor, configParams, null);
    assertThat(outerExtensionContext.getTags()).containsExactly("outer-tag");
    assertThat(outerExtensionContext.getRoot()).isSameAs(outerExtensionContext);
    ClassExtensionContext nestedExtensionContext = new ClassExtensionContext(outerExtensionContext, null, nestedClassDescriptor, configParams, null);
    assertThat(nestedExtensionContext.getTags()).containsExactlyInAnyOrder("outer-tag", "nested-tag");
    assertThat(nestedExtensionContext.getRoot()).isSameAs(outerExtensionContext);
    MethodExtensionContext methodExtensionContext = new MethodExtensionContext(outerExtensionContext, null, methodTestDescriptor, configParams, new OuterClass(), new ThrowableCollector());
    assertThat(methodExtensionContext.getTags()).containsExactlyInAnyOrder("outer-tag", "method-tag");
    assertThat(methodExtensionContext.getRoot()).isSameAs(outerExtensionContext);
}
Also used : MethodExtensionContext(org.junit.jupiter.engine.descriptor.MethodExtensionContext) ClassExtensionContext(org.junit.jupiter.engine.descriptor.ClassExtensionContext) NestedClassTestDescriptor(org.junit.jupiter.engine.descriptor.NestedClassTestDescriptor) ClassTestDescriptor(org.junit.jupiter.engine.descriptor.ClassTestDescriptor) TestMethodTestDescriptor(org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor) DynamicTest.dynamicTest(org.junit.jupiter.api.DynamicTest.dynamicTest) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest)

Example 7 with ClassExtensionContext

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

the class ExtensionContextTests method reportEntriesArePublishedToExecutionContext.

@Test
@SuppressWarnings("resource")
void reportEntriesArePublishedToExecutionContext() {
    ClassTestDescriptor classTestDescriptor = outerClassDescriptor(null);
    EngineExecutionListener engineExecutionListener = Mockito.spy(EngineExecutionListener.class);
    ExtensionContext extensionContext = new ClassExtensionContext(null, engineExecutionListener, classTestDescriptor, configParams, null);
    Map<String, String> map1 = Collections.singletonMap("key", "value");
    Map<String, String> map2 = Collections.singletonMap("other key", "other value");
    extensionContext.publishReportEntry(map1);
    extensionContext.publishReportEntry(map2);
    extensionContext.publishReportEntry("3rd key", "third value");
    ArgumentCaptor<ReportEntry> entryCaptor = ArgumentCaptor.forClass(ReportEntry.class);
    Mockito.verify(engineExecutionListener, Mockito.times(3)).reportingEntryPublished(Mockito.eq(classTestDescriptor), entryCaptor.capture());
    ReportEntry reportEntry1 = entryCaptor.getAllValues().get(0);
    ReportEntry reportEntry2 = entryCaptor.getAllValues().get(1);
    ReportEntry reportEntry3 = entryCaptor.getAllValues().get(2);
    assertEquals(map1, reportEntry1.getKeyValuePairs());
    assertEquals(map2, reportEntry2.getKeyValuePairs());
    assertEquals("third value", reportEntry3.getKeyValuePairs().get("3rd key"));
}
Also used : EngineExecutionListener(org.junit.platform.engine.EngineExecutionListener) ClassExtensionContext(org.junit.jupiter.engine.descriptor.ClassExtensionContext) ReportEntry(org.junit.platform.engine.reporting.ReportEntry) 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) NestedClassTestDescriptor(org.junit.jupiter.engine.descriptor.NestedClassTestDescriptor) ClassTestDescriptor(org.junit.jupiter.engine.descriptor.ClassTestDescriptor) DynamicTest.dynamicTest(org.junit.jupiter.api.DynamicTest.dynamicTest) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest)

Example 8 with ClassExtensionContext

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

the class JupiterEngineExecutionContextTests method extendWithAllAttributes.

@Test
void extendWithAllAttributes() {
    UniqueId uniqueId = UniqueId.parse("[engine:junit-jupiter]/[class:MyClass]");
    ClassTestDescriptor classTestDescriptor = new ClassTestDescriptor(uniqueId, getClass());
    ClassExtensionContext extensionContext = new ClassExtensionContext(null, null, classTestDescriptor, configParams, null);
    ExtensionRegistry extensionRegistry = ExtensionRegistry.createRegistryWithDefaultExtensions(configParams);
    TestInstanceProvider testInstanceProvider = mock(TestInstanceProvider.class);
    JupiterEngineExecutionContext newContext = // 
    originalContext.extend().withExtensionContext(// 
    extensionContext).withExtensionRegistry(// 
    extensionRegistry).withTestInstanceProvider(// 
    testInstanceProvider).build();
    assertSame(extensionContext, newContext.getExtensionContext());
    assertSame(extensionRegistry, newContext.getExtensionRegistry());
    assertSame(testInstanceProvider, newContext.getTestInstanceProvider());
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) ClassExtensionContext(org.junit.jupiter.engine.descriptor.ClassExtensionContext) ClassTestDescriptor(org.junit.jupiter.engine.descriptor.ClassTestDescriptor) ExtensionRegistry(org.junit.jupiter.engine.extension.ExtensionRegistry) Test(org.junit.jupiter.api.Test)

Aggregations

ClassExtensionContext (org.junit.jupiter.engine.descriptor.ClassExtensionContext)8 ClassTestDescriptor (org.junit.jupiter.engine.descriptor.ClassTestDescriptor)8 Test (org.junit.jupiter.api.Test)7 NestedClassTestDescriptor (org.junit.jupiter.engine.descriptor.NestedClassTestDescriptor)6 DynamicTest (org.junit.jupiter.api.DynamicTest)5 DynamicTest.dynamicTest (org.junit.jupiter.api.DynamicTest.dynamicTest)5 MethodExtensionContext (org.junit.jupiter.engine.descriptor.MethodExtensionContext)5 JupiterEngineExtensionContext (org.junit.jupiter.engine.descriptor.JupiterEngineExtensionContext)4 TestMethodTestDescriptor (org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor)4 UniqueId (org.junit.platform.engine.UniqueId)4 Method (java.lang.reflect.Method)3 ExtensionContext (org.junit.jupiter.api.extension.ExtensionContext)3 JupiterEngineDescriptor (org.junit.jupiter.engine.descriptor.JupiterEngineDescriptor)3 TestFactory (org.junit.jupiter.api.TestFactory)2 ExtensionRegistry (org.junit.jupiter.engine.extension.ExtensionRegistry)2 PreconditionViolationException (org.junit.platform.commons.util.PreconditionViolationException)2 ConfigurationParameters (org.junit.platform.engine.ConfigurationParameters)2 EngineExecutionListener (org.junit.platform.engine.EngineExecutionListener)2 ReportEntry (org.junit.platform.engine.reporting.ReportEntry)2 Collections (java.util.Collections)1