All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.serenitybdd.junit5.JunitTestHierarchy Maven / Gradle / Ivy

There is a newer version: 4.2.9
Show newest version
package net.serenitybdd.junit5;

import org.junit.platform.engine.support.descriptor.ClassSource;
import org.junit.platform.launcher.TestIdentifier;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class JunitTestHierarchy {
    private static final JunitTestHierarchy INSTANCE = new JunitTestHierarchy();

    private final Map classPathToDisplayName = new ConcurrentHashMap<>();
    private final Map idToDisplayName = new ConcurrentHashMap<>();
    private final Map idToParent = new ConcurrentHashMap<>();

    public static JunitTestHierarchy getInstance() {
        return INSTANCE;
    }

    public void testSuiteStarted(TestIdentifier testIdentifier) {
        idToDisplayName.put(testIdentifier.getUniqueId(), testIdentifier.getDisplayName());
        if (testIdentifier.getSource().isPresent() && testIdentifier.getSource().get() instanceof ClassSource) {
            String className = ((ClassSource) testIdentifier.getSource().get()).getClassName();
            classPathToDisplayName.put(className, testIdentifier.getDisplayName());
        }
        testIdentifier.getParentId().ifPresent(
                parentId -> idToParent.put(testIdentifier.getUniqueId(), parentId)
        );

    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy