use of spoon.reflect.declaration.CtMethod in project dspot by STAMP-project.
the class MethodsAssertGeneratorTest method testOnInfiniteLoop.
@Test
public void testOnInfiniteLoop() throws Exception {
AmplificationHelper.setTimeOutInMs(1000);
final CtClass testClass = Utils.findClass("fr.inria.infinite.LoopTest");
MethodsAssertGenerator mag = new MethodsAssertGenerator(testClass, Utils.getInputConfiguration(), Utils.getCompiler());
CtMethod test = Utils.findMethod("fr.inria.infinite.LoopTest", "testLoop");
List<CtMethod<?>> test_buildNewAssert = mag.generateAsserts(testClass, Collections.singletonList(test));
assertTrue(test_buildNewAssert.isEmpty());
AmplificationHelper.setTimeOutInMs(10000);
}
use of spoon.reflect.declaration.CtMethod in project dspot by STAMP-project.
the class MethodsAssertGeneratorTest method testBuildAssertOnSpecificCases.
@Test
public void testBuildAssertOnSpecificCases() throws Exception {
CtClass testClass = Utils.findClass("fr.inria.sample.TestClassWithSpecificCaseToBeAsserted");
MethodsAssertGenerator mag = new MethodsAssertGenerator(testClass, Utils.getInputConfiguration(), Utils.getCompiler());
CtMethod test1 = Utils.findMethod("fr.inria.sample.TestClassWithSpecificCaseToBeAsserted", "test1");
List<CtMethod<?>> test1_buildNewAssert = mag.generateAsserts(testClass, Collections.singletonList(test1));
final String expectedBody = "{" + AmplificationHelper.LINE_SEPARATOR + " int a = 0;" + AmplificationHelper.LINE_SEPARATOR + " int b = 1;" + AmplificationHelper.LINE_SEPARATOR + " int o_test1__3 = new java.util.Comparator<java.lang.Integer>() {" + AmplificationHelper.LINE_SEPARATOR + " @java.lang.Override" + AmplificationHelper.LINE_SEPARATOR + " public int compare(java.lang.Integer integer, java.lang.Integer t1) {" + AmplificationHelper.LINE_SEPARATOR + " return integer - t1;" + AmplificationHelper.LINE_SEPARATOR + " }" + AmplificationHelper.LINE_SEPARATOR + " }.compare(a, b);" + AmplificationHelper.LINE_SEPARATOR + " org.junit.Assert.assertEquals(-1, ((int) (o_test1__3)));" + AmplificationHelper.LINE_SEPARATOR + "}";
assertEquals(expectedBody, test1_buildNewAssert.get(0).getBody().toString());
}
use of spoon.reflect.declaration.CtMethod in project dspot by STAMP-project.
the class MethodsAssertGeneratorTest method testBuildNewAssert.
@Test
public void testBuildNewAssert() throws Exception {
/*
DSpot is able to generate multiple assertion using getter inside the targeted class
- Boolean (assertTrue / assertFalse)
- primitive type and String (assertEquals)
- null value (assertNull)
- Collection: with elements (assertTrue(contains())) and empty (assertTrue(isEmpty()))
//TODO support generation of assertion on array and on map
*/
CtClass testClass = Utils.findClass("fr.inria.sample.TestClassWithoutAssert");
MethodsAssertGenerator mag = new MethodsAssertGenerator(testClass, Utils.getInputConfiguration(), Utils.getCompiler());
CtMethod test1 = Utils.findMethod("fr.inria.sample.TestClassWithoutAssert", "test1");
List<CtMethod<?>> test1_buildNewAssert = mag.generateAsserts(testClass, Collections.singletonList(test1));
assertEquals(expectedBody, test1_buildNewAssert.get(0).getBody().toString());
}
use of spoon.reflect.declaration.CtMethod in project dspot by STAMP-project.
the class ChangeDetectorSelectorTest method getAmplifiedTest.
@Override
protected CtMethod<?> getAmplifiedTest() {
final CtMethod clone = getTest().clone();
Utils.replaceGivenLiteralByNewValue(clone, -1);
return clone;
}
use of spoon.reflect.declaration.CtMethod in project dspot by STAMP-project.
the class NumberLiteralAmplifierTest method testShortMutation.
@Test
public void testShortMutation() throws Exception {
final String nameMethod = "methodShort";
final short originalValue = 23;
CtClass<Object> literalMutationClass = Utils.getFactory().Class().get("fr.inria.amp.LiteralMutation");
AmplificationHelper.setSeedRandom(42L);
NumberLiteralAmplifier amplificator = getAmplifier(literalMutationClass);
CtMethod method = literalMutationClass.getMethod(nameMethod);
List<Short> expectedValues = Arrays.asList((short) 22, (short) 24, Short.MIN_VALUE, Short.MAX_VALUE, (short) 0);
List<CtMethod> mutantMethods = amplificator.apply(method);
assertEquals(5, mutantMethods.size());
for (int i = 0; i < mutantMethods.size(); i++) {
CtMethod mutantMethod = mutantMethods.get(i);
assertEquals(nameMethod + "litNum" + (i + 1), mutantMethod.getSimpleName());
CtLiteral mutantLiteral = mutantMethod.getBody().getElements(new TypeFilter<>(CtLiteral.class)).get(0);
assertNotEquals(originalValue, mutantLiteral.getValue());
assertTrue(mutantLiteral.getValue() + " not in expected values", expectedValues.contains(mutantLiteral.getValue()));
}
}
Aggregations