use of org.junit.platform.engine.UniqueId in project intellij-community by JetBrains.
the class JUnit5NavigationTest method methodNavigation.
@Test
void methodNavigation() throws Exception {
UniqueId uniqueId = UniqueId.parse("[class:JUnit5NavigationTest]/[method:methodNavigation]");
MethodTestDescriptor methodTestDescriptor = new MethodTestDescriptor(uniqueId, JUnit5NavigationTest.class, JUnit5NavigationTest.class.getDeclaredMethod("methodNavigation"));
TestIdentifier testIdentifier = TestIdentifier.from(methodTestDescriptor);
Assertions.assertEquals(JUnit5NavigationTest.class.getName(), JUnit5TestExecutionListener.getClassName(testIdentifier));
Assertions.assertEquals("methodNavigation", JUnit5TestExecutionListener.getMethodName(testIdentifier));
//Assertions.assertEquals("methodNavigation", testIdentifier.getDisplayName()); todo methodNavigation()
}
use of org.junit.platform.engine.UniqueId in project junit5 by junit-team.
the class AbstractMethodResolver method createTestDescriptor.
private TestDescriptor createTestDescriptor(TestDescriptor parent, Method method) {
UniqueId uniqueId = createUniqueId(method, parent);
Class<?> testClass = ((ClassTestDescriptor) parent).getTestClass();
return createTestDescriptor(uniqueId, testClass, method);
}
use of org.junit.platform.engine.UniqueId in project junit5 by junit-team.
the class TestFactoryTestDescriptor method createDynamicDescriptor.
static Optional<JupiterTestDescriptor> createDynamicDescriptor(JupiterTestDescriptor parent, DynamicNode node, int index, TestSource source, DynamicDescendantFilter dynamicDescendantFilter) {
UniqueId uniqueId;
Supplier<JupiterTestDescriptor> descriptorCreator;
if (node instanceof DynamicTest) {
DynamicTest test = (DynamicTest) node;
uniqueId = parent.getUniqueId().append(DYNAMIC_TEST_SEGMENT_TYPE, "#" + index);
descriptorCreator = () -> new DynamicTestTestDescriptor(uniqueId, index, test, source);
} else {
DynamicContainer container = (DynamicContainer) node;
uniqueId = parent.getUniqueId().append(DYNAMIC_CONTAINER_SEGMENT_TYPE, "#" + index);
descriptorCreator = () -> new DynamicContainerTestDescriptor(uniqueId, index, container, source, dynamicDescendantFilter);
}
if (dynamicDescendantFilter.test(uniqueId)) {
JupiterTestDescriptor descriptor = descriptorCreator.get();
parent.addChild(descriptor);
return Optional.of(descriptor);
}
return Optional.empty();
}
use of org.junit.platform.engine.UniqueId in project junit5 by junit-team.
the class TestContainerResolver method resolveUniqueId.
@Override
public Optional<TestDescriptor> resolveUniqueId(UniqueId.Segment segment, TestDescriptor parent) {
if (!segment.getType().equals(getSegmentType())) {
return Optional.empty();
}
if (!requiredParentType().isInstance(parent)) {
return Optional.empty();
}
String className = getClassName(parent, segment.getValue());
Optional<Class<?>> optionalContainerClass = ReflectionUtils.loadClass(className);
if (!optionalContainerClass.isPresent()) {
return Optional.empty();
}
Class<?> containerClass = optionalContainerClass.get();
if (!isPotentialCandidate(containerClass)) {
return Optional.empty();
}
UniqueId uniqueId = createUniqueId(containerClass, parent);
return Optional.of(resolveClass(containerClass, uniqueId));
}
use of org.junit.platform.engine.UniqueId in project junit5 by junit-team.
the class VintageTestEngineDiscoveryTests method usesCustomUniqueIdsWhenPresent.
@Test
void usesCustomUniqueIdsWhenPresent() {
Class<?> testClass = JUnit4TestCaseWithRunnerWithCustomUniqueIds.class;
LauncherDiscoveryRequest request = request().selectors(selectClass(testClass)).build();
TestDescriptor engineDescriptor = discoverTests(request);
TestDescriptor runnerDescriptor = getOnlyElement(engineDescriptor.getChildren());
assertRunnerTestDescriptor(runnerDescriptor, testClass);
TestDescriptor childDescriptor = getOnlyElement(runnerDescriptor.getChildren());
UniqueId prefix = VintageUniqueIdBuilder.uniqueIdForClass(testClass);
assertThat(childDescriptor.getUniqueId().toString()).startsWith(prefix.toString());
String customUniqueIdValue = childDescriptor.getUniqueId().getSegments().get(2).getType();
assertNotNull(Base64.getDecoder().decode(customUniqueIdValue.getBytes(StandardCharsets.UTF_8)), "is a valid Base64 encoding scheme");
}
Aggregations