Search in sources :

Example 1 with ClassSource

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;
}
Also used : ReportEntry(org.junit.platform.engine.reporting.ReportEntry) TestPlan(org.junit.platform.launcher.TestPlan) JUnit4TestListener(com.intellij.junit4.JUnit4TestListener) CompositeTestSource(org.junit.platform.engine.support.descriptor.CompositeTestSource) TestExecutionResult(org.junit.platform.engine.TestExecutionResult) ClassSource(org.junit.platform.engine.support.descriptor.ClassSource) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) AssertionFailedError(org.opentest4j.AssertionFailedError) Map(java.util.Map) ExpectedPatterns(com.intellij.junit4.ExpectedPatterns) MapSerializerUtil(com.intellij.rt.execution.junit.MapSerializerUtil) MethodSource(org.junit.platform.engine.support.descriptor.MethodSource) PrintStream(java.io.PrintStream) PrintWriter(java.io.PrintWriter) ComparisonFailureData(com.intellij.rt.execution.junit.ComparisonFailureData) FileSource(org.junit.platform.engine.support.descriptor.FileSource) MultipleFailuresError(org.opentest4j.MultipleFailuresError) StringWriter(java.io.StringWriter) TestSource(org.junit.platform.engine.TestSource) Set(java.util.Set) File(java.io.File) TestIdentifier(org.junit.platform.launcher.TestIdentifier) ValueWrapper(org.opentest4j.ValueWrapper) TestExecutionListener(org.junit.platform.launcher.TestExecutionListener) CompositeTestSource(org.junit.platform.engine.support.descriptor.CompositeTestSource) CompositeTestSource(org.junit.platform.engine.support.descriptor.CompositeTestSource) TestSource(org.junit.platform.engine.TestSource) FileSource(org.junit.platform.engine.support.descriptor.FileSource) MethodSource(org.junit.platform.engine.support.descriptor.MethodSource) File(java.io.File) ClassSource(org.junit.platform.engine.support.descriptor.ClassSource)

Example 2 with ClassSource

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();
}
Also used : TestSource(org.junit.platform.engine.TestSource) ClassSource(org.junit.platform.engine.support.descriptor.ClassSource)

Example 3 with ClassSource

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);
}
Also used : ClassSource(org.junit.platform.engine.support.descriptor.ClassSource)

Example 4 with ClassSource

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);
}
Also used : TestIdentifier(org.junit.platform.launcher.TestIdentifier) ClassSource(org.junit.platform.engine.support.descriptor.ClassSource)

Aggregations

ClassSource (org.junit.platform.engine.support.descriptor.ClassSource)4 TestSource (org.junit.platform.engine.TestSource)2 TestIdentifier (org.junit.platform.launcher.TestIdentifier)2 ExpectedPatterns (com.intellij.junit4.ExpectedPatterns)1 JUnit4TestListener (com.intellij.junit4.JUnit4TestListener)1 ComparisonFailureData (com.intellij.rt.execution.junit.ComparisonFailureData)1 MapSerializerUtil (com.intellij.rt.execution.junit.MapSerializerUtil)1 File (java.io.File)1 PrintStream (java.io.PrintStream)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 TestExecutionResult (org.junit.platform.engine.TestExecutionResult)1 ReportEntry (org.junit.platform.engine.reporting.ReportEntry)1 CompositeTestSource (org.junit.platform.engine.support.descriptor.CompositeTestSource)1 FileSource (org.junit.platform.engine.support.descriptor.FileSource)1 MethodSource (org.junit.platform.engine.support.descriptor.MethodSource)1