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);
}
Aggregations