use of org.evosuite.setup.InheritanceTree in project evosuite by EvoSuite.
the class TestFinalPrimitiveFieldIsNotAddedToCluster method test.
/**
* As RESET_STATIC_FINAL_FIELDS=true removes the <code>final</code> modifier
* of static fields in the target class, the purpose of this test case is to
* check that the TestClusterGenerator indeed does not include these fields.
*
* @throws ClassNotFoundException
* @throws RuntimeException
*/
@Test
public void test() throws ClassNotFoundException, RuntimeException {
Properties.TARGET_CLASS = FinalPrimitiveField.class.getCanonicalName();
Properties.RESET_STATIC_FINAL_FIELDS = true;
ClassPathHandler.getInstance().changeTargetCPtoTheSameAsEvoSuite();
String cp = ClassPathHandler.getInstance().getTargetProjectClasspath();
DependencyAnalysis.analyzeClass(Properties.TARGET_CLASS, Arrays.asList(cp.split(File.pathSeparator)));
InheritanceTree tree = DependencyAnalysis.getInheritanceTree();
TestClusterGenerator gen = new TestClusterGenerator(tree);
assertNotNull(gen);
TestCluster cluster = TestCluster.getInstance();
List<GenericAccessibleObject<?>> testCalls = cluster.getTestCalls();
assertEquals("Unexpected number of TestCalls", 2, testCalls.size());
}
use of org.evosuite.setup.InheritanceTree in project evosuite by EvoSuite.
the class TestFinalReferenceFieldIsNotAddedToCluster method test.
/**
* As RESET_STATIC_FINAL_FIELDS=true removes the <code>final</code> modifier
* of static fields in the target class, the purpose of this test case is to
* check that the TestClusterGenerator indeed does not include these fields.
*
* @throws ClassNotFoundException
* @throws RuntimeException
*/
@Test
public void test() throws ClassNotFoundException, RuntimeException {
Properties.TARGET_CLASS = FinalReferenceField.class.getCanonicalName();
Properties.RESET_STATIC_FINAL_FIELDS = true;
ClassPathHandler.getInstance().changeTargetCPtoTheSameAsEvoSuite();
String cp = ClassPathHandler.getInstance().getTargetProjectClasspath();
DependencyAnalysis.analyzeClass(Properties.TARGET_CLASS, Arrays.asList(cp.split(File.pathSeparator)));
InheritanceTree tree = DependencyAnalysis.getInheritanceTree();
TestClusterGenerator gen = new TestClusterGenerator(tree);
assertNotNull(gen);
TestCluster cluster = TestCluster.getInstance();
List<GenericAccessibleObject<?>> testCalls = cluster.getTestCalls();
assertEquals("Unexpected number of TestCalls", 2, testCalls.size());
}
use of org.evosuite.setup.InheritanceTree in project evosuite by EvoSuite.
the class CheapPurityAnalyzer method isPureSuperclass.
private boolean isPureSuperclass(MethodEntry entry, Stack<MethodEntry> callStack) {
InheritanceTree inheritanceTree = TestCluster.getInheritanceTree();
for (String superClassName : inheritanceTree.getOrderedSuperclasses(entry.className)) {
if (superClassName.equals(entry.className))
continue;
MethodEntry superEntry = new MethodEntry(superClassName, entry.methodName, entry.descriptor);
if (!callStack.contains(superEntry) && methodsWithBodies.contains(superEntry)) {
// We can conclude the purity of this method because
// we found an implementation in a super class for it
Stack<MethodEntry> newStack = new Stack<MethodEntry>();
newStack.addAll(callStack);
newStack.add(superEntry);
boolean purityValueForSuperClass = isPure(superEntry, newStack);
return purityValueForSuperClass;
}
}
// to default purity value
return DEFAULT_PURITY_VALUE;
}
use of org.evosuite.setup.InheritanceTree in project evosuite by EvoSuite.
the class CheapPurityAnalyzer method checkAnyOverridingMethodImpure.
private boolean checkAnyOverridingMethodImpure(MethodEntry entry, Stack<MethodEntry> callStack) {
InheritanceTree inheritanceTree = DependencyAnalysis.getInheritanceTree();
String className = "" + entry.className;
if (!inheritanceTree.hasClass(className)) {
logger.warn(className + " was not found in the inheritance tree. Using DEFAULT value for cheap-purity analysis");
return DEFAULT_PURITY_VALUE;
}
Set<String> subclasses = inheritanceTree.getSubclasses(className);
for (String subclassName : subclasses) {
if (!entry.className.equals(subclassName)) {
MethodEntry subclassEntry = new MethodEntry(subclassName, entry.methodName, entry.descriptor);
if (!callStack.contains(subclassEntry) && methodEntries.contains(subclassEntry)) {
Stack<MethodEntry> newStack = new Stack<MethodEntry>();
newStack.addAll(callStack);
newStack.add(subclassEntry);
if (!isPure(subclassEntry, newStack)) {
return true;
}
}
}
}
return false;
}
use of org.evosuite.setup.InheritanceTree in project evosuite by EvoSuite.
the class EvoSuite method generateInheritanceTree.
public static String generateInheritanceTree(String cp) throws IOException {
LoggingUtils.getEvoLogger().info("* Analyzing classpath (generating inheritance tree)");
List<String> cpList = Arrays.asList(cp.split(File.pathSeparator));
// Clear current inheritance file to make sure a new one is generated
Properties.INHERITANCE_FILE = "";
InheritanceTree tree = InheritanceTreeGenerator.createFromClassPath(cpList);
File outputFile = File.createTempFile("ES_inheritancetree", ".xml.gz");
outputFile.deleteOnExit();
InheritanceTreeGenerator.writeInheritanceTree(tree, outputFile);
return outputFile.getAbsolutePath();
}
Aggregations