use of org.evosuite.utils.generic.GenericConstructor 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.GenericConstructor 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.GenericConstructor 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.GenericConstructor 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.GenericConstructor in project evosuite by EvoSuite.
the class TestCluster method addNumericConstructor.
/**
* FIXME: This is a workaround for a bug where Integer is not contained in
* the generatorCache, but there is a key. No idea how it comes to place
*
* @param clazz
*/
private void addNumericConstructor(GenericClass clazz) {
if (!generatorCache.containsKey(clazz)) {
generatorCache.put(clazz, new LinkedHashSet<GenericAccessibleObject<?>>());
}
if (!generators.containsKey(clazz)) {
generators.put(clazz, new LinkedHashSet<GenericAccessibleObject<?>>());
}
logger.info("addNumericConstructor for class " + clazz);
for (Constructor<?> constructor : clazz.getRawClass().getConstructors()) {
if (constructor.getParameterTypes().length == 1) {
Class<?> parameterClass = constructor.getParameterTypes()[0];
if (!parameterClass.equals(String.class)) {
GenericConstructor genericConstructor = new GenericConstructor(constructor, clazz);
generatorCache.get(clazz).add(genericConstructor);
generators.get(clazz).add(genericConstructor);
}
}
}
logger.info("Constructors for class " + clazz + ": " + generators.get(clazz).size());
}
Aggregations