Skip to content

Commit

Permalink
test: reduce the scope of the testSettersAreAllGood test
Browse files Browse the repository at this point in the history
  • Loading branch information
tdurieux committed Feb 23, 2017
1 parent f6d989a commit 894e967
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/test/java/spoon/test/intercession/IntercessionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import spoon.reflect.declaration.CtConstructor;
import spoon.reflect.declaration.CtMethod;
import spoon.reflect.declaration.CtParameter;
import spoon.reflect.declaration.CtType;
import spoon.reflect.declaration.CtTypeParameter;
import spoon.reflect.declaration.ModifierKind;
import spoon.reflect.factory.Factory;
Expand All @@ -31,6 +32,7 @@
import spoon.support.UnsettableProperty;

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

Expand Down Expand Up @@ -181,28 +183,32 @@ public void testInsertAfter() {

@Test
public void testSettersAreAllGood() throws Exception {
StringBuilder classpath = new StringBuilder();
ArrayList classpath = new ArrayList();
for (String classpathEntry : System.getProperty("java.class.path").split(File.pathSeparator)) {
if (!classpathEntry.contains("test-classes")) {
classpath.append(classpathEntry);
classpath.append(File.pathSeparator);
classpath.add(classpathEntry);
}
}
String systemClassPath = classpath.substring(0, classpath.length() - 1);

final Launcher launcher = new Launcher();
launcher.run(new String[] {
"-i", "./src/main/java",
"--output-type", "nooutput",
"--source-classpath", systemClassPath
});
launcher.addInputResource("./src/main/java/spoon/reflect/");
launcher.addInputResource("./src/main/java/spoon/support/");
launcher.getModelBuilder().setSourceClasspath((String[]) classpath.toArray(new String[]{}));
launcher.buildModel();

final Factory factory = launcher.getFactory();
final List<CtMethod<?>> setters = Query
.getElements(factory, new AbstractFilter<CtMethod<?>>(CtMethod.class) {
@Override
public boolean matches(CtMethod<?> element) {
return element.getDeclaringType().isInterface() &&
element.getDeclaringType().getSimpleName().startsWith("Ct") &&
CtType<?> declaringType = element.getDeclaringType();
if (declaringType.getPackage() != null &&
(declaringType.getPackage().getQualifiedName().startsWith("spoon.support.visitor")
|| declaringType.getPackage().getQualifiedName().startsWith("spoon.reflect.visitor"))) {
return false;
}
return declaringType.isInterface() &&
declaringType.getSimpleName().startsWith("Ct") &&
(element.getSimpleName().startsWith("set") ||
element.getSimpleName().startsWith("add"));
}
Expand Down

0 comments on commit 894e967

Please sign in to comment.