org.junit.platform.engine.support.descriptor.ClassSource Java Examples

The following examples show how to use org.junit.platform.engine.support.descriptor.ClassSource. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AllureJunitPlatform.java    From allure-java with Apache License 2.0 7 votes vote down vote up
private List<Label> getSourceLabels(final TestSource source) {
    if (source instanceof MethodSource) {
        final MethodSource ms = (MethodSource) source;
        return Arrays.asList(
                createPackageLabel(ms.getClassName()),
                createTestClassLabel(ms.getClassName()),
                createTestMethodLabel(ms.getMethodName())
        );
    }
    if (source instanceof ClassSource) {
        final ClassSource cs = (ClassSource) source;
        return Arrays.asList(
                createPackageLabel(cs.getClassName()),
                createTestClassLabel(cs.getClassName())
        );
    }
    return Collections.emptyList();
}
 
Example #2
Source File: TestPlanExecutionReport.java    From junit5-extensions with MIT License 6 votes vote down vote up
private DisplayName getDisplayName(TestIdentifier testIdentifier) {
  LinkedList<String> names = new LinkedList<>();
  Optional<TestIdentifier> id = Optional.of(testIdentifier);
  do {
    TestIdentifier identifier = id.get();
    Optional<ClassSource> classSource = identifier.getSource()
        .filter(source -> source instanceof ClassSource)
        .map(source -> (ClassSource) source)
        .filter(source -> !source.getPosition().isPresent())
        .filter(source -> classesToSkip.contains(source.getJavaClass()));
    if (classSource.isPresent()) {
      break;
    }

    names.addFirst(identifier.getDisplayName());

    id = id.flatMap(testPlan::getParent);
  } while (id.isPresent());

  return DisplayName.create(names);
}
 
Example #3
Source File: JupiterTestCollector.java    From sbt-jupiter-interface with Apache License 2.0 6 votes vote down vote up
private String fullyQualifiedName(TestIdentifier testIdentifier) {

        TestSource testSource = testIdentifier.getSource().orElse(null);

        if (testSource instanceof ClassSource) {

            ClassSource classSource = (ClassSource)testSource;
            return classSource.getClassName();
        }

        if (testSource instanceof MethodSource) {

            MethodSource methodSource = (MethodSource)testSource;
            return methodSource.getClassName()
                    + '#' + methodSource.getMethodName()
                    + '(' + methodSource.getMethodParameterTypes() + ')';
        }

        return testIdentifier.getLegacyReportingName();
    }
 
Example #4
Source File: Configuration.java    From sbt-jupiter-interface with Apache License 2.0 6 votes vote down vote up
/**
 * Extracts the class-name from the specified test identifier.
 *
 * @param identifier The identifier from which to extract the class-name.
 * @return The class-name of the specified test identifier.
 */
public String extractClassName(TestIdentifier identifier) {

    TestSource testSource = identifier.getSource().orElseThrow(() ->
            new RuntimeException("Test identifier without source: " + identifier));

    if (testSource instanceof ClassSource) {
        return ((ClassSource)testSource).getClassName();
    }

    if (testSource instanceof MethodSource) {
        return ((MethodSource)testSource).getClassName();
    }

    throw new RuntimeException("Test identifier with unknown source: " + identifier);
}
 
Example #5
Source File: TaskName.java    From sbt-jupiter-interface with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a task name for the specified {@code identifier}.
 *
 * @param testSuite The name of the test suite.
 * @param identifier The test identifier.
 * @return A task name representing the given identifier.
 */
static TaskName of(String testSuite, TestIdentifier identifier) {

    TaskName result = new TaskName();
    result.fullyQualifiedName = testSuite;

    TestSource testSource = identifier.getSource().orElse(null);

    if (testSource instanceof ClassSource) {

        ClassSource classSource = (ClassSource)testSource;
        result.nestedSuiteId = nestedSuiteId(testSuite, classSource.getClassName());
    }

    if (testSource instanceof MethodSource) {

        MethodSource methodSource = (MethodSource)testSource;
        result.nestedSuiteId = nestedSuiteId(testSuite, methodSource.getClassName());
        result.invocation = invocation(UniqueId.parse(identifier.getUniqueId()));
        result.testName = testName(methodSource.getMethodName(),
                methodSource.getMethodParameterTypes());
    }

    return result;
}
 
Example #6
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 6 votes vote down vote up
@Test
void an_unique_id() {
    UniqueId ruleIdToDiscover = simpleRulesId(engineId)
            .append(FIELD_SEGMENT_TYPE, SimpleRules.SIMPLE_RULE_FIELD_ONE_NAME);
    EngineDiscoveryTestRequest discoveryRequest = new EngineDiscoveryTestRequest().withUniqueId(ruleIdToDiscover);

    TestDescriptor descriptor = getOnlyTest(testEngine.discover(discoveryRequest, engineId));

    assertThat(descriptor.getUniqueId()).isEqualTo(ruleIdToDiscover);
    assertThat(descriptor.getDisplayName()).isEqualTo(SimpleRules.SIMPLE_RULE_FIELD_ONE_NAME);
    assertThat(descriptor.getChildren()).isEmpty();
    assertThat(descriptor.getDescendants()).isEmpty();
    assertThat(descriptor.getType()).isEqualTo(TEST);
    assertThat(descriptor.getSource().get()).isEqualTo(FieldSource.from(field(SimpleRules.class, SimpleRules.SIMPLE_RULE_FIELD_ONE_NAME)));
    assertThat(descriptor.getParent().get().getSource().get()).isEqualTo(ClassSource.from(SimpleRules.class));
}
 
Example #7
Source File: AllureJunitPlatform.java    From allure-java with Apache License 2.0 5 votes vote down vote up
private Optional<String> getFullName(final TestSource source) {
    if (source instanceof MethodSource) {
        final MethodSource ms = (MethodSource) source;
        return Optional.of(String.format("%s.%s", ms.getClassName(), ms.getMethodName()));
    }
    if (source instanceof ClassSource) {
        final ClassSource cs = (ClassSource) source;
        return Optional.ofNullable(cs.getClassName());
    }
    return Optional.empty();
}
 
Example #8
Source File: AllureJunitPlatform.java    From allure-java with Apache License 2.0 5 votes vote down vote up
private Optional<Class<?>> getTestClass(final TestSource source) {
    if (source instanceof MethodSource) {
        return getTestClass(((MethodSource) source).getClassName());
    }
    if (source instanceof ClassSource) {
        return Optional.of(((ClassSource) source).getJavaClass());
    }
    return Optional.empty();
}
 
Example #9
Source File: Configuration.java    From sbt-jupiter-interface with Apache License 2.0 5 votes vote down vote up
private String toVintageName(TestIdentifier identifier, Segment lastSegment) {

            final String type = lastSegment.getType();

            if ("runner".equals(type)) {

                String className = identifier.getDisplayName();
                return colorClassName(className, colorTheme.container());
            }

            if ("test".equals(type)) {

                final TestSource source = identifier.getSource().orElse(null);

                if (null == source) {
                    // Caused by Parameterized test runner, display name usually is the index name in brackets.
                    // Ignored since the index name is repeated in the display name of the test method.
                    return null;
                }

                if (source instanceof ClassSource) {
                    String nestedClassName = "$" + identifier.getDisplayName().replaceFirst(".*?\\$", "");
                    return colorTheme.container().format(nestedClassName);
                }

                if (source instanceof MethodSource) {
                    String testName = "#" + identifier.getDisplayName();
                    return colorTheme.testMethod().format(testName);
                }
            }

            return "/" + identifier.getDisplayName();
        }
 
Example #10
Source File: ArchUnitTestDescriptor.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
ArchUnitRulesDescriptor(ElementResolver resolver, DeclaredArchRules rules, Supplier<JavaClasses> classes, Field field) {

            super(resolver.getUniqueId(),
                    rules.getDisplayName(),
                    ClassSource.from(rules.getDefinitionLocation()),
                    field,
                    rules.getDefinitionLocation());
            this.rules = rules;
            this.classes = classes;
        }
 
Example #11
Source File: ArchUnitTestDescriptor.java    From ArchUnit with Apache License 2.0 4 votes vote down vote up
private ArchUnitTestDescriptor(ElementResolver resolver, Class<?> testClass, ClassCache classCache) {
    super(resolver.getUniqueId(), testClass.getSimpleName(), ClassSource.from(testClass), testClass);
    this.testClass = testClass;
    this.classCache = classCache;
}
 
Example #12
Source File: ArchUnitTestEngineTest.java    From ArchUnit with Apache License 2.0 4 votes vote down vote up
private void assertClassSource(TestDescriptor child, Class<?> aClass) {
    ClassSource classSource = (ClassSource) child.getSource().get();
    assertThat(classSource.getClassName()).isEqualTo(aClass.getName());
    assertThat(classSource.getJavaClass()).isEqualTo(aClass);
    assertThat(classSource.getPosition().isPresent()).as("position is present").isFalse();
}