Search in sources :

Example 1 with DynamicContainer

use of org.junit.jupiter.api.DynamicContainer in project junit5 by junit-team.

the class TestFactoryTestDescriptor method createDynamicDescriptor.

static Optional<JupiterTestDescriptor> createDynamicDescriptor(JupiterTestDescriptor parent, DynamicNode node, int index, TestSource source, DynamicDescendantFilter dynamicDescendantFilter) {
    UniqueId uniqueId;
    Supplier<JupiterTestDescriptor> descriptorCreator;
    if (node instanceof DynamicTest) {
        DynamicTest test = (DynamicTest) node;
        uniqueId = parent.getUniqueId().append(DYNAMIC_TEST_SEGMENT_TYPE, "#" + index);
        descriptorCreator = () -> new DynamicTestTestDescriptor(uniqueId, index, test, source);
    } else {
        DynamicContainer container = (DynamicContainer) node;
        uniqueId = parent.getUniqueId().append(DYNAMIC_CONTAINER_SEGMENT_TYPE, "#" + index);
        descriptorCreator = () -> new DynamicContainerTestDescriptor(uniqueId, index, container, source, dynamicDescendantFilter);
    }
    if (dynamicDescendantFilter.test(uniqueId)) {
        JupiterTestDescriptor descriptor = descriptorCreator.get();
        parent.addChild(descriptor);
        return Optional.of(descriptor);
    }
    return Optional.empty();
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) DynamicContainer(org.junit.jupiter.api.DynamicContainer) DynamicTest(org.junit.jupiter.api.DynamicTest)

Aggregations

DynamicContainer (org.junit.jupiter.api.DynamicContainer)1 DynamicTest (org.junit.jupiter.api.DynamicTest)1 UniqueId (org.junit.platform.engine.UniqueId)1