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

com.github.jjYBdx4IL.utils.env.Surefire Maven / Gradle / Ivy

/*
 * Copyright (C) 2016 jjYBdx4IL (https://github.com/jjYBdx4IL)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.github.jjYBdx4IL.utils.env;

/**
 *
 * @author jjYBdx4IL
 */
public class Surefire extends Maven {

    public final static String PROPNAME_SUREFIRE_TEST_CLASS_PATH = "surefire.test.class.path";

    public static String getSurefireTestClassPath() {
        String s = System.getProperty(PROPNAME_SUREFIRE_TEST_CLASS_PATH);
        if (s == null) {
            throw new IllegalStateException();
        }
        return s;
    }
    
    /**
     * JUnit test being run inside Eclipse without calling maven?
     * 
     * @return
     */
    public static boolean isEclipseDirectJUnit() {
        if (Maven.getMavenBasedir() == null && System.getProperty("sun.java.command").startsWith("org.eclipse.jdt.internal.junit.runner.RemoteTestRunner ")) {
        	return true;
        }
    	return false;
    }
    
    /**
     * Single JUnit test being run inside Eclipse without calling maven?
     * 
     * @return
     */
    public static boolean isEclipseDirectSingleJUnit() {
        if (System.getProperty("basedir") == null
      			&& System.getProperty("sun.java.command").startsWith("org.eclipse.jdt.internal.junit.runner.RemoteTestRunner ")
      			&& System.getProperty("sun.java.command").contains(" -test ")) {
        	return true;
        }
    	return false;
    }
    
    public static String getMavenBasedir() {
    	if (isEclipseDirectJUnit()) {
    		return System.getProperty("user.dir");
    	}
        return Maven.getMavenBasedir();
    }

    /**
     * Some junit tests might require user interaction. You may use
     * this function together with a junit assumption to prevent running those tests in junit batch runs.
     * 
     * @return
     */
    public static boolean isSingleTextExecution() {
        return isEclipseDirectSingleJUnit()
                || Maven.getMavenBasedir() != null && System.getProperty("test", "").contains("#");
    }
    
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy