use of org.evosuite.utils.generic.GenericConstructor in project evosuite by EvoSuite.
the class ConstraintVerifierTest method testInitializingBoundedVariable_correct.
@Test
public void testInitializingBoundedVariable_correct() throws Exception {
TestChromosome tc = new TestChromosome();
TestFactory factory = TestFactory.getInstance();
VariableReference servlet = factory.addConstructor(tc.getTestCase(), new GenericConstructor(FakeServlet.class.getDeclaredConstructor(), FakeServlet.class), 0, 0);
// initializing bounding variable method called directly after the new
factory.addMethod(tc.getTestCase(), new GenericMethod(Injector.class.getDeclaredMethod("executePostConstruct", Object.class), Injector.class), 1, 0);
// method on servlet after the bounding variable initialization: it is ok
factory.addMethodFor(tc.getTestCase(), servlet, new GenericMethod(FakeServlet.class.getDeclaredMethod("foo"), FakeServlet.class), 2);
Assert.assertEquals(3, tc.size());
Assert.assertTrue(ConstraintVerifier.verifyTest(tc));
}
use of org.evosuite.utils.generic.GenericConstructor in project evosuite by EvoSuite.
the class ConstraintVerifierTest method testInitializingBoundedVariable_correct_severalCalls.
@Test
public void testInitializingBoundedVariable_correct_severalCalls() throws Exception {
TestChromosome tc = new TestChromosome();
TestFactory factory = TestFactory.getInstance();
VariableReference servlet = factory.addConstructor(tc.getTestCase(), new GenericConstructor(FakeServlet.class.getDeclaredConstructor(), FakeServlet.class), 0, 0);
// both calls on same bounding variable
factory.addMethod(tc.getTestCase(), new GenericMethod(ConstraintVerifierTest.class.getDeclaredMethod("fakeInjection", Servlet.class), ConstraintVerifierTest.class), 1, 0);
// this is an atMostOnce type
factory.addMethod(tc.getTestCase(), new GenericMethod(Injector.class.getDeclaredMethod("executePostConstruct", Object.class), Injector.class), 2, 0);
Assert.assertEquals(3, tc.size());
Assert.assertTrue(ConstraintVerifier.verifyTest(tc));
}
use of org.evosuite.utils.generic.GenericConstructor in project evosuite by EvoSuite.
the class ConstraintVerifierTest method testInitializingBoundedVariable_wrong_atMostOnce.
@Test
public void testInitializingBoundedVariable_wrong_atMostOnce() throws Exception {
TestChromosome tc = new TestChromosome();
TestFactory factory = TestFactory.getInstance();
VariableReference servlet = factory.addConstructor(tc.getTestCase(), new GenericConstructor(FakeServlet.class.getDeclaredConstructor(), FakeServlet.class), 0, 0);
// initializing bounding variable method called directly after the new
factory.addMethod(tc.getTestCase(), new GenericMethod(Injector.class.getDeclaredMethod("executePostConstruct", Object.class), Injector.class), 1, 0);
Assert.assertEquals(2, tc.size());
Assert.assertTrue(ConstraintVerifier.verifyTest(tc));
// this should be invalid, as executePostConstruct can be used only once on same bounded variable
factory.addMethod(tc.getTestCase(), new GenericMethod(Injector.class.getDeclaredMethod("executePostConstruct", Object.class), Injector.class), 2, 0);
Assert.assertEquals(3, tc.size());
Assert.assertFalse(ConstraintVerifier.verifyTest(tc));
}
use of org.evosuite.utils.generic.GenericConstructor in project evosuite by EvoSuite.
the class ConstraintVerifierTest method testNoNullInputs_notNull.
@Test
public void testNoNullInputs_notNull() throws Exception {
TestChromosome tc = new TestChromosome();
TestFactory factory = TestFactory.getInstance();
VariableReference servlet = factory.addConstructor(tc.getTestCase(), new GenericConstructor(FakeServlet.class.getDeclaredConstructor(), FakeServlet.class), 0, 0);
factory.addMethod(tc.getTestCase(), new GenericMethod(EvoServletState.class.getDeclaredMethod("initServlet", Servlet.class), EvoServletState.class), 1, 0);
StringPrimitiveStatement foo = new StringPrimitiveStatement(tc.getTestCase(), "foo");
tc.getTestCase().addStatement(foo);
VariableReference con = factory.addMethod(tc.getTestCase(), new GenericMethod(EvoServletState.class.getDeclaredMethod("getConfiguration"), EvoServletState.class), 3, 0);
factory.addMethodFor(tc.getTestCase(), con, new GenericMethod(EvoServletConfig.class.getDeclaredMethod("createDispatcher", String.class), EvoServletConfig.class), 4);
Assert.assertEquals(5, tc.size());
Assert.assertTrue(ConstraintVerifier.verifyTest(tc));
}
use of org.evosuite.utils.generic.GenericConstructor in project evosuite by EvoSuite.
the class ConstraintVerifierTest method testNoNullInputs_nullString.
@Test
public void testNoNullInputs_nullString() throws Exception {
TestChromosome tc = new TestChromosome();
TestFactory factory = TestFactory.getInstance();
VariableReference servlet = factory.addConstructor(tc.getTestCase(), new GenericConstructor(FakeServlet.class.getDeclaredConstructor(), FakeServlet.class), 0, 0);
factory.addMethod(tc.getTestCase(), new GenericMethod(EvoServletState.class.getDeclaredMethod("initServlet", Servlet.class), EvoServletState.class), 1, 0);
// shouldn't be able to pass it to createDispatcher
StringPrimitiveStatement foo = new StringPrimitiveStatement(tc.getTestCase(), null);
tc.getTestCase().addStatement(foo);
VariableReference con = factory.addMethod(tc.getTestCase(), new GenericMethod(EvoServletState.class.getDeclaredMethod("getConfiguration"), EvoServletState.class), 3, 0);
factory.addMethodFor(tc.getTestCase(), con, new GenericMethod(EvoServletConfig.class.getDeclaredMethod("createDispatcher", String.class), EvoServletConfig.class), 4);
/*
even if "foo" is null and we have the P of object reuse to 1, still "foo"
will not be used, as "null" constraint is always enforced
*/
Assert.assertEquals(tc.getTestCase().toCode(), 6, tc.size());
Assert.assertTrue(ConstraintVerifier.verifyTest(tc));
}
Aggregations