Search in sources :

Example 51 with MethodStatement

use of org.evosuite.testcase.statements.MethodStatement in project evosuite by EvoSuite.

the class FactoryTestSystemTest method testGetCandidatesForReuse.

@Test
public void testGetCandidatesForReuse() throws ClassNotFoundException, NoSuchFieldException, ConstructionFailedException, NoSuchMethodException {
    TestFactory testFactory = TestFactory.getInstance();
    Class<?> sut = TestGenerationContext.getInstance().getClassLoaderForSUT().loadClass(FactoryExample.class.getCanonicalName());
    Properties.PRIMITIVE_REUSE_PROBABILITY = 1.0;
    Properties.OBJECT_REUSE_PROBABILITY = 1.0;
    DefaultTestCase test = new DefaultTestCase();
    GenericConstructor constructor = new GenericConstructor(sut.getConstructor(), sut);
    VariableReference var1 = testFactory.addConstructor(test, constructor, 0, 0);
    test.addStatement(new CharPrimitiveStatement(test, '-'));
    GenericMethod method = new GenericMethod(sut.getMethod("testInt", int.class), sut);
    testFactory.addMethodFor(test, var1, method, 2);
    MethodStatement stmt = (MethodStatement) test.getStatement(test.size() - 1);
    VariableReference var = stmt.getParameterReferences().get(0);
    assertNotEquals("Char should not be passed as Integer", var.getType(), char.class);
    assertEquals("Incorrect test size", 4, test.size());
}
Also used : MethodStatement(org.evosuite.testcase.statements.MethodStatement) VariableReference(org.evosuite.testcase.variable.VariableReference) GenericConstructor(org.evosuite.utils.generic.GenericConstructor) FactoryExample(com.examples.with.different.packagename.FactoryExample) GenericMethod(org.evosuite.utils.generic.GenericMethod) CharPrimitiveStatement(org.evosuite.testcase.statements.numeric.CharPrimitiveStatement) Test(org.junit.Test)

Example 52 with MethodStatement

use of org.evosuite.testcase.statements.MethodStatement in project evosuite by EvoSuite.

the class LocalSearchNumericSystemTest method getFloatTest.

private TestCase getFloatTest(float x, float 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 FloatPrimitiveStatement(test, x));
    VariableReference intVar0 = test.addStatement(new FloatPrimitiveStatement(test, y));
    Method m = clazz.getRawClass().getMethod("testMe", new Class<?>[] { float.class, float.class });
    GenericMethod method = new GenericMethod(m, sut);
    MethodStatement ms = new MethodStatement(test, method, callee, Arrays.asList(new VariableReference[] { intVar0, intVar1 }));
    test.addStatement(ms);
    return test;
}
Also used : MethodStatement(org.evosuite.testcase.statements.MethodStatement) VariableReference(org.evosuite.testcase.variable.VariableReference) FloatPrimitiveStatement(org.evosuite.testcase.statements.numeric.FloatPrimitiveStatement) GenericClass(org.evosuite.utils.generic.GenericClass) TestFactory(org.evosuite.testcase.TestFactory) GenericConstructor(org.evosuite.utils.generic.GenericConstructor) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) GenericMethod(org.evosuite.utils.generic.GenericMethod) Method(java.lang.reflect.Method) GenericMethod(org.evosuite.utils.generic.GenericMethod)

Example 53 with MethodStatement

use of org.evosuite.testcase.statements.MethodStatement in project evosuite by EvoSuite.

the class LocalSearchNumericSystemTest method getIntTest.

private TestCase getIntTest(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 intVar0 = 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[] { intVar0, intVar1 }));
    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) TestFactory(org.evosuite.testcase.TestFactory) GenericConstructor(org.evosuite.utils.generic.GenericConstructor) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) 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 54 with MethodStatement

use of org.evosuite.testcase.statements.MethodStatement in project evosuite by EvoSuite.

the class LocalSearchNumericSystemTest method getDoubleTest.

private TestCase getDoubleTest(double x, double 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 DoublePrimitiveStatement(test, x));
    VariableReference intVar0 = test.addStatement(new DoublePrimitiveStatement(test, y));
    Method m = clazz.getRawClass().getMethod("testMe", new Class<?>[] { double.class, double.class });
    GenericMethod method = new GenericMethod(m, sut);
    MethodStatement ms = new MethodStatement(test, method, callee, Arrays.asList(new VariableReference[] { intVar0, intVar1 }));
    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) TestFactory(org.evosuite.testcase.TestFactory) GenericConstructor(org.evosuite.utils.generic.GenericConstructor) DoublePrimitiveStatement(org.evosuite.testcase.statements.numeric.DoublePrimitiveStatement) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) GenericMethod(org.evosuite.utils.generic.GenericMethod) Method(java.lang.reflect.Method) GenericMethod(org.evosuite.utils.generic.GenericMethod)

Aggregations

MethodStatement (org.evosuite.testcase.statements.MethodStatement)54 VariableReference (org.evosuite.testcase.variable.VariableReference)40 GenericMethod (org.evosuite.utils.generic.GenericMethod)29 Method (java.lang.reflect.Method)25 ConstructorStatement (org.evosuite.testcase.statements.ConstructorStatement)22 GenericConstructor (org.evosuite.utils.generic.GenericConstructor)22 Statement (org.evosuite.testcase.statements.Statement)19 GenericClass (org.evosuite.utils.generic.GenericClass)15 DefaultTestCase (org.evosuite.testcase.DefaultTestCase)11 IntPrimitiveStatement (org.evosuite.testcase.statements.numeric.IntPrimitiveStatement)10 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)8 TestCase (org.evosuite.testcase.TestCase)7 CodeUnderTestException (org.evosuite.testcase.execution.CodeUnderTestException)5 FieldStatement (org.evosuite.testcase.statements.FieldStatement)5 StringPrimitiveStatement (org.evosuite.testcase.statements.StringPrimitiveStatement)5 HashSet (java.util.HashSet)4 TestFactory (org.evosuite.testcase.TestFactory)4 AssignmentStatement (org.evosuite.testcase.statements.AssignmentStatement)4 PrimitiveStatement (org.evosuite.testcase.statements.PrimitiveStatement)4