Skip to content

Commit

Permalink
test: replace jre matching check with JUnit annotation (INRIA#3704)
Browse files Browse the repository at this point in the history
  • Loading branch information
Artamm authored Nov 23, 2020
1 parent f27aa68 commit c305bc7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 36 deletions.
25 changes: 6 additions & 19 deletions src/test/java/spoon/test/module/TestModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down
20 changes: 4 additions & 16 deletions src/test/java/spoon/test/refactoring/RefactoringTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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;
}
}
7 changes: 6 additions & 1 deletion src/test/java/spoon/test/variable/VariableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand Down

0 comments on commit c305bc7

Please sign in to comment.