use of org.junit.platform.engine.support.descriptor.ClassSource in project intellij-community by JetBrains.
the class JUnit5TestExecutionListener method getLocationHintValue.
static String getLocationHintValue(TestSource testSource, boolean isTest) {
if (testSource instanceof CompositeTestSource) {
CompositeTestSource compositeTestSource = ((CompositeTestSource) testSource);
for (TestSource sourceFromComposite : compositeTestSource.getSources()) {
String locationHintValue = getLocationHintValue(sourceFromComposite, isTest);
if (!NO_LOCATION_HINT_VALUE.equals(locationHintValue)) {
return locationHintValue;
}
}
return NO_LOCATION_HINT_VALUE;
}
if (testSource instanceof FileSource) {
FileSource fileSource = (FileSource) testSource;
File file = fileSource.getFile();
String line = fileSource.getPosition().map(position -> ":" + position.getLine()).orElse("");
return "file://" + file.getAbsolutePath() + line;
}
if (testSource instanceof MethodSource) {
MethodSource methodSource = (MethodSource) testSource;
return javaLocation(methodSource.getClassName(), methodSource.getMethodName(), isTest);
}
if (testSource instanceof ClassSource) {
String className = ((ClassSource) testSource).getClassName();
return javaLocation(className, null, isTest);
}
return NO_LOCATION_HINT_VALUE;
}
use of org.junit.platform.engine.support.descriptor.ClassSource in project ant by apache.
the class AbstractJUnitResultFormatter method isTestClass.
static Optional<ClassSource> isTestClass(final TestIdentifier testIdentifier) {
if (testIdentifier == null) {
return Optional.empty();
}
final Optional<TestSource> source = testIdentifier.getSource();
if (!source.isPresent()) {
return Optional.empty();
}
final TestSource testSource = source.get();
if (testSource instanceof ClassSource) {
return Optional.of((ClassSource) testSource);
}
return Optional.empty();
}
use of org.junit.platform.engine.support.descriptor.ClassSource in project junit5 by junit-team.
the class VintageTestEngineDiscoveryTests method assertClassSource.
private static void assertClassSource(Class<?> expectedClass, TestDescriptor testDescriptor) {
assertThat(testDescriptor.getSource()).containsInstanceOf(ClassSource.class);
ClassSource classSource = (ClassSource) testDescriptor.getSource().get();
assertThat(classSource.getJavaClass()).isEqualTo(expectedClass);
}
use of org.junit.platform.engine.support.descriptor.ClassSource in project junit5 by junit-team.
the class LegacyReportingUtils method getClassName.
// /CLOVER:ON
/**
* Get the class name for the supplied {@link TestIdentifier} using the
* supplied {@link TestPlan}.
*
* <p>This implementation attempts to find the closest test identifier with
* a {@link ClassSource} by traversing the hierarchy upwards towards the
* root starting with the supplied test identifier. In case no such source
* is found, it falls back to using the parent's
* {@linkplain TestIdentifier#getLegacyReportingName legacy reporting name}.
*
* @param testPlan the test plan that contains the {@code TestIdentifier};
* never {@code null}
* @param testIdentifier the identifier to determine the class name for;
* never {@code null}
* @see TestIdentifier#getLegacyReportingName
*/
public static String getClassName(TestPlan testPlan, TestIdentifier testIdentifier) {
Preconditions.notNull(testPlan, "testPlan must not be null");
Preconditions.notNull(testIdentifier, "testIdentifier must not be null");
for (TestIdentifier current = testIdentifier; current != null; current = getParent(testPlan, current)) {
ClassSource source = getClassSource(current);
if (source != null) {
return source.getClassName();
}
}
return getParentLegacyReportingName(testPlan, testIdentifier);
}
Aggregations