private String getMethodName(F target) { return target.getTargetMethod(); }
/** * Determine the set of methods this test case is exercising * * @return */ public Set<String> getTargetMethods() { Set<String> targetMethods = new HashSet<String>(); for (TestFitnessFunction goal : primaryTargets) { targetMethods.add(goal.getTargetMethod()); } return targetMethods; }
/** * Determine if we have overloaded methods, which requires the use of signatures * * @param testToGoals */ private void initializeMethodCoverageCount(Map<TestCase, Set<TestFitnessFunction>> testToGoals) { for(Set<TestFitnessFunction> goals : testToGoals.values()) { for(TestFitnessFunction goal : goals) { String methodName = getMethodNameWithoutDescriptor(goal.getTargetMethod()); if(!methodCount.containsKey(methodName)) { methodCount.put(methodName, new LinkedHashSet<>()); } methodCount.get(methodName).add(goal.getTargetMethod()); } } }
if(methodToPosition.containsKey(goal.getTargetMethod())) { int position = methodToPosition.get(goal.getTargetMethod()); if(position >= chosenPosition) { chosenPosition = position;
/** * Some goals require special treatment when combining two * @param goal1 * @param goal2 * @return */ private String getGoalPairName(TestFitnessFunction goal1, TestFitnessFunction goal2) { if(goal1.getClass().equals(goal2.getClass())) { if(goal1 instanceof MethodCoverageTestFitness) { return getGoalPairName((MethodCoverageTestFitness) goal1, (MethodCoverageTestFitness) goal2); } if(goal1.getTargetClass().equals(goal2.getTargetClass()) && goal1.getTargetMethod().equals(goal2.getTargetMethod())) { if (goal1 instanceof InputCoverageTestFitness) { return getGoalPairName((InputCoverageTestFitness) goal1, (InputCoverageTestFitness) goal2); } else if (goal1 instanceof OutputCoverageTestFitness) { return getGoalPairName((OutputCoverageTestFitness) goal1, (OutputCoverageTestFitness) goal2); } } } return getGoalName(goal1) + STR_AND + getGoalName(goal2); }
/** * Helper function to redirect name retrieval to the right method * * @param goal * @return */ private String getGoalName(TestFitnessFunction goal) { if(goal instanceof MethodCoverageTestFitness) { return getGoalName((MethodCoverageTestFitness)goal); } else if(goal instanceof MethodCoverageTestFitness) { return getGoalName((MethodCoverageTestFitness)goal); } else if(goal instanceof MethodNoExceptionCoverageTestFitness) { return getGoalName((MethodNoExceptionCoverageTestFitness)goal); } else if(goal instanceof ExceptionCoverageTestFitness) { return getGoalName((ExceptionCoverageTestFitness)goal); } else if(goal instanceof InputCoverageTestFitness) { return getGoalName((InputCoverageTestFitness)goal); } else if(goal instanceof OutputCoverageTestFitness) { return getGoalName((OutputCoverageTestFitness)goal); } else { return formatMethodName(goal.getTargetClass(), goal.getTargetMethod()); // throw new RuntimeException("Not implemented yet: "+goal.getClass()); } }