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

io.cucumber.junit.platform.engine.DefaultNamingStrategy Maven / Gradle / Ivy

There is a newer version: 7.20.1
Show newest version
package io.cucumber.junit.platform.engine;

import io.cucumber.plugin.event.Node;

import java.util.Locale;
import java.util.function.Supplier;

enum DefaultNamingStrategy implements NamingStrategy {

    LONG {
        @Override
        public String name(Node node) {
            StringBuilder builder = new StringBuilder();
            builder.append(nameOrKeyword(node));
            node = node.getParent().orElse(null);

            while (node != null) {
                builder.insert(0, " - ");
                builder.insert(0, nameOrKeyword(node));
                node = node.getParent().orElse(null);
            }

            return builder.toString();
        }
    },

    SHORT {
        @Override
        public String name(Node node) {
            return nameOrKeyword(node);
        }
    };

    static DefaultNamingStrategy getStrategy(String s) {
        return valueOf(s.toUpperCase(Locale.ROOT));
    }

    private static String nameOrKeyword(Node node) {
        Supplier keyword = () -> node.getKeyword().orElse("Unknown");
        return node.getName().orElseGet(keyword);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy