/** * This methods derive the dependencies between {@link CBranchTestFitness} and branches. * Therefore, it is used to update 'this.dependencies' */ @SuppressWarnings("unchecked") private void addDependencies4CBranch() { logger.debug("Added dependencies for CBranch"); CallGraph callGraph = DependencyAnalysis.getCallGraph(); for (BranchCoverageTestFitness branch : this.dependencies.keySet()) { for (CallContext context : callGraph.getMethodEntryPoint(branch.getClassName(), branch.getMethod())) { CBranchTestFitness cBranch = new CBranchTestFitness(branch.getBranchGoal(), context); this.dependencies.get(branch).add((FitnessFunction<T>) cBranch); logger.debug("Added context branch: " + cBranch.toString()); } } }
@Override public List<CBranchTestFitness> getCoverageGoals() { //TODO this creates duplicate goals. Momentary fixed using a Set, but it should be optimised Set<CBranchTestFitness> goals = new HashSet<>(); // retrieve set of branches BranchCoverageFactory branchFactory = new BranchCoverageFactory(); List<BranchCoverageTestFitness> branchGoals = branchFactory.getCoverageGoals(); CallGraph callGraph = DependencyAnalysis.getCallGraph(); // try to find all occurrences of this branch in the call tree for (BranchCoverageTestFitness branchGoal : branchGoals) { logger.info("Adding context branches for " + branchGoal.toString()); for (CallContext context : callGraph.getMethodEntryPoint(branchGoal.getClassName(), branchGoal.getMethod())) { goals.add(new CBranchTestFitness(branchGoal.getBranchGoal(), context)); } } logger.info("Created " + goals.size() + " goals"); return new ArrayList<CBranchTestFitness>(goals); } }
@Override public List<IBranchTestFitness> getCoverageGoals() { //TODO this creates duplicate goals. Momentary fixed using a Set. Set<IBranchTestFitness> goals = new HashSet<IBranchTestFitness>(); // retrieve set of branches BranchCoverageFactory branchFactory = new BranchCoverageFactory(); List<BranchCoverageTestFitness> branchGoals = branchFactory.getCoverageGoalsForAllKnownClasses(); CallGraph callGraph = DependencyAnalysis.getCallGraph(); // try to find all occurrences of this branch in the call tree for (BranchCoverageTestFitness branchGoal : branchGoals) { logger.info("Adding context branches for " + branchGoal.toString()); for (CallContext context : callGraph.getAllContextsFromTargetClass(branchGoal.getClassName(), branchGoal.getMethod())) { //if is not possible to reach this branch from the target class, continue. if(context.isEmpty()) continue; goals.add(new IBranchTestFitness(branchGoal.getBranchGoal(), context)); } } assert(goals.size()>=branchFactory.getCoverageGoals().size()); logger.info("Created " + goals.size() + " goals"); return new ArrayList<IBranchTestFitness>(goals); } }
/** * test level 3 context masked by an abstract class and an interface */ @Test public void test3levelContext() { String context2 = DependencyAnalysis .getCallGraph() .getAllContextsFromTargetClass( "com.examples.with.different.packagename.context.SubSubClass", "innermethod(I)Z").toString(); System.out.println(DependencyAnalysis .getCallGraph().getViewOfCurrentMethods()); assertEquals( context2, "[com.examples.with.different.packagename.context.EntryPointsClass:dosmt(I)V com.examples.with.different.packagename.context.SubClass:checkFiftneen(I)Z com.examples.with.different.packagename.context.SubClass:bla(I)Z com.examples.with.different.packagename.context.SubSubClass:innermethod(I)Z]"); }
/** * test level 2 context masked by an abtract class */ @Test public void test2levelContext() { String context2 = DependencyAnalysis .getCallGraph() .getAllContextsFromTargetClass( "com.examples.with.different.packagename.context.SubClass", "bla(I)Z").toString(); System.out.println(DependencyAnalysis .getCallGraph().getViewOfCurrentMethods()); assertEquals( context2, "[com.examples.with.different.packagename.context.EntryPointsClass:dosmt(I)V com.examples.with.different.packagename.context.SubClass:checkFiftneen(I)Z com.examples.with.different.packagename.context.SubClass:bla(I)Z]"); }
@Test public void test1levelContext() { String context1 = DependencyAnalysis .getCallGraph() .getAllContextsFromTargetClass( "com.examples.with.different.packagename.context.SubClass", "checkFiftneen(I)Z").toString(); assertEquals( context1, "[com.examples.with.different.packagename.context.EntryPointsClass:dosmt(I)V com.examples.with.different.packagename.context.SubClass:checkFiftneen(I)Z]"); }
@Test public void testContextInParamethers() { String context2 = DependencyAnalysis .getCallGraph() .getAllContextsFromTargetClass( "com.examples.with.different.packagename.context.complex.ParameterObject", "isEnabled()Z").toString(); assertEquals( context2, "[com.examples.with.different.packagename.context.complex.EntryPointsClass:doObj(Lcom/examples/with/different/packagename/context/complex/AParameterObject;)V com.examples.with.different.packagename.context.complex.ParameterObject:isEnabled()Z]"); }
@Test public void test1levelContext() { String context1 = DependencyAnalysis .getCallGraph() .getAllContextsFromTargetClass( "com.examples.with.different.packagename.context.complex.SubClass", "checkFiftneen(I)Z").toString(); assertEquals( context1, "[com.examples.with.different.packagename.context.complex.EntryPointsClass:dosmt(ILjava/lang/String;D)V com.examples.with.different.packagename.context.complex.SubClass:checkFiftneen(I)Z]"); }
/** * test level 3 context masked by an abstract class and an interface */ @Test public void test3levelContext() { String context2 = DependencyAnalysis .getCallGraph() .getAllContextsFromTargetClass( "com.examples.with.different.packagename.context.complex.SubSubClass", "innermethod(I)Z").toString(); assertEquals( context2, "[com.examples.with.different.packagename.context.complex.EntryPointsClass:dosmt(ILjava/lang/String;D)V com.examples.with.different.packagename.context.complex.SubClass:checkFiftneen(I)Z com.examples.with.different.packagename.context.complex.SubClass:bla(I)Z com.examples.with.different.packagename.context.complex.SubSubClass:innermethod(I)Z]"); }
/** * test level 2 context masked by an abtract class */ @Test public void test2levelContext() { String context2 = DependencyAnalysis .getCallGraph() .getAllContextsFromTargetClass( "com.examples.with.different.packagename.context.complex.SubClass", "bla(I)Z").toString(); assertEquals( context2, "[com.examples.with.different.packagename.context.complex.EntryPointsClass:dosmt(ILjava/lang/String;D)V com.examples.with.different.packagename.context.complex.SubClass:checkFiftneen(I)Z com.examples.with.different.packagename.context.complex.SubClass:bla(I)Z]"); }
DependencyAnalysis.getInheritanceTree()); testClusterGenerator.generateCluster(DependencyAnalysis.getCallGraph()); } catch (RuntimeException e) { logger.error(e.getMessage(), e);