
com.atlassian.clover.recorder.TestNameSnifferHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of clover-runtime Show documentation
Show all versions of clover-runtime Show documentation
Clover's runtime library - required by code instrumented by Clover.
Clover is an award-winning code coverage and testing tool for Java and Groovy.
It integrates easily with Maven, Ant, Grails, Eclipse and IntelliJ IDEA
as well as with continuous integration servers such as Bamboo, Jenkins or Hudson.
The newest version!
package com.atlassian.clover.recorder;
import com.atlassian.clover.CloverNames;
import com.atlassian.clover.Logger;
import com_atlassian_clover.TestNameSniffer;
import java.lang.reflect.Field;
public class TestNameSnifferHelper {
/**
* Find the CloverNames.CLOVER_TEST_NAME_SNIFFER field in the current instance of a test class Return instance
* assigned to this field if it's a TestNameSniffer or null
otherwise.
*
* @return TestNameSniffer instance or null
*/
/*@Nullable*/
public static TestNameSniffer lookupTestSnifferField(Class currentTestClass) {
try {
Field sniffer = currentTestClass.getField(CloverNames.CLOVER_TEST_NAME_SNIFFER);
if (sniffer.getType().isAssignableFrom(TestNameSniffer.class)) {
return (TestNameSniffer) sniffer.get(null);
} else {
Logger.getInstance().debug("Unexpected type of the "
+ CloverNames.CLOVER_TEST_NAME_SNIFFER + " field: " + sniffer.getType().getName()
+ " - ignoring. Test name found during instrumentation may differ from the actual name of the test at runtime.");
}
} catch (NoSuchFieldException ex) {
Logger.getInstance().debug("Field " + CloverNames.CLOVER_TEST_NAME_SNIFFER
+ " was not found in an instance of " + currentTestClass.getName()
+ ". Test name found during instrumentation may differ from the actual name of the test at runtime.",
ex);
} catch (SecurityException | IllegalAccessException ex) {
Logger.getInstance().debug("Field " + CloverNames.CLOVER_TEST_NAME_SNIFFER
+ " couldn't be accessed in an instance of " + currentTestClass.getName()
+ ". Test name found during instrumentation may differ from the actual name of the test at runtime.",
ex);
}
// error when searching / accesing the field; return null
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy