Bael 3850: EnabledForJRERange and DisabledForJRERange JUnit Annotations (#8724)

* Upgraded to Jupiter 5.6.0

Also removed some deprecated stuff!

* Added a new test

* Resotre Delete Tests
This commit is contained in:
Mona Mohamadinia 2020-02-22 14:16:52 +03:30 committed by GitHub
parent 9da978ec65
commit 80b7fed6e1
2 changed files with 31 additions and 16 deletions

View File

@ -49,8 +49,8 @@
</dependencies> </dependencies>
<properties> <properties>
<junit.jupiter.version>5.4.2</junit.jupiter.version> <junit.jupiter.version>5.6.0</junit.jupiter.version>
<junit.platform.version>1.4.2</junit.platform.version> <junit.platform.version>1.6.0</junit.platform.version>
<log4j2.version>2.8.2</log4j2.version> <log4j2.version>2.8.2</log4j2.version>
</properties> </properties>

View File

@ -10,6 +10,7 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
public class ConditionalAnnotationsUnitTest { public class ConditionalAnnotationsUnitTest {
@Test @Test
@EnabledOnOs({OS.WINDOWS, OS.MAC}) @EnabledOnOs({OS.WINDOWS, OS.MAC})
public void shouldRunBothWindowsAndMac() { public void shouldRunBothWindowsAndMac() {
@ -28,6 +29,18 @@ public class ConditionalAnnotationsUnitTest {
System.out.println("runs with java 10 and 11"); System.out.println("runs with java 10 and 11");
} }
@Test
@EnabledForJreRange(min = JRE.JAVA_8, max = JRE.JAVA_13)
public void shouldOnlyRunOnJava8UntilJava13() {
System.out.println("runs with Java 8, 9, 10, 11, 12 and 13!");
}
@Test
@DisabledForJreRange(min = JRE.JAVA_14, max = JRE.JAVA_15)
public void shouldNotBeRunOnJava14AndJava15() {
System.out.println("Shouldn't be run on Java 14 and 15.");
}
@Test @Test
@DisabledOnJre(JRE.OTHER) @DisabledOnJre(JRE.OTHER)
public void thisTestOnlyRunsWithUpToDateJREs() { public void thisTestOnlyRunsWithUpToDateJREs() {
@ -58,36 +71,38 @@ public class ConditionalAnnotationsUnitTest {
System.out.println("will not run if environment variable LC_TIME is UTF-8"); System.out.println("will not run if environment variable LC_TIME is UTF-8");
} }
// Commented codes are going to work prior JUnit 5.5
@Test @Test
@EnabledIf("'FR' == systemProperty.get('user.country')") // @EnabledIf("'FR' == systemProperty.get('user.country')")
public void onlyFrenchPeopleWillRunThisMethod() { public void onlyFrenchPeopleWillRunThisMethod() {
System.out.println("will run only if user.country is FR"); System.out.println("will run only if user.country is FR");
} }
@Test @Test
@DisabledIf("java.lang.System.getProperty('os.name').toLowerCase().contains('mac')") // @DisabledIf("java.lang.System.getProperty('os.name').toLowerCase().contains('mac')")
public void shouldNotRunOnMacOS() { public void shouldNotRunOnMacOS() {
System.out.println("will not run if our os.name is mac"); System.out.println("will not run if our os.name is mac");
} }
@Test @Test
@EnabledIf(value = { /*@EnabledIf(value = {
"load('nashorn:mozilla_compat.js')", "load('nashorn:mozilla_compat.js')",
"importPackage(java.time)", "importPackage(java.time)",
"", "",
"var thisMonth = LocalDate.now().getMonth().name()", "var thisMonth = LocalDate.now().getMonth().name()",
"var february = Month.FEBRUARY.name()", "var february = Month.FEBRUARY.name()",
"thisMonth.equals(february)" "thisMonth.equals(february)"
}, },
engine = "nashorn", engine = "nashorn",
reason = "Self-fulfilling: {result}") reason = "Self-fulfilling: {result}")*/
public void onlyRunsInFebruary() { public void onlyRunsInFebruary() {
System.out.println("this test only runs in February"); System.out.println("this test only runs in February");
} }
@Test @Test
@DisabledIf("systemEnvironment.get('XPC_SERVICE_NAME') != null " + /*@DisabledIf("systemEnvironment.get('XPC_SERVICE_NAME') != null " +
"&& systemEnvironment.get('XPC_SERVICE_NAME').contains('intellij')") "&& systemEnvironment.get('XPC_SERVICE_NAME').contains('intellij')")*/
public void notValidForIntelliJ() { public void notValidForIntelliJ() {
System.out.println("this test will run if our ide is INTELLIJ"); System.out.println("this test will run if our ide is INTELLIJ");
} }
@ -107,7 +122,7 @@ public class ConditionalAnnotationsUnitTest {
@Target(ElementType.METHOD) @Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@DisabledIf("Math.random() >= 0.5") // @DisabledIf("Math.random() >= 0.5")
@interface CoinToss { @interface CoinToss {
} }