Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: reduce the scope of the testSettersAreAllGood test #1196

Merged
merged 1 commit into from
Feb 23, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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