use of org.evosuite.testcase.variable.VariableReferenceImpl in project evosuite by EvoSuite.
the class FunctionalMockStatementTest method testBase.
@Test
public void testBase() throws Exception {
TestCase tc = new DefaultTestCase();
final int MOCKED_VALUE = 42;
VariableReference mockedInput = tc.addStatement(new IntPrimitiveStatement(tc, MOCKED_VALUE));
VariableReference ref = new VariableReferenceImpl(tc, Foo.class);
FunctionalMockStatement mockStmt = new FunctionalMockStatement(tc, ref, Foo.class);
VariableReference mock = tc.addStatement(mockStmt);
VariableReference result = tc.addStatement(new MethodStatement(tc, new GenericMethod(this.getClass().getDeclaredMethod("base", Foo.class), FunctionalMockStatementTest.class), null, Arrays.asList(mock)));
// if not executed, should be no way to tell if needs new inputs
Assert.assertFalse(mockStmt.doesNeedToUpdateInputs());
Assert.assertEquals(0, mockStmt.getNumParameters());
// execute first time with default mock
Scope scope = execute(tc);
Integer val = (Integer) scope.getObject(result);
// default mock value should be 0
Assert.assertEquals(0, val.intValue());
// after execution, there should be one variable to provide
Assert.assertTrue(mockStmt.doesNeedToUpdateInputs());
List<Type> types = mockStmt.updateMockedMethods();
Assert.assertEquals(1, types.size());
Assert.assertEquals(int.class, types.get(0));
// add int variable to list of mock expected returns
mockStmt.addMissingInputs(Arrays.asList(mockedInput));
Assert.assertEquals(1, mockStmt.getNumParameters());
Assert.assertTrue(mockStmt.getParameterReferences().get(0).same(mockedInput));
// re-execute with initialized mock
scope = new Scope();
for (Statement st : tc) {
st.execute(scope, System.out);
}
val = (Integer) scope.getObject(result);
Assert.assertEquals(MOCKED_VALUE, val.intValue());
}
use of org.evosuite.testcase.variable.VariableReferenceImpl in project evosuite by EvoSuite.
the class FunctionalMockStatementTest method testPackageLevel_local.
@Test
public void testPackageLevel_local() throws Exception {
TestCase tc = new DefaultTestCase();
VariableReference ref = new VariableReferenceImpl(tc, PackageLevel.class);
try {
FunctionalMockStatement mockStmt = new FunctionalMockStatement(tc, ref, PackageLevel.class);
fail();
} catch (java.lang.IllegalArgumentException e) {
// expected
}
// tc.addStatement(mockStmt);
// execute(tc);
}
use of org.evosuite.testcase.variable.VariableReferenceImpl in project evosuite by EvoSuite.
the class FunctionalMockStatementTest method testPackageLevel_differentPackage.
@Test
public void testPackageLevel_differentPackage() throws Exception {
TestCase tc = new DefaultTestCase();
Class<?> example = Class.forName("com.examples.with.different.packagename.fm.ExamplePackageLevel");
VariableReference ref = new VariableReferenceImpl(tc, example);
try {
FunctionalMockStatement mockStmt = new FunctionalMockStatement(tc, ref, example);
fail();
} catch (java.lang.IllegalArgumentException e) {
// expected
}
// tc.addStatement(mockStmt);
// execute(tc);
}
use of org.evosuite.testcase.variable.VariableReferenceImpl in project evosuite by EvoSuite.
the class FunctionalMockStatementTest method testPackageLevel_differentPackage_nonInstrumentation_package.
@Test
public void testPackageLevel_differentPackage_nonInstrumentation_package() throws Exception {
TestCase tc = new DefaultTestCase();
ClassPathHandler.getInstance().changeTargetCPtoTheSameAsEvoSuite();
NonInstrumentingClassLoader loader = new NonInstrumentingClassLoader();
Class<?> example = loader.loadClass("com.examples.with.different.packagename.fm.ExamplePackageLevel");
VariableReference ref = new VariableReferenceImpl(tc, example);
try {
FunctionalMockStatement mockStmt = new FunctionalMockStatement(tc, ref, example);
fail();
} catch (java.lang.IllegalArgumentException e) {
// expected
}
// tc.addStatement(mockStmt);
// execute(tc);
}
use of org.evosuite.testcase.variable.VariableReferenceImpl in project evosuite by EvoSuite.
the class TestOverloading method testNotOverloadedMethod.
@Test
public void testNotOverloadedMethod() {
Class<?> clazz = ClassWithoutOverloadedMethods.class;
Method method1 = clazz.getMethods()[0];
Method method2 = clazz.getMethods()[1];
GenericMethod genericMethod1 = new GenericMethod(method1, clazz);
GenericMethod genericMethod2 = new GenericMethod(method2, clazz);
TestCase test = new DefaultTestCase();
ConstantValue intValue = new ConstantValue(test, int.class);
VariableReference stringVar = new VariableReferenceImpl(test, String.class);
List<VariableReference> parameters1 = Arrays.asList(intValue);
List<VariableReference> parameters2 = Arrays.asList(stringVar);
assertFalse(genericMethod1.isOverloaded());
assertFalse(genericMethod2.isOverloaded());
assertFalse(genericMethod1.isOverloaded(parameters1));
assertFalse(genericMethod2.isOverloaded(parameters1));
assertFalse(genericMethod1.isOverloaded(parameters2));
assertFalse(genericMethod2.isOverloaded(parameters2));
}
Aggregations