use of org.evosuite.utils.generic.GenericMethod in project evosuite by EvoSuite.
the class ConstraintVerifierTest method testAfter.
@Test
public void testAfter() throws Exception {
TestChromosome tc = new TestChromosome();
TestFactory factory = TestFactory.getInstance();
// this method has an "after" constraint on initServlet
factory.addMethod(tc.getTestCase(), new GenericMethod(EvoServletState.class.getDeclaredMethod("getRequest"), EvoServletState.class), 0, 0);
Assert.assertEquals(1, tc.size());
Assert.assertFalse(ConstraintVerifier.verifyTest(tc));
VariableReference con = 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);
Assert.assertEquals(3, tc.size());
Assert.assertTrue(ConstraintVerifier.verifyTest(tc));
}
use of org.evosuite.utils.generic.GenericMethod 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.GenericMethod in project evosuite by EvoSuite.
the class ConstraintVerifierTest method testHasAnyOnlyForAssertionMethod.
@Test
public void testHasAnyOnlyForAssertionMethod() throws Exception {
TestChromosome tc = new TestChromosome();
TestFactory factory = TestFactory.getInstance();
VariableReference req = factory.addMethod(tc.getTestCase(), new GenericMethod(EvoServletState.class.getDeclaredMethod("getRequest"), EvoServletState.class), 0, 0);
Assert.assertEquals(tc.getTestCase().toCode(), 1, tc.size());
Assert.assertFalse(ConstraintVerifier.hasAnyOnlyForAssertionMethod(tc.getTestCase()));
// this method should be only for assertions
factory.addMethodFor(tc.getTestCase(), req, new GenericMethod(EvoHttpServletRequest.class.getDeclaredMethod("isAsyncStarted"), EvoHttpServletRequest.class), 1);
Assert.assertEquals(tc.getTestCase().toCode(), 2, tc.size());
Assert.assertTrue(ConstraintVerifier.hasAnyOnlyForAssertionMethod(tc.getTestCase()));
}
use of org.evosuite.utils.generic.GenericMethod 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.GenericMethod 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));
}
Aggregations