Skip to content

Commit

Permalink
CtScannerTest is buggy
Browse files Browse the repository at this point in the history
  • Loading branch information
pvojtechovsky committed Oct 21, 2017
1 parent dc14487 commit 5788240
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/test/java/spoon/reflect/visitor/CtScannerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@

import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Expand Down Expand Up @@ -108,15 +111,23 @@ public void testScannerCallsAllProperties() throws Exception {
CtClass<?> scanner = (CtClass<?>)launcher.getFactory().Type().get(CtScanner.class);

List<String> problems = new ArrayList<>();
Set<String> ignoredInvocations = new HashSet(Arrays.asList("scan", "enter", "exit"));

for (CtType<?> t : SpoonTestHelpers.getAllInstantiableMetamodelInterfaces()) {
CtMethod<?> visitMethod = scanner.getMethodsByName("visit"+t.getSimpleName()).get(0);
Set<String> calledMethods = new HashSet<>();
Set<String> checkedMethods = new HashSet<>();
for (CtMethod<?> m : SpoonTestHelpers.getAllMetamodelMethods(t)) {
if (isMetamodelProperty(t, m)) {
checkedMethods.add(m.getSignature());
//System.out.println("checking "+m.getSignature() +" in "+visitMethod.getSignature());
CtInvocation invocation = visitMethod.filterChildren(new TypeFilter<CtInvocation>(CtInvocation.class) {
@Override
public boolean matches(CtInvocation element) {
if(ignoredInvocations.contains(element.getExecutable().getSimpleName())) {
return false;
}
calledMethods.add(element.getExecutable().getSignature());
return super.matches(element) && element.getExecutable().getSimpleName().equals(m.getSimpleName());
}
}).first();
Expand All @@ -131,6 +142,8 @@ public boolean matches(CtInvocation element) {
}
}
}
calledMethods.removeAll(checkedMethods);
assertEquals("CtScanner " + visitMethod.getPosition() + " calls unexpected methods: "+calledMethods, 0, calledMethods.size());
}
if(problems.size()>0) {
fail(problems.toString());
Expand Down

0 comments on commit 5788240

Please sign in to comment.