Search in sources :

Example 26 with UniqueId

use of org.junit.platform.engine.UniqueId in project junit5 by junit-team.

the class JavaElementsResolver method resolveAllSegments.

/**
 * Attempt to resolve all segments for the supplied unique ID.
 */
private Deque<TestDescriptor> resolveAllSegments(UniqueId uniqueId) {
    List<Segment> segments = uniqueId.getSegments();
    Deque<TestDescriptor> resolvedDescriptors = new LinkedList<>();
    resolvedDescriptors.addFirst(this.engineDescriptor);
    for (int index = 1; index < segments.size() && resolvedDescriptors.size() == index; index++) {
        Segment segment = segments.get(index);
        TestDescriptor parent = resolvedDescriptors.getLast();
        UniqueId partialUniqueId = parent.getUniqueId().append(segment);
        Optional<TestDescriptor> resolvedDescriptor = findTestDescriptorByUniqueId(partialUniqueId);
        if (!resolvedDescriptor.isPresent()) {
            // @formatter:off
            resolvedDescriptor = this.resolvers.stream().map(resolver -> resolver.resolveUniqueId(segment, parent)).filter(Optional::isPresent).map(Optional::get).findFirst();
            // @formatter:on
            resolvedDescriptor.ifPresent(parent::addChild);
        }
        resolvedDescriptor.ifPresent(resolvedDescriptors::addLast);
    }
    return resolvedDescriptors;
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) Optional(java.util.Optional) ClassTestDescriptor(org.junit.jupiter.engine.descriptor.ClassTestDescriptor) TestDescriptor(org.junit.platform.engine.TestDescriptor) Segment(org.junit.platform.engine.UniqueId.Segment) LinkedList(java.util.LinkedList)

Example 27 with UniqueId

use of org.junit.platform.engine.UniqueId in project junit5 by junit-team.

the class TestContainerResolver method resolveElement.

@Override
public Set<TestDescriptor> resolveElement(AnnotatedElement element, TestDescriptor parent) {
    if (!(element instanceof Class)) {
        return Collections.emptySet();
    }
    Class<?> clazz = (Class<?>) element;
    if (!isPotentialCandidate(clazz)) {
        return Collections.emptySet();
    }
    UniqueId uniqueId = createUniqueId(clazz, parent);
    return Collections.singleton(resolveClass(clazz, uniqueId));
}
Also used : UniqueId(org.junit.platform.engine.UniqueId)

Example 28 with UniqueId

use of org.junit.platform.engine.UniqueId in project junit5 by junit-team.

the class UniqueIdSelectorResolverTests method logsWarningOnUnexpectedTestDescriptor.

@Test
void logsWarningOnUnexpectedTestDescriptor(LogRecordListener listener) {
    UniqueId uniqueId = UniqueId.forEngine(ENGINE_ID).append("wrong-type", "foo:bar");
    EngineDiscoveryRequest request = requestWithSelector(selectUniqueId(uniqueId));
    new UniqueIdSelectorResolver().resolve(request, allClassesPredicate, collector);
    assertNoRequests();
    assertLoggedWarning(listener, "Unresolvable Unique ID (" + uniqueId + "): Unique ID segment after engine segment must be of type \"runner\"");
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) Test(org.junit.jupiter.api.Test)

Example 29 with UniqueId

use of org.junit.platform.engine.UniqueId in project junit5 by junit-team.

the class UniqueIdSelectorResolverTests method ignoresUniqueIdsOfOtherEngines.

@Test
void ignoresUniqueIdsOfOtherEngines(LogRecordListener listener) {
    UniqueId uniqueId = UniqueId.forEngine("someEngine");
    EngineDiscoveryRequest request = requestWithSelector(selectUniqueId(uniqueId));
    new UniqueIdSelectorResolver().resolve(request, allClassesPredicate, collector);
    assertNoRequests();
    assertThat(listener.stream(UniqueIdSelectorResolver.class)).isEmpty();
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) Test(org.junit.jupiter.api.Test)

Example 30 with UniqueId

use of org.junit.platform.engine.UniqueId in project junit5 by junit-team.

the class UniqueIdSelectorResolverTests method logsWarningOnUnloadableTestClass.

@Test
void logsWarningOnUnloadableTestClass(LogRecordListener listener) {
    UniqueId uniqueId = VintageUniqueIdBuilder.uniqueIdForClass("foo.bar.UnknownClass");
    EngineDiscoveryRequest request = requestWithSelector(selectUniqueId(uniqueId));
    new UniqueIdSelectorResolver().resolve(request, allClassesPredicate, collector);
    assertNoRequests();
    assertLoggedWarning(listener, "Unresolvable Unique ID (" + uniqueId + "): Unknown class foo.bar.UnknownClass");
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) Test(org.junit.jupiter.api.Test)

Aggregations

UniqueId (org.junit.platform.engine.UniqueId)78 Test (org.junit.jupiter.api.Test)59 DiscoverySelectors.selectUniqueId (org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId)44 DynamicTest (org.junit.jupiter.api.DynamicTest)32 TestDescriptor (org.junit.platform.engine.TestDescriptor)19 EngineDiscoveryRequest (org.junit.platform.engine.EngineDiscoveryRequest)13 UniqueIdSelector (org.junit.platform.engine.discovery.UniqueIdSelector)12 TestPlan (org.junit.platform.launcher.TestPlan)10 ClassSelector (org.junit.platform.engine.discovery.ClassSelector)8 TestDescriptorStub (org.junit.platform.engine.test.TestDescriptorStub)7 List (java.util.List)5 TrackLogRecords (org.junit.jupiter.engine.TrackLogRecords)5 ClassTestDescriptor (org.junit.jupiter.engine.descriptor.ClassTestDescriptor)5 Method (java.lang.reflect.Method)4 ArrayList (java.util.ArrayList)4 JupiterTestDescriptor (org.junit.jupiter.engine.descriptor.JupiterTestDescriptor)4 TestTemplateInvocationTestDescriptor (org.junit.jupiter.engine.descriptor.TestTemplateInvocationTestDescriptor)4 ExecutionRequest (org.junit.platform.engine.ExecutionRequest)4 ExecutionEventRecorder (org.junit.platform.engine.test.event.ExecutionEventRecorder)4 Optional (java.util.Optional)3