Search in sources :

Example 56 with GenericMethod

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;
}
Also used : MethodStatement(org.evosuite.testcase.statements.MethodStatement) VariableReference(org.evosuite.testcase.variable.VariableReference) GenericClass(org.evosuite.utils.generic.GenericClass) GenericConstructor(org.evosuite.utils.generic.GenericConstructor) GenericMethod(org.evosuite.utils.generic.GenericMethod) Method(java.lang.reflect.Method) GenericMethod(org.evosuite.utils.generic.GenericMethod) IntPrimitiveStatement(org.evosuite.testcase.statements.numeric.IntPrimitiveStatement)

Example 57 with GenericMethod

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;
}
Also used : MethodStatement(org.evosuite.testcase.statements.MethodStatement) VariableReference(org.evosuite.testcase.variable.VariableReference) GenericClass(org.evosuite.utils.generic.GenericClass) GenericConstructor(org.evosuite.utils.generic.GenericConstructor) GenericMethod(org.evosuite.utils.generic.GenericMethod) Method(java.lang.reflect.Method) GenericMethod(org.evosuite.utils.generic.GenericMethod) IntPrimitiveStatement(org.evosuite.testcase.statements.numeric.IntPrimitiveStatement)

Example 58 with GenericMethod

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\")"));
}
Also used : VariableReference(org.evosuite.testcase.variable.VariableReference) ArrayList(java.util.ArrayList) GenericConstructor(org.evosuite.utils.generic.GenericConstructor) StringConstantInliningExample(com.examples.with.different.packagename.StringConstantInliningExample) GenericMethod(org.evosuite.utils.generic.GenericMethod) Test(org.junit.Test)

Example 59 with GenericMethod

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;
}
Also used : GenericConstructor(org.evosuite.utils.generic.GenericConstructor) GenericMethod(org.evosuite.utils.generic.GenericMethod)

Example 60 with GenericMethod

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();
}
Also used : MethodStatement(org.evosuite.testcase.statements.MethodStatement) VariableReference(org.evosuite.testcase.variable.VariableReference) GenericMethod(org.evosuite.utils.generic.GenericMethod)

Aggregations

GenericMethod (org.evosuite.utils.generic.GenericMethod)110 Test (org.junit.Test)68 VariableReference (org.evosuite.testcase.variable.VariableReference)64 GenericConstructor (org.evosuite.utils.generic.GenericConstructor)60 Method (java.lang.reflect.Method)57 GenericClass (org.evosuite.utils.generic.GenericClass)40 MethodStatement (org.evosuite.testcase.statements.MethodStatement)29 IntPrimitiveStatement (org.evosuite.testcase.statements.numeric.IntPrimitiveStatement)19 ArrayList (java.util.ArrayList)18 DefaultTestCase (org.evosuite.testcase.DefaultTestCase)17 ConstructorStatement (org.evosuite.testcase.statements.ConstructorStatement)15 TestCase (org.evosuite.testcase.TestCase)12 BranchCoverageSuiteFitness (org.evosuite.coverage.branch.BranchCoverageSuiteFitness)11 Injector (org.evosuite.runtime.javaee.injection.Injector)10 Type (java.lang.reflect.Type)9 ConstructionFailedException (org.evosuite.ga.ConstructionFailedException)8 EvoServletState (org.evosuite.runtime.javaee.javax.servlet.EvoServletState)8 GenericAccessibleObject (org.evosuite.utils.generic.GenericAccessibleObject)8 GenericField (org.evosuite.utils.generic.GenericField)8 TestSuiteChromosome (org.evosuite.testsuite.TestSuiteChromosome)7