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);
}
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"));
}
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());
}
Aggregations