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

org.pitest.mutationtest.verify.MissingJUnit5PluginVerifierFactory Maven / Gradle / Ivy

There is a newer version: 1.17.1
Show newest version
package org.pitest.mutationtest.verify;

import org.pitest.classinfo.ClassName;
import org.pitest.classpath.CodeSource;
import org.pitest.util.Log;

import java.util.Collections;
import java.util.List;

import static java.util.Arrays.asList;

public class MissingJUnit5PluginVerifierFactory implements BuildVerifierFactory {
    @Override
    public BuildVerifier create(CodeSource code) {
        return new MissingJUnit5PluginVerifier(code);
    }

    @Override
    public String description() {
        return "Detect missing JUnit5 plugin";
    }

}

class MissingJUnit5PluginVerifier implements BuildVerifier {

    private final CodeSource code;

    MissingJUnit5PluginVerifier(CodeSource code) {
        this.code = code;
    }

    @Override
    public List verify() {
        if (!junit5PluginIsPresent() && junitJupiterPresent()) {
            // log as well as return in case the run is aborted before messages are displayed at the end
            String msg = "JUnit 5 is on the classpath but the pitest junit 5 plugin is not installed (https://github.com/pitest/pitest-junit5-plugin)";
            Log.getLogger().warning(msg);
            return asList(msg);
        }

        return Collections.emptyList();
    }

    private boolean junitJupiterPresent() {
        return code.fetchClassBytes(ClassName.fromString("org.junit.jupiter.api.Test")).isPresent();
    }

    private boolean junit5PluginIsPresent() {
        return code.fetchClassBytes(ClassName.fromString("org.pitest.junit5.JUnit5TestPluginFactory")).isPresent();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy