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

io.qameta.allure.tree.TreeGroup Maven / Gradle / Ivy

There is a newer version: 2.30.0
Show newest version
package io.qameta.allure.tree;

import io.qameta.allure.entity.LabelName;
import io.qameta.allure.entity.TestResult;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @author charlie (Dmitry Baev).
 */
@FunctionalInterface
public interface TreeGroup {

    List getGroupNames();

    static TreeGroup values(String... values) {
        return () -> Arrays.asList(values);
    }

    static TreeGroup values(List values) {
        return () -> Collections.unmodifiableList(values);
    }

    static TreeGroup allByLabel(TestResult result, LabelName labelName, String... defaultGroups) {
        Set groups = result.findAll(labelName, Collectors.toSet());
        if (groups.isEmpty()) {
            return values(defaultGroups);
        }
        return values(new ArrayList<>(groups));
    }

    static TreeGroup oneByLabel(TestResult result, LabelName labelName, String defaultGroup) {
        return values(result.findOne(labelName).orElse(defaultGroup));
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy