use of eu.stamp_project.dspot.amplifier.amplifiers.MethodAdderOnExistingObjectsAmplifier in project dspot by STAMP-project.
the class MethodAdderOnExistingObjectsAmplifierTest method testInLoop.
@Test
public void testInLoop() throws Exception {
/*
Test that MethodAdderOnExistingObjectsAmplifier amplifier is able to add statement inside a loop if this loop has not brackets
*/
final String packageName = "fr.inria.statementadd";
final Factory factory = launcher.getFactory();
RandomHelper.setSeedRandom(32L);
MethodAdderOnExistingObjectsAmplifier amplifier = new MethodAdderOnExistingObjectsAmplifier();
amplifier.reset(factory.Class().get(packageName + ".ClassTarget"));
CtMethod<?> ctMethod = factory.Class().get(packageName + ".TestClassTarget").getMethodsByName("testWithLoop").get(0);
// the original body of the loop has one statement
assertEquals(1, ((CtBlock<?>) ctMethod.getElements(new TypeFilter<>(CtForEach.class)).get(0).getBody()).getStatements().size());
CtMethod<?> amplifiedMethod = amplifier.amplify(ctMethod, 0).collect(Collectors.toList()).get(0);
// elements has been added by the amplification: a method call and a local variable (needed to call the method)
assertEquals(3, ((CtBlock<?>) amplifiedMethod.getElements(new TypeFilter<>(CtForEach.class)).get(0).getBody()).getStatements().size());
}
use of eu.stamp_project.dspot.amplifier.amplifiers.MethodAdderOnExistingObjectsAmplifier in project dspot by STAMP-project.
the class MethodAdderOnExistingObjectsAmplifierTest method testOnClassWithJavaObjects.
@Test
public void testOnClassWithJavaObjects() throws Exception {
/*
Test that the MethodAdderOnExistingObjectsAmplifier amplifier is able to generate, and manage Collection and Map from java.util
*/
final String packageName = "fr.inria.statementadd";
final Factory factory = launcher.getFactory();
RandomHelper.setSeedRandom(32L);
MethodAdderOnExistingObjectsAmplifier amplifier = new MethodAdderOnExistingObjectsAmplifier();
amplifier.reset(factory.Class().get(packageName + ".ClassTarget"));
CtMethod<?> ctMethod = factory.Class().get(packageName + ".TestClassTarget").getMethodsByName("test").get(0);
List<CtMethod> amplifiedMethods = amplifier.amplify(ctMethod, 0).collect(Collectors.toList());
assertEquals(7, amplifiedMethods.size());
List<String> expectedCalledMethod = Arrays.asList("getList", "getSizeOf", "getSizeOfTypedCollection", "getSizeOfTypedMap");
assertTrue(amplifiedMethods.stream().allMatch(amplifiedMethod -> amplifiedMethod.filterChildren(new TypeFilter<CtInvocation<?>>(CtInvocation.class) {
@Override
public boolean matches(CtInvocation<?> element) {
return expectedCalledMethod.contains(element.getExecutable().getSimpleName());
}
}).first() != null));
}
Aggregations