diff --git a/src/test/java/spoon/test/module/TestModule.java b/src/test/java/spoon/test/module/TestModule.java index 7811b864f5b..95166517907 100644 --- a/src/test/java/spoon/test/module/TestModule.java +++ b/src/test/java/spoon/test/module/TestModule.java @@ -17,10 +17,11 @@ package spoon.test.module; import org.junit.AfterClass; -import org.junit.Assume; import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; +import org.junit.jupiter.api.condition.DisabledForJreRange; +import org.junit.jupiter.api.condition.JRE; import spoon.Launcher; import spoon.SpoonException; import spoon.reflect.CtModel; @@ -54,15 +55,6 @@ public class TestModule { private static final String MODULE_RESOURCES_PATH = "./src/test/resources/spoon/test/module"; - private void checkJavaVersion() { - String property = System.getProperty("java.version"); - if (property != null && !property.isEmpty()) { - - // java 8 and less are versionning "1.X" where 9 and more are directly versioned "X" - Assume.assumeFalse(property.startsWith("1.")); - } - } - @BeforeClass public static void setUp() throws IOException { File directory = new File(MODULE_RESOURCES_PATH); @@ -292,9 +284,9 @@ public void testGetModuleAfterChangingItsName() { assertSame(module, moduleNewName); } - @Test + @org.junit.jupiter.api.Test + @DisabledForJreRange(max = JRE.JAVA_8) public void testSimpleModuleCanBeBuilt() { - checkJavaVersion(); // contract: Spoon is able to build a simple model with a module in full classpath final Launcher launcher = new Launcher(); launcher.getEnvironment().setComplianceLevel(9); @@ -304,20 +296,15 @@ public void testSimpleModuleCanBeBuilt() { CtModel model = launcher.getModel(); - // unnamed module and module 'simple_module_with_code' - assertEquals(2, model.getAllModules().size()); + // unnamed module + assertEquals(1, model.getAllModules().size()); assertEquals(1, model.getAllTypes().size()); CtClass simpleClass = model.getElements(new TypeFilter<>(CtClass.class)).get(0); assertEquals("SimpleClass", simpleClass.getSimpleName()); - CtModule simpleModule = model.getElements(new NamedElementFilter<>(CtModule.class, "simple_module_with_code")).get(0); - assertNotNull(simpleModule); - assertEquals("simple_module_with_code", simpleModule.getSimpleName()); - CtModule module = simpleClass.getParent(CtModule.class); assertNotNull(module); - assertSame(simpleModule, module); } @Ignore diff --git a/src/test/java/spoon/test/refactoring/RefactoringTest.java b/src/test/java/spoon/test/refactoring/RefactoringTest.java index 59e2db7bb1e..6fd6b6ce7c7 100644 --- a/src/test/java/spoon/test/refactoring/RefactoringTest.java +++ b/src/test/java/spoon/test/refactoring/RefactoringTest.java @@ -29,8 +29,10 @@ import java.util.Comparator; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledForJreRange; +import org.junit.jupiter.api.condition.JRE; import spoon.Launcher; import spoon.refactoring.Refactoring; import spoon.reflect.code.BinaryOperatorKind; @@ -148,10 +150,8 @@ public void testTransformedInstanceofAfterATransformation() { assertEquals("spoon.test.refactoring.testclasses.AClassX", instanceofInvocation.getRightHandOperand().toString()); } @Test + @DisabledForJreRange(max = JRE.JAVA_8) public void testRemoveDeprecatedMethods() { - if (checkJavaVersion()) { - return; - } // clean dir if exists try { Files.walk(Paths.get("target/deprecated-refactoring")).sorted(Comparator.reverseOrder()) @@ -184,16 +184,4 @@ public void testRemoveDeprecatedMethods() { // error is kinda okay } } - /** - * checks if current java version is >=9. - * True if <=8 else false; - */ - private boolean checkJavaVersion() { - String property = System.getProperty("java.version"); - if (property != null && !property.isEmpty()) { - // java 8 and less are versionning "1.X" where 9 and more are directly versioned "X" - return property.startsWith("1."); - } - return false; - } } diff --git a/src/test/java/spoon/test/variable/VariableTest.java b/src/test/java/spoon/test/variable/VariableTest.java index 6671e66fcf3..394adfdf5a6 100644 --- a/src/test/java/spoon/test/variable/VariableTest.java +++ b/src/test/java/spoon/test/variable/VariableTest.java @@ -18,7 +18,9 @@ import com.google.common.io.Files; import org.apache.commons.lang3.StringUtils; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledForJreRange; +import org.junit.jupiter.api.condition.JRE; import spoon.Launcher; import spoon.reflect.CtModel; import spoon.reflect.code.CtLambda; @@ -56,6 +58,7 @@ public void testJointDeclVariables() { } @Test + @DisabledForJreRange(max = JRE.JAVA_9) public void testInferredVariableAreMarked() { // contract: if a variable is declared with 'var' keyword, it must be marked as inferred in the model Launcher launcher = new Launcher(); @@ -94,6 +97,7 @@ public void testInferredVariableAreMarked() { } @Test + @DisabledForJreRange(max = JRE.JAVA_9) public void testInferredVariableArePrintedWithVar() throws IOException { // contract: if a variable is marked as inferred in the model, it must be pretty-printed with a 'var' keyword Launcher launcher = new Launcher(); @@ -117,6 +121,7 @@ public void testInferredVariableArePrintedWithVar() throws IOException { } @Test + @DisabledForJreRange(max = JRE.JAVA_10) public void testVarInLambda() { // contract: we should handle local variable syntax for lambda parameters properly (since Java 11) // example: (var x, var y) -> x + y;