use of org.junit.platform.engine.UniqueId in project junit5 by junit-team.
the class LegacyReportingUtilsTest method legacyReportingClassNameForDescendantOfTestIdentifierWithClassSourceIsClassName.
@Test
void legacyReportingClassNameForDescendantOfTestIdentifierWithClassSourceIsClassName() {
UniqueId classUniqueId = engineDescriptor.getUniqueId().append("class", "class");
TestDescriptor classDescriptor = createTestDescriptor(classUniqueId, "Class", ClassSource.from(LegacyReportingUtilsTest.class));
engineDescriptor.addChild(classDescriptor);
UniqueId subUniqueId = classUniqueId.append("sub", "baz");
TestDescriptor subDescriptor = createTestDescriptor(subUniqueId, "Baz", null);
classDescriptor.addChild(subDescriptor);
UniqueId subSubUniqueId = subUniqueId.append("subsub", "qux");
TestDescriptor subSubDescriptor = createTestDescriptor(subSubUniqueId, "Qux", null);
subDescriptor.addChild(subSubDescriptor);
assertThat(getClassName(engineDescriptor.getUniqueId())).isEqualTo("<unrooted>");
assertThat(getClassName(classUniqueId)).isEqualTo(LegacyReportingUtilsTest.class.getName());
assertThat(getClassName(subUniqueId)).isEqualTo(LegacyReportingUtilsTest.class.getName());
assertThat(getClassName(subSubUniqueId)).isEqualTo(LegacyReportingUtilsTest.class.getName());
}
use of org.junit.platform.engine.UniqueId in project junit5 by junit-team.
the class LegacyReportingUtilsTest method legacyReportingClassNameForTestIdentifierWithoutClassSourceIsParentLegacyReportingName.
@Test
void legacyReportingClassNameForTestIdentifierWithoutClassSourceIsParentLegacyReportingName() {
UniqueId uniqueId = engineDescriptor.getUniqueId().append("child", "bar");
TestDescriptor testDescriptor = createTestDescriptor(uniqueId, "Bar", null);
engineDescriptor.addChild(testDescriptor);
assertThat(getClassName(engineDescriptor.getUniqueId())).isEqualTo("<unrooted>");
assertThat(getClassName(uniqueId)).isEqualTo("Foo");
}
use of org.junit.platform.engine.UniqueId in project junit5 by junit-team.
the class DefaultLauncher method discoverEngineRoot.
private Optional<TestDescriptor> discoverEngineRoot(TestEngine testEngine, LauncherDiscoveryRequest discoveryRequest) {
UniqueId uniqueEngineId = UniqueId.forEngine(testEngine.getId());
try {
TestDescriptor engineRoot = testEngine.discover(discoveryRequest, uniqueEngineId);
Preconditions.notNull(engineRoot, () -> String.format("The discover() method for TestEngine with ID '%s' must return a non-null root TestDescriptor.", testEngine.getId()));
return Optional.of(engineRoot);
} catch (Throwable throwable) {
handleThrowable(testEngine, "discover", throwable);
return Optional.empty();
}
}
use of org.junit.platform.engine.UniqueId in project junit5 by junit-team.
the class TestClassRequestResolver method addChildrenRecursively.
private void addChildrenRecursively(VintageTestDescriptor parent) {
List<Description> children = parent.getDescription().getChildren();
// Use LinkedHashMap to preserve order, ArrayList for fast access by index
Map<String, List<Description>> childrenByUniqueId = children.stream().collect(groupingBy(uniqueIdReader.andThen(uniqueIdStringifier), LinkedHashMap::new, toCollection(ArrayList::new)));
for (Entry<String, List<Description>> entry : childrenByUniqueId.entrySet()) {
String uniqueId = entry.getKey();
List<Description> childrenWithSameUniqueId = entry.getValue();
IntFunction<String> uniqueIdGenerator = determineUniqueIdGenerator(uniqueId, childrenWithSameUniqueId);
for (int index = 0; index < childrenWithSameUniqueId.size(); index++) {
String reallyUniqueId = uniqueIdGenerator.apply(index);
Description description = childrenWithSameUniqueId.get(index);
UniqueId id = parent.getUniqueId().append(VintageTestDescriptor.SEGMENT_TYPE_TEST, reallyUniqueId);
VintageTestDescriptor child = new VintageTestDescriptor(id, description);
parent.addChild(child);
addChildrenRecursively(child);
}
}
}
use of org.junit.platform.engine.UniqueId in project junit5 by junit-team.
the class TestClassRequestResolver method createCompleteRunnerTestDescriptor.
private RunnerTestDescriptor createCompleteRunnerTestDescriptor(Class<?> testClass, Runner runner, UniqueId engineId) {
UniqueId id = engineId.append(SEGMENT_TYPE_RUNNER, testClass.getName());
RunnerTestDescriptor runnerTestDescriptor = new RunnerTestDescriptor(id, testClass, runner);
addChildrenRecursively(runnerTestDescriptor);
return runnerTestDescriptor;
}
Aggregations