use of org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor 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))));
}
use of org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor in project junit5 by junit-team.
the class TestMethodFilterTests method newTestMethodDescriptor.
private static TestMethodTestDescriptor newTestMethodDescriptor() throws Exception {
UniqueId uniqueId = UniqueId.forEngine("method");
Class<TestClass> testClass = TestClass.class;
Method testMethod = testClass.getMethod("testMethod");
return new TestMethodTestDescriptor(uniqueId, testClass, testMethod);
}
use of org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor 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
}
use of org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor 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.engine.descriptor.TestMethodTestDescriptor 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);
}
Aggregations