Search in sources :

Example 1 with AbstractLiteralAmplifier

use of eu.stamp_project.dspot.amplifier.amplifiers.AbstractLiteralAmplifier in project dspot by STAMP-project.

the class LiteralAmplifiersTest method testAvoidRedundantAmplification.

@Test
public void testAvoidRedundantAmplification() throws Exception {
    /*
            This test implements the example cases showed in https://github.com/STAMP-project/dspot/issues/454
         */
    CtClass<?> literalMutationClass = launcher.getFactory().Class().get("fr.inria.amp.LiteralMutation");
    final String nameMethod = "methodString";
    final CtMethod method = literalMutationClass.getMethodsByName(nameMethod).get(0);
    final CtMethod clone = method.clone();
    clone.setSimpleName("temporaryMethod");
    clone.setBody(launcher.getFactory().createCodeSnippetStatement("int x = 1 + 1").compile());
    Amplifier zeroAmplifier = new AbstractLiteralAmplifier<Integer>() {

        @Override
        protected Set<CtExpression<Integer>> amplify(CtExpression<Integer> original, CtMethod<?> testMethod) {
            return Collections.singleton(testMethod.getFactory().createLiteral(0));
        }

        @Override
        protected String getSuffix() {
            return "zero-amplifier";
        }

        @Override
        protected Class<?> getTargetedClass() {
            return Integer.class;
        }
    };
    literalMutationClass.addMethod(clone);
    // used to verify that the application of Amplifiers does not modify the given test method
    final String originalTestMethodString = clone.toString();
    List<CtMethod<?>> zeroAmplifiedTests = zeroAmplifier.amplify(clone, 0).collect(Collectors.toList());
    assertEquals(2, zeroAmplifiedTests.size());
    // the original test method has not been modified
    assertEquals(originalTestMethodString, clone.toString());
    zeroAmplifiedTests = zeroAmplifiedTests.stream().flatMap(testMethod -> zeroAmplifier.amplify(testMethod, 0)).collect(Collectors.toList());
    assertEquals(originalTestMethodString, clone.toString());
    assertEquals(1, zeroAmplifiedTests.size());
    literalMutationClass.removeMethod(clone);
}
Also used : AbstractLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.AbstractLiteralAmplifier) CtExpression(spoon.reflect.code.CtExpression) AbstractLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.AbstractLiteralAmplifier) StringLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.StringLiteralAmplifier) NumberLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.NumberLiteralAmplifier) Amplifier(eu.stamp_project.dspot.amplifier.amplifiers.Amplifier) CtMethod(spoon.reflect.declaration.CtMethod) Test(org.junit.Test)

Aggregations

AbstractLiteralAmplifier (eu.stamp_project.dspot.amplifier.amplifiers.AbstractLiteralAmplifier)1 Amplifier (eu.stamp_project.dspot.amplifier.amplifiers.Amplifier)1 NumberLiteralAmplifier (eu.stamp_project.dspot.amplifier.amplifiers.NumberLiteralAmplifier)1 StringLiteralAmplifier (eu.stamp_project.dspot.amplifier.amplifiers.StringLiteralAmplifier)1 Test (org.junit.Test)1 CtExpression (spoon.reflect.code.CtExpression)1 CtMethod (spoon.reflect.declaration.CtMethod)1