use of org.evosuite.utils.generic.GenericMethod in project evosuite by EvoSuite.
the class InsertionMutationSystemTest method getIntTest.
private TestCase getIntTest(int x) throws NoSuchMethodException, SecurityException, ConstructionFailedException, ClassNotFoundException {
Class<?> sut = TestGenerationContext.getInstance().getClassLoaderForSUT().loadClass(Properties.TARGET_CLASS);
GenericClass clazz = new GenericClass(sut);
DefaultTestCase test = new DefaultTestCase();
GenericConstructor gc = new GenericConstructor(clazz.getRawClass().getConstructors()[0], clazz);
TestFactory testFactory = TestFactory.getInstance();
VariableReference callee = testFactory.addConstructor(test, gc, 0, 0);
VariableReference intVar = test.addStatement(new IntPrimitiveStatement(test, x));
Method m = clazz.getRawClass().getMethod("testMe", new Class<?>[] { int.class });
GenericMethod method = new GenericMethod(m, sut);
MethodStatement ms = new MethodStatement(test, method, callee, Arrays.asList(new VariableReference[] { intVar }));
test.addStatement(ms);
return test;
}
use of org.evosuite.utils.generic.GenericMethod in project evosuite by EvoSuite.
the class InsertionMutationSystemTest method getTwoIntTest.
private TestCase getTwoIntTest(int x, int y) throws NoSuchMethodException, SecurityException, ConstructionFailedException, ClassNotFoundException {
Class<?> sut = TestGenerationContext.getInstance().getClassLoaderForSUT().loadClass(Properties.TARGET_CLASS);
GenericClass clazz = new GenericClass(sut);
DefaultTestCase test = new DefaultTestCase();
GenericConstructor gc = new GenericConstructor(clazz.getRawClass().getConstructors()[0], clazz);
TestFactory testFactory = TestFactory.getInstance();
VariableReference callee = testFactory.addConstructor(test, gc, 0, 0);
VariableReference intVar1 = test.addStatement(new IntPrimitiveStatement(test, x));
VariableReference intVar2 = test.addStatement(new IntPrimitiveStatement(test, y));
Method m = clazz.getRawClass().getMethod("testMe", new Class<?>[] { int.class, int.class });
GenericMethod method = new GenericMethod(m, sut);
MethodStatement ms = new MethodStatement(test, method, callee, Arrays.asList(new VariableReference[] { intVar1, intVar2 }));
test.addStatement(ms);
return test;
}
use of org.evosuite.utils.generic.GenericMethod in project evosuite by EvoSuite.
the class TestConstantInliner method testStringQuoting.
@Test
public void testStringQuoting() throws NoSuchMethodException, SecurityException {
DefaultTestCase test = new DefaultTestCase();
ConstructorStatement cs = new ConstructorStatement(test, new GenericConstructor(StringConstantInliningExample.class.getConstructor(), StringConstantInliningExample.class), new ArrayList<VariableReference>());
VariableReference objectVar = test.addStatement(cs);
StringPrimitiveStatement stringStatement = new StringPrimitiveStatement(test, "EXAMPLE");
VariableReference stringParam = test.addStatement(stringStatement);
List<VariableReference> parameters = new ArrayList<VariableReference>();
parameters.add(stringParam);
test.addStatement(new MethodStatement(test, new GenericMethod(StringConstantInliningExample.class.getMethods()[0], StringConstantInliningExample.class), objectVar, parameters));
System.out.println(test.toCode());
ConstantInliner inliner = new ConstantInliner();
inliner.inline(test);
String code = test.toCode();
System.out.println(code);
assertFalse(code.contains("foo(EXAMPLE)"));
assertTrue(code.contains("foo(\"EXAMPLE\")"));
}
use of org.evosuite.utils.generic.GenericMethod in project evosuite by EvoSuite.
the class TestCluster method getKey.
private String getKey(GenericAccessibleObject<?> call) {
String name = call.getDeclaringClass().getCanonicalName();
if (call.isMethod()) {
GenericMethod method = (GenericMethod) call;
name += method.getNameWithDescriptor();
} else if (call.isConstructor()) {
GenericConstructor constructor = (GenericConstructor) call;
name += constructor.getNameWithDescriptor();
} else {
throw new RuntimeException("Coverage goals must be methods or constructors");
}
return name;
}
use of org.evosuite.utils.generic.GenericMethod in project evosuite by EvoSuite.
the class TestCaseBuilder method appendMethod.
/**
* @param callee
* <code>null</code> for state methods
* @param method
* @param parameters
* @return <code>void reference</code> for void methods
*/
public VariableReference appendMethod(VariableReference callee, Method method, VariableReference... parameters) {
List<VariableReference> parameter_list = Arrays.asList(parameters);
MethodStatement methodStmt = null;
if (callee == null) {
methodStmt = new MethodStatement(tc, new GenericMethod(method, method.getDeclaringClass()), callee, parameter_list);
} else {
methodStmt = new MethodStatement(tc, new GenericMethod(method, callee.getType()), callee, parameter_list);
}
tc.addStatement(methodStmt);
return methodStmt.getReturnValue();
}
Aggregations