@Test public void testWithRegularClass() throws NoSuchMethodException { Class cls[] = new Class[] { int.class }; Constructor constructor = Integer.class.getConstructor(cls); List<Constructor> constructorsList = new ArrayList<>(); constructorsList.add(constructor); Mockito.when(utility.getStackTraceConstructors()).thenReturn(constructorsList); Method method1 = Integer.class.getMethod("equals",Object.class); List<Method> methods = new ArrayList<>(); methods.add(method1); Mockito.when(utility.getStackTraceMethods()).thenReturn(methods); List<InputCoverageTestFitness> goals = inputCoverageFactory.getCoverageGoals(); assert(goals.size() == 6); int initCount = 0; int equalCount = 0; for (InputCoverageTestFitness goal : goals){ if(goal.getMethod().contains("<init>")){ initCount++; }else if(goal.getMethod().contains("equals")){ equalCount++; } } assert (initCount == 3); assert (equalCount == 3); }
@Override public List<InputCoverageTestFitness> getCoverageGoals() { List<InputCoverageTestFitness> goals = new ArrayList<>(); List<Method> stackTraceMethods = utility.getStackTraceMethods(); List<Constructor> stackTraceConstructors = utility.getStackTraceConstructors(); for(Constructor constructor: stackTraceConstructors){ String className = constructor.getDeclaringClass().getName(); String methodName = "<init>"+Type.getConstructorDescriptor(constructor); Type[] argumentTypes = utility.getConstructorArgumentTypes(constructor); Class<?>[] argumentClasses = constructor.getParameterTypes(); LOG.info("Adding input goals for constructor " + className + "." + methodName); detectGoals(className,methodName,argumentClasses,argumentTypes,goals); } for(Method method: stackTraceMethods){ String className = method.getDeclaringClass().getName(); String methodName = method.getName()+Type.getMethodDescriptor(method); Type[] argumentTypes = Type.getArgumentTypes(method); Class<?>[] argumentClasses = method.getParameterTypes(); LOG.info("Adding input goals for method " + className + "." + methodName); detectGoals(className,methodName,argumentClasses,argumentTypes,goals); } return goals; }
InputCoverageFactory extends org.evosuite.coverage.io.input.InputCoverageFactory { @Override public List<InputCoverageTestFitness> getCoverageGoals() { List<InputCoverageTestFitness> goals = new ArrayList<>(); List<Method> stackTraceMethods = utility.getStackTraceMethods(); List<Constructor> stackTraceConstructors = utility.getStackTraceConstructors(); for(Constructor constructor: stackTraceConstructors){ String className = constructor.getDeclaringClass().getName(); String methodName = "<init>"+Type.getConstructorDescriptor(constructor); Type[] argumentTypes = utility.getConstructorArgumentTypes(constructor); Class<?>[] argumentClasses = constructor.getParameterTypes(); LOG.info("Adding input goals for constructor " + className + "." + methodName); detectGoals(className,methodName,argumentClasses,argumentTypes,goals); } for(Method method: stackTraceMethods){ String className = method.getDeclaringClass().getName(); String methodName = method.getName()+Type.getMethodDescriptor(method); Type[] argumentTypes = Type.getArgumentTypes(method); Class<?>[] argumentClasses = method.getParameterTypes(); LOG.info("Adding input goals for method " + className + "." + methodName); detectGoals(className,methodName,argumentClasses,argumentTypes,goals); } return goals; } }
InputCoverageFactory extends org.evosuite.coverage.io.input.InputCoverageFactory { @Override public List<InputCoverageTestFitness> getCoverageGoals() { List<InputCoverageTestFitness> goals = new ArrayList<>(); List<Method> stackTraceMethods = utility.getStackTraceMethods(); List<Constructor> stackTraceConstructors = utility.getStackTraceConstructors(); for(Constructor constructor: stackTraceConstructors){ String className = constructor.getDeclaringClass().getName(); String methodName = "<init>"+Type.getConstructorDescriptor(constructor); Type[] argumentTypes = utility.getConstructorArgumentTypes(constructor); Class<?>[] argumentClasses = constructor.getParameterTypes(); LOG.info("Adding input goals for constructor " + className + "." + methodName); detectGoals(className,methodName,argumentClasses,argumentTypes,goals); } for(Method method: stackTraceMethods){ String className = method.getDeclaringClass().getName(); String methodName = method.getName()+Type.getMethodDescriptor(method); Type[] argumentTypes = Type.getArgumentTypes(method); Class<?>[] argumentClasses = method.getParameterTypes(); LOG.info("Adding input goals for method " + className + "." + methodName); detectGoals(className,methodName,argumentClasses,argumentTypes,goals); } return goals; }  }
InputCoverageFactory extends org.evosuite.coverage.io.input.InputCoverageFactory { @Override public List<InputCoverageTestFitness> getCoverageGoals() { List<InputCoverageTestFitness> goals = new ArrayList<>(); List<Method> stackTraceMethods = utility.getStackTraceMethods(); List<Constructor> stackTraceConstructors = utility.getStackTraceConstructors(); for(Constructor constructor: stackTraceConstructors){ String className = constructor.getDeclaringClass().getName(); String methodName = "<init>"+Type.getConstructorDescriptor(constructor); Type[] argumentTypes = utility.getConstructorArgumentTypes(constructor); Class<?>[] argumentClasses = constructor.getParameterTypes(); LOG.info("Adding input goals for constructor " + className + "." + methodName); detectGoals(className,methodName,argumentClasses,argumentTypes,goals); } for(Method method: stackTraceMethods){ String className = method.getDeclaringClass().getName(); String methodName = method.getName()+Type.getMethodDescriptor(method); Type[] argumentTypes = Type.getArgumentTypes(method); Class<?>[] argumentClasses = method.getParameterTypes(); LOG.info("Adding input goals for method " + className + "." + methodName); detectGoals(className,methodName,argumentClasses,argumentTypes,goals); } return goals; }  @Override List<InputCoverageTestFitness> getCoverageGoals(); }
InputCoverageFactory extends org.evosuite.coverage.io.input.InputCoverageFactory { @Override public List<InputCoverageTestFitness> getCoverageGoals() { List<InputCoverageTestFitness> goals = new ArrayList<>(); List<Method> stackTraceMethods = utility.getStackTraceMethods(); List<Constructor> stackTraceConstructors = utility.getStackTraceConstructors(); for(Constructor constructor: stackTraceConstructors){ String className = constructor.getDeclaringClass().getName(); String methodName = "<init>"+Type.getConstructorDescriptor(constructor); Type[] argumentTypes = utility.getConstructorArgumentTypes(constructor); Class<?>[] argumentClasses = constructor.getParameterTypes(); LOG.info("Adding input goals for constructor " + className + "." + methodName); detectGoals(className,methodName,argumentClasses,argumentTypes,goals); } for(Method method: stackTraceMethods){ String className = method.getDeclaringClass().getName(); String methodName = method.getName()+Type.getMethodDescriptor(method); Type[] argumentTypes = Type.getArgumentTypes(method); Class<?>[] argumentClasses = method.getParameterTypes(); LOG.info("Adding input goals for method " + className + "." + methodName); detectGoals(className,methodName,argumentClasses,argumentTypes,goals); } return goals; }  @Override List<InputCoverageTestFitness> getCoverageGoals();  }