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

com.github.aoreshin.junit5.extensions.ExcludeDisplayNameRegexExecutionCondition Maven / Gradle / Ivy

There is a newer version: 83
Show newest version
package com.github.aoreshin.junit5.extensions;

import org.junit.jupiter.api.extension.ConditionEvaluationResult;
import org.junit.jupiter.api.extension.ExecutionCondition;
import org.junit.jupiter.api.extension.ExtensionContext;

import java.util.regex.Pattern;

import static org.junit.jupiter.api.extension.ConditionEvaluationResult.disabled;
import static org.junit.jupiter.api.extension.ConditionEvaluationResult.enabled;

public final class ExcludeDisplayNameRegexExecutionCondition implements ExecutionCondition {
    private static final String PROPERTY_NAME = "excludeDisplayNamesRegex";
    private final String PATTERN = System.getProperty(PROPERTY_NAME);

    @Override
    public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
        if (PATTERN != null) {
            String displayName = context.getDisplayName();

            if (Pattern.matches(PATTERN, displayName)) {
                return disabled(displayName + " matches " + PROPERTY_NAME + " pattern " + PATTERN);
            }

            return enabled(displayName + " doesn't match " + PROPERTY_NAME + " pattern " + PATTERN);
        }

        return enabled(PROPERTY_NAME + " property is null");
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy