use of spoon.reflect.visitor.filter.TypeFilter in project dspot by STAMP-project.
the class StatementAddTest method testOnClassWithJavaObjects.
@Test
public void testOnClassWithJavaObjects() throws Exception {
/*
Test that the StatementAdd amplifier is able to generate, and manage Collection and Map from java.util
*/
final String packageName = "fr.inria.statementadd";
InputProgram inputProgram = Utils.getInputProgram();
final Factory factory = inputProgram.getFactory();
inputProgram.setFactory(factory);
AmplificationHelper.setSeedRandom(32L);
StatementAdd amplifier = new StatementAdd(packageName);
amplifier.reset(factory.Class().get(packageName + ".ClassTarget"));
CtMethod<?> ctMethod = Utils.findMethod(factory.Class().get(packageName + ".TestClassTarget"), "test");
List<CtMethod> amplifiedMethods = amplifier.apply(ctMethod);
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));
}
use of spoon.reflect.visitor.filter.TypeFilter in project dspot by STAMP-project.
the class StatementAddTest method testStatementAddOnArrayObjects.
@Test
public void testStatementAddOnArrayObjects() throws Exception {
final String packageName = "fr.inria.statementaddarray";
InputProgram inputProgram = Utils.getInputProgram();
final Factory factory = inputProgram.getFactory();
inputProgram.setFactory(factory);
AmplificationHelper.setSeedRandom(32L);
StatementAdd amplifier = new StatementAdd(packageName);
amplifier.reset(factory.Class().get(packageName + ".ClassTargetAmplify"));
CtMethod<?> ctMethod = Utils.findMethod(factory.Class().get(packageName + ".TestClassTargetAmplify"), "test");
List<CtMethod> amplifiedMethods = amplifier.apply(ctMethod);
System.out.println(amplifiedMethods);
assertEquals(5, amplifiedMethods.size());
List<String> expectedCalledMethod = Arrays.asList("methodWithArrayParatemeter", "methodWithArrayParatemeterFromDomain", "methodWithDomainParameter", "methodWithReturn", "method1");
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));
}
use of spoon.reflect.visitor.filter.TypeFilter in project dspot by STAMP-project.
the class StatementAddTest method testStatementAddOnUnderTest.
@Test
public void testStatementAddOnUnderTest() throws Exception {
Factory factory = Utils.getFactory();
CtClass<Object> ctClass = factory.Class().get("fr.inria.mutation.ClassUnderTestTest");
AmplificationHelper.setSeedRandom(23L);
StatementAdd amplificator = new StatementAdd();
amplificator.reset(ctClass);
CtMethod originalMethod = Utils.findMethod(ctClass, "testLit");
List<CtMethod> amplifiedMethods = amplificator.apply(originalMethod);
System.out.println(amplifiedMethods);
assertEquals(2, amplifiedMethods.size());
List<String> expectedCalledMethod = Arrays.asList("plusOne", "minusOne");
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));
}
use of spoon.reflect.visitor.filter.TypeFilter in project dspot by STAMP-project.
the class AmplificationHelper method createAmplifiedTest.
public static CtType createAmplifiedTest(List<CtMethod<?>> ampTest, CtType<?> classTest, Minimizer minimizer) {
CtType amplifiedTest = classTest.clone();
final String amplifiedName = classTest.getSimpleName().startsWith("Test") ? classTest.getSimpleName() + "Ampl" : "Ampl" + classTest.getSimpleName();
amplifiedTest.setSimpleName(amplifiedName);
classTest.getMethods().stream().filter(AmplificationChecker::isTest).forEach(amplifiedTest::removeMethod);
if (minimize) {
ampTest.stream().map(minimizer::minimize).forEach(amplifiedTest::addMethod);
} else {
ampTest.forEach(amplifiedTest::addMethod);
}
final CtTypeReference classTestReference = classTest.getReference();
amplifiedTest.getElements(new TypeFilter<CtTypeReference>(CtTypeReference.class) {
@Override
public boolean matches(CtTypeReference element) {
return element.equals(classTestReference) && super.matches(element);
}
}).forEach(ctTypeReference -> ctTypeReference.setSimpleName(amplifiedName));
classTest.getPackage().addType(amplifiedTest);
return amplifiedTest;
}
use of spoon.reflect.visitor.filter.TypeFilter in project dspot by STAMP-project.
the class AmplificationHelper method computeClassProvider.
@Deprecated
public static Set<CtType> computeClassProvider(CtType testClass) {
List<CtType> types = Query.getElements(testClass.getParent(CtPackage.class), new TypeFilter(CtType.class));
types = types.stream().filter(Objects::nonNull).filter(type -> type.getPackage() != null).filter(type -> type.getPackage().getQualifiedName().equals(testClass.getPackage().getQualifiedName())).collect(Collectors.toList());
if (testClass.getParent(CtType.class) != null) {
types.add(testClass.getParent(CtType.class));
}
types.addAll(types.stream().flatMap(type -> getImport(type).stream()).collect(Collectors.toSet()));
return new HashSet<>(types);
}
Aggregations