use of org.evosuite.utils.generic.GenericMethod in project evosuite by EvoSuite.
the class EvoTestCaseCodeGenerator method createUnobservedInitStmt.
@SuppressWarnings({ "rawtypes" })
@Override
public void createUnobservedInitStmt(CaptureLog log, int logRecNo) {
// NOTE: PLAIN INIT: has always one non-null param
// TODO: use primitives
final int oid = log.objectIds.get(logRecNo);
try {
final Object value = log.params.get(logRecNo)[0];
final PrimitiveStatement stringRep = new ImmutableStringPrimitiveStatement(testCase, (String) value);
final VariableReference stringRepRef = testCase.addStatement(stringRep);
final MethodStatement m = new MethodStatement(testCase, new GenericMethod(EvoSuiteXStream.class.getMethod("fromString", new Class<?>[] { String.class }), EvoSuiteXStream.class), null, Arrays.asList(stringRepRef));
this.oidToVarRefMap.put(oid, testCase.addStatement(m));
} catch (final Exception e) {
throw new RuntimeException(e);
}
}
use of org.evosuite.utils.generic.GenericMethod in project evosuite by EvoSuite.
the class ConstraintHelper method countNumberOfMethodCalls.
/**
* This ignores the input parameters
*
* @param test
* @param klass
* @param methodName
* @return
* @throws IllegalArgumentException
*/
public static int countNumberOfMethodCalls(TestCase test, Class<?> klass, String methodName) throws IllegalArgumentException {
Inputs.checkNull(test, klass);
int counter = 0;
for (int i = 0; i < test.size(); i++) {
Statement st = test.getStatement(i);
if (st instanceof MethodStatement) {
MethodStatement ms = (MethodStatement) st;
GenericMethod gm = ms.getMethod();
if (gm.getDeclaringClass().equals(klass) && gm.getName().equals(methodName)) {
counter++;
}
}
}
return counter;
}
use of org.evosuite.utils.generic.GenericMethod in project evosuite by EvoSuite.
the class ConstraintHelper method getLastPositionOfMethodCall.
/**
* @param test
* @param className
* @param methodName
* @return a negative value if it is not present
*/
public static int getLastPositionOfMethodCall(TestCase test, String className, String methodName, int lastPosition) {
Inputs.checkNull(test, className, methodName);
int pos = -1;
for (int i = 0; i < lastPosition; i++) {
Statement st = test.getStatement(i);
if (st instanceof MethodStatement) {
MethodStatement ms = (MethodStatement) st;
GenericMethod gm = ms.getMethod();
if (gm.getDeclaringClass().getCanonicalName().equals(className) && gm.getName().equals(methodName)) {
pos = i;
}
}
}
return pos;
}
use of org.evosuite.utils.generic.GenericMethod in project evosuite by EvoSuite.
the class ChangeMutationSystemTest 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 ChangeMutationSystemTest 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;
}
Aggregations