use of org.evosuite.utils.generic.GenericMethod in project evosuite by EvoSuite.
the class ConstraintVerifierTest method testAtMostOnce.
@Test
public void testAtMostOnce() 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);
// 2 different methods that can be used at most once
factory.addMethod(tc.getTestCase(), new GenericMethod(EvoServletState.class.getDeclaredMethod("getRequest"), EvoServletState.class), 2, 0);
factory.addMethod(tc.getTestCase(), new GenericMethod(EvoServletState.class.getDeclaredMethod("getResponse"), EvoServletState.class), 3, 0);
Assert.assertEquals(4, tc.size());
Assert.assertTrue(ConstraintVerifier.verifyTest(tc));
// add an invalid new call
factory.addMethod(tc.getTestCase(), new GenericMethod(EvoServletState.class.getDeclaredMethod("getResponse"), EvoServletState.class), 4, 0);
Assert.assertEquals(5, tc.size());
// check should fail
Assert.assertFalse(ConstraintVerifier.verifyTest(tc));
}
use of org.evosuite.utils.generic.GenericMethod in project evosuite by EvoSuite.
the class ConstraintVerifierTest method testInitializingBoundedVariable_wrong_inputInOtherMethodBeforeInit.
@Test
public void testInitializingBoundedVariable_wrong_inputInOtherMethodBeforeInit() 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(ConstraintVerifierTest.class.getDeclaredMethod("takeServletAsInput", FakeServlet.class), ConstraintVerifierTest.class), 1, 0);
// initializing bounding variable method cannot be called here after the bounded variable has been used as input in some other method
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.GenericMethod in project evosuite by EvoSuite.
the class ConstraintVerifierTest method testExcludeOthers.
@Test
public void testExcludeOthers() 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);
VariableReference req = factory.addMethod(tc.getTestCase(), new GenericMethod(EvoServletState.class.getDeclaredMethod("getRequest"), EvoServletState.class), 2, 0);
factory.addMethodFor(tc.getTestCase(), req, new GenericMethod(EvoHttpServletRequest.class.getDeclaredMethod("asGET"), EvoHttpServletRequest.class), 3);
Assert.assertEquals(tc.getTestCase().toCode(), 4, tc.size());
Assert.assertTrue(ConstraintVerifier.verifyTest(tc));
// once it is set as GET, we should not be able to change it to POST
factory.addMethodFor(tc.getTestCase(), req, new GenericMethod(EvoHttpServletRequest.class.getDeclaredMethod("asPOST"), EvoHttpServletRequest.class), 4);
Assert.assertEquals(tc.getTestCase().toCode(), 5, tc.size());
Assert.assertFalse(ConstraintVerifier.verifyTest(tc));
}
use of org.evosuite.utils.generic.GenericMethod in project evosuite by EvoSuite.
the class ConstraintVerifierTest method testCanDelete.
@Test
public void testCanDelete() 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));
// bounded variable can be deleted
Assert.assertTrue(ConstraintVerifier.canDelete(tc.getTestCase(), 0));
// method using bounded variable should not be deleted
Assert.assertFalse(ConstraintVerifier.canDelete(tc.getTestCase(), 1));
boolean mutated = tc.deleteStatement(factory, 1);
// should fail
Assert.assertFalse(mutated);
Assert.assertEquals(2, tc.size());
mutated = tc.deleteStatement(factory, 0);
Assert.assertTrue(mutated);
// deleting first statement should have had effect of removing the second as well
Assert.assertEquals(0, tc.size());
}
use of org.evosuite.utils.generic.GenericMethod in project evosuite by EvoSuite.
the class ConstraintVerifierTest method testExcludeMethod.
@Test
public void testExcludeMethod() throws Exception {
TestChromosome tc = new TestChromosome();
TestFactory factory = TestFactory.getInstance();
// 'reset' is a method that shouldn't be used in a test
factory.addMethod(tc.getTestCase(), new GenericMethod(EvoServletState.class.getDeclaredMethod("reset"), EvoServletState.class), 0, 0);
Assert.assertEquals(tc.getTestCase().toCode(), 1, tc.size());
Assert.assertFalse(ConstraintVerifier.verifyTest(tc));
}
Aggregations