use of org.junit.jupiter.api.extension.ExtensionContext in project junit5 by junit-team.
the class ParameterizedTestExtensionTests method supportsReturnsFalseForTestMethodWithoutParameterizedTestAnnotation.
@Test
void supportsReturnsFalseForTestMethodWithoutParameterizedTestAnnotation() {
ExtensionContext extensionContextWithUnAnnotatedTestMethod = getExtensionContextReturningSingleMethod(new TestCaseWithMethod());
assertFalse(this.parameterizedTestExtension.supportsTestTemplate(extensionContextWithUnAnnotatedTestMethod));
}
use of org.junit.jupiter.api.extension.ExtensionContext in project junit5 by junit-team.
the class ParameterizedTestExtensionTests method supportsReturnsTrueForTestMethodWithParameterizedTestAnnotation.
@Test
void supportsReturnsTrueForTestMethodWithParameterizedTestAnnotation() {
ExtensionContext extensionContextWithAnnotatedTestMethod = getExtensionContextReturningSingleMethod(new TestCaseWithAnnotatedMethod());
assertTrue(this.parameterizedTestExtension.supportsTestTemplate(extensionContextWithAnnotatedTestMethod));
}
use of org.junit.jupiter.api.extension.ExtensionContext in project junit5 by junit-team.
the class Heavyweight method resolveParameter.
@Override
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext context) {
ExtensionContext engineContext = context.getRoot();
Store store = engineContext.getStore(ExtensionContext.Namespace.GLOBAL);
ResourceValue resource = store.getOrComputeIfAbsent(ResourceValue.class);
resource.usages.incrementAndGet();
return resource;
}
use of org.junit.jupiter.api.extension.ExtensionContext in project junit5 by junit-team.
the class ExtensionContextTests method usingStore.
@Test
@SuppressWarnings("resource")
void usingStore() {
TestMethodTestDescriptor methodTestDescriptor = methodDescriptor();
ClassTestDescriptor classTestDescriptor = outerClassDescriptor(methodTestDescriptor);
ExtensionContext parentContext = new ClassExtensionContext(null, null, classTestDescriptor, configParams, null);
MethodExtensionContext childContext = new MethodExtensionContext(parentContext, null, methodTestDescriptor, configParams, new OuterClass(), new ThrowableCollector());
ExtensionContext.Store childStore = childContext.getStore(Namespace.GLOBAL);
ExtensionContext.Store parentStore = parentContext.getStore(Namespace.GLOBAL);
final Object key1 = "key 1";
final String value1 = "a value";
childStore.put(key1, value1);
assertEquals(value1, childStore.get(key1));
assertEquals(value1, childStore.remove(key1));
assertNull(childStore.get(key1));
childStore.put(key1, value1);
assertEquals(value1, childStore.get(key1));
assertEquals(value1, childStore.remove(key1, String.class));
assertNull(childStore.get(key1));
final Object key2 = "key 2";
final String value2 = "other value";
assertEquals(value2, childStore.getOrComputeIfAbsent(key2, key -> value2));
assertEquals(value2, childStore.getOrComputeIfAbsent(key2, key -> value2, String.class));
assertEquals(value2, childStore.get(key2));
assertEquals(value2, childStore.get(key2, String.class));
final Object parentKey = "parent key";
final String parentValue = "parent value";
parentStore.put(parentKey, parentValue);
assertEquals(parentValue, childStore.getOrComputeIfAbsent(parentKey, k -> "a different value"));
assertEquals(parentValue, childStore.get(parentKey));
}
use of org.junit.jupiter.api.extension.ExtensionContext 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"));
}
Aggregations