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

review: test: don't use Junit3 classes in test suite, only use Junit4 org.junit.* #1577

Merged
merged 1 commit into from
Oct 13, 2017
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/test/java/spoon/MavenLauncherTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void spoonMavenLauncherTest() {
// with the tests
launcher = new MavenLauncher("./", MavenLauncher.SOURCE_TYPE.ALL_SOURCE);
// 236 because of the sub folders of src/main/java and src/test/java
assertTrue(launcher.getModelBuilder().getInputSources().size() >= 236);
assertTrue("size: "+launcher.getModelBuilder().getInputSources().size(), launcher.getModelBuilder().getInputSources().size() >= 220);

// specify the pom.xml
launcher = new MavenLauncher("./pom.xml", MavenLauncher.SOURCE_TYPE.APP_SOURCE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import spoon.reflect.declaration.CtType;
import spoon.reflect.declaration.ModifierKind;
import spoon.reflect.factory.Factory;
import spoon.reflect.reference.CtTypeReference;
import spoon.reflect.visitor.filter.AbstractFilter;
import spoon.reflect.visitor.filter.TypeFilter;

Expand Down Expand Up @@ -155,6 +156,17 @@ public boolean matches(CtMethod element) {
})) {
assertTrue("naming contract violated for "+meth.getParent(CtClass.class).getSimpleName(), meth.getParent(CtClass.class).getSimpleName().startsWith("Test") || meth.getParent(CtClass.class).getSimpleName().endsWith("Test"));
}

// contract: the Spoon test suite does not depend on Junit 3 classes and methods
// otherwise, intellij automatically selects the junit3 runner, finds nothing
// and crashes with a dirty exception
assertEquals(0, spoon.getModel().getRootPackage().getElements(new TypeFilter<CtTypeReference>(CtTypeReference.class){
@Override
public boolean matches(CtTypeReference element) {
CtMethod parent = element.getParent(CtMethod.class);
return "junit.framework.TestCase".equals(element.getQualifiedName());
}
}).size());
}

@Test
Expand Down
5 changes: 4 additions & 1 deletion src/test/java/spoon/test/imports/ImportScannerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ public void testComputeImportsInClassWithSameName() throws Exception {
String className = "ImportSameName";
String qualifiedName = packageName + "." + className;

Factory aFactory = build(packageName, className).getFactory();
Launcher spoon = new Launcher();
spoon.addInputResource("src/test/resources/spoon/test/imports/testclasses2/");
spoon.buildModel();
Factory aFactory = spoon.getFactory();
CtType<?> theClass = aFactory.Type().get(qualifiedName);

ImportScanner importContext = new ImportScannerImpl();
Expand Down
47 changes: 22 additions & 25 deletions src/test/java/spoon/test/imports/ImportTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@
import spoon.test.imports.testclasses.SubClass;
import spoon.test.imports.testclasses.Tacos;
import spoon.test.imports.testclasses.internal.ChildClass;
import spoon.test.imports.testclasses2.apachetestsuite.staticcollision.AllLangTestSuite;
import spoon.test.imports.testclasses2.apachetestsuite.staticjava3.AllLangTestJava3;
import spoon.test.imports.testclasses2.apachetestsuite.staticmethod.AllLangTestSuiteStaticMethod;
import spoon.testing.utils.ModelUtils;

import java.io.File;
Expand Down Expand Up @@ -557,7 +554,7 @@ void checkCanAccess(String aClassName, boolean isInterface, boolean canAccessCli
public void testNestedAccessPathWithTypedParameter() throws Exception {
final Launcher launcher = new Launcher();
launcher.setArgs(new String[] {
"-i", "./src/test/java/spoon/test/imports/testclasses2/AbstractMapBasedMultimap.java"
"-i", "./src/test/resources/spoon/test/imports/testclasses2/AbstractMapBasedMultimap.java"
});
launcher.buildModel();
launcher.prettyprint();
Expand All @@ -580,7 +577,7 @@ public void testNestedAccessPathWithTypedParameter() throws Exception {
public void testNestedAccessPathWithTypedParameterWithImports() throws Exception {
final Launcher launcher = new Launcher();
launcher.setArgs(new String[] {
"-i", "./src/test/java/spoon/test/imports/testclasses2/AbstractMapBasedMultimap.java", "--with-imports"
"-i", "./src/test/resources/spoon/test/imports/testclasses2/AbstractMapBasedMultimap.java", "--with-imports"
});
launcher.buildModel();
launcher.prettyprint();
Expand All @@ -604,7 +601,7 @@ public void testNestedAccessPathWithTypedParameterWithImports() throws Exception
public void testNestedStaticPathWithTypedParameter() throws Exception {
final Launcher launcher = new Launcher();
launcher.setArgs(new String[] {
"-i", "./src/test/java/spoon/test/imports/testclasses2/Interners.java"
"-i", "./src/test/resources/spoon/test/imports/testclasses2/Interners.java"
});
launcher.buildModel();
launcher.prettyprint();
Expand All @@ -622,7 +619,7 @@ public void testNestedStaticPathWithTypedParameter() throws Exception {
public void testNestedStaticPathWithTypedParameterWithImports() throws Exception {
final Launcher launcher = new Launcher();
launcher.setArgs(new String[] {
"-i", "./src/test/java/spoon/test/imports/testclasses2/Interners.java", "--with-imports"
"-i", "./src/test/resources/spoon/test/imports/testclasses2/Interners.java", "--with-imports"
});
launcher.buildModel();
launcher.prettyprint();
Expand All @@ -640,7 +637,7 @@ public void testNestedStaticPathWithTypedParameterWithImports() throws Exception
public void testDeepNestedStaticPathWithTypedParameter() throws Exception {
final Launcher launcher = new Launcher();
launcher.setArgs(new String[] {
"-i", "./src/test/java/spoon/test/imports/testclasses2/StaticWithNested.java"
"-i", "./src/test/resources/spoon/test/imports/testclasses2/StaticWithNested.java"
});
launcher.buildModel();
launcher.prettyprint();
Expand All @@ -657,7 +654,7 @@ public void testDeepNestedStaticPathWithTypedParameter() throws Exception {
public void testDeepNestedStaticPathWithTypedParameterWithImports() throws Exception {
final Launcher launcher = new Launcher();
launcher.setArgs(new String[] {
"-i", "./src/test/java/spoon/test/imports/testclasses2/StaticWithNested.java", "--with-imports"
"-i", "./src/test/resources/spoon/test/imports/testclasses2/StaticWithNested.java", "--with-imports"
});
launcher.buildModel();
launcher.prettyprint();
Expand Down Expand Up @@ -961,7 +958,7 @@ public void testJavaLangIsConsideredAsImported() {
final Launcher launcher = new Launcher();
launcher.getEnvironment().setAutoImports(false);
String outputDir = "./target/spooned-javalang";
launcher.addInputResource("./src/test/java/spoon/test/imports/testclasses2/JavaLangConflict.java");
launcher.addInputResource("./src/test/resources/spoon/test/imports/testclasses2/JavaLangConflict.java");
launcher.setSourceOutputDirectory(outputDir);
launcher.run();

Expand Down Expand Up @@ -1040,16 +1037,16 @@ public void testStaticMethodWithDifferentClassSameNameJava7NoCollision() {
final Launcher launcher = new Launcher();
launcher.getEnvironment().setAutoImports(true);
String outputDir = "./target/spooned-staticmethod";
launcher.addInputResource("./src/test/java/spoon/test/imports/testclasses2/apachetestsuite/staticmethod/");
launcher.addInputResource("./src/test/java/spoon/test/imports/testclasses2/apachetestsuite/enums/");
launcher.addInputResource("./src/test/java/spoon/test/imports/testclasses2/apachetestsuite/enum2/");
launcher.addInputResource("./src/test/java/spoon/test/imports/testclasses2/apachetestsuite/LangTestSuite.java");
launcher.addInputResource("./src/test/resources/spoon/test/imports/testclasses2/apachetestsuite/staticmethod/");
launcher.addInputResource("./src/test/resources/spoon/test/imports/testclasses2/apachetestsuite/enums/");
launcher.addInputResource("./src/test/resources/spoon/test/imports/testclasses2/apachetestsuite/enum2/");
launcher.addInputResource("./src/test/resources/spoon/test/imports/testclasses2/apachetestsuite/LangTestSuite.java");
launcher.setSourceOutputDirectory(outputDir);
launcher.getEnvironment().setComplianceLevel(7);
launcher.run();
PrettyPrinter prettyPrinter = launcher.createPrettyPrinter();

CtType element = launcher.getFactory().Class().get(AllLangTestSuiteStaticMethod.class);
CtType element = launcher.getFactory().Class().get("spoon.test.imports.testclasses2.apachetestsuite.staticmethod.AllLangTestSuiteStaticMethod");
List<CtType<?>> toPrint = new ArrayList<>();
toPrint.add(element);

Expand All @@ -1070,16 +1067,16 @@ public void testStaticMethodWithDifferentClassSameNameJava3NoCollision() {
final Launcher launcher = new Launcher();
launcher.getEnvironment().setAutoImports(true);
String outputDir = "./target/spooned-staticjava3";
launcher.addInputResource("./src/test/java/spoon/test/imports/testclasses2/apachetestsuite/staticjava3/");
launcher.addInputResource("./src/test/java/spoon/test/imports/testclasses2/apachetestsuite/enums/");
launcher.addInputResource("./src/test/java/spoon/test/imports/testclasses2/apachetestsuite/enum2/");
launcher.addInputResource("./src/test/java/spoon/test/imports/testclasses2/apachetestsuite/LangTestSuite.java");
launcher.addInputResource("./src/test/resources/spoon/test/imports/testclasses2/apachetestsuite/staticjava3/");
launcher.addInputResource("./src/test/resources/spoon/test/imports/testclasses2/apachetestsuite/enums/");
launcher.addInputResource("./src/test/resources/spoon/test/imports/testclasses2/apachetestsuite/enum2/");
launcher.addInputResource("./src/test/resources/spoon/test/imports/testclasses2/apachetestsuite/LangTestSuite.java");
launcher.setSourceOutputDirectory(outputDir);
launcher.getEnvironment().setComplianceLevel(3);
launcher.run();
PrettyPrinter prettyPrinter = launcher.createPrettyPrinter();

CtType element = launcher.getFactory().Class().get(AllLangTestJava3.class);
CtType element = launcher.getFactory().Class().get("spoon.test.imports.testclasses2.apachetestsuite.staticjava3.AllLangTestJava3");
List<CtType<?>> toPrint = new ArrayList<>();
toPrint.add(element);

Expand All @@ -1100,16 +1097,16 @@ public void testStaticMethodWithDifferentClassSameNameCollision() {
final Launcher launcher = new Launcher();
launcher.getEnvironment().setAutoImports(true);
String outputDir = "./target/spooned-apache";
launcher.addInputResource("./src/test/java/spoon/test/imports/testclasses2/apachetestsuite/staticcollision/");
launcher.addInputResource("./src/test/java/spoon/test/imports/testclasses2/apachetestsuite/enums/");
launcher.addInputResource("./src/test/java/spoon/test/imports/testclasses2/apachetestsuite/enum2/");
launcher.addInputResource("./src/test/java/spoon/test/imports/testclasses2/apachetestsuite/LangTestSuite.java");
launcher.addInputResource("./src/test/resources/spoon/test/imports/testclasses2/apachetestsuite/staticcollision/");
launcher.addInputResource("./src/test/resources/spoon/test/imports/testclasses2/apachetestsuite/enums/");
launcher.addInputResource("./src/test/resources/spoon/test/imports/testclasses2/apachetestsuite/enum2/");
launcher.addInputResource("./src/test/resources/spoon/test/imports/testclasses2/apachetestsuite/LangTestSuite.java");
launcher.setSourceOutputDirectory(outputDir);
launcher.getEnvironment().setComplianceLevel(3);
launcher.run();
PrettyPrinter prettyPrinter = launcher.createPrettyPrinter();

CtType element = launcher.getFactory().Class().get(AllLangTestSuite.class);
CtType element = launcher.getFactory().Class().get("spoon.test.imports.testclasses2.apachetestsuite.staticcollision.AllLangTestSuite");
List<CtType<?>> toPrint = new ArrayList<>();
toPrint.add(element);

Expand Down
3 changes: 1 addition & 2 deletions src/test/java/spoon/test/prettyprinter/PrinterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ public void testAutoimportModeDontImportUselessStatic() {

assertTrue("The result should not contain import static: ", !result.contains("import static spoon.test.prettyprinter.testclasses.sub.Constants.READY"));
assertTrue("The result should contain import type: ", result.contains("import spoon.test.prettyprinter.testclasses.sub.Constants"));
assertTrue("The result should contain import for TestCase: ", result.contains("import junit.framework.TestCase;"));
assertTrue("The result should contain assertTrue(...): ", result.contains("TestCase.assertTrue(\"blabla\".equals(\"toto\"));"));
assertTrue("The result should contain assertTrue(...): ", result.contains("Assert.assertTrue(\"blabla\".equals(\"toto\"));"));
assertTrue("The result should use System.out.println(Constants.READY): "+result, result.contains("System.out.println(Constants.READY);"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import spoon.test.prettyprinter.testclasses.sub.Constants;

import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertTrue;


/**
* Created by urli on 30/01/2017.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

import java.util.List;

import static junit.framework.TestCase.assertFalse;
import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

public class ElasticsearchStackoverflowTest {

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/spoon/test/type/TypeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@
import java.util.List;
import java.util.stream.Collectors;

import static junit.framework.TestCase.assertFalse;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;
import static spoon.testing.utils.ModelUtils.buildClass;
import static spoon.testing.utils.ModelUtils.canBeBuilt;
Expand Down