Search in sources :

Example 1 with EnabledIf

use of org.junit.jupiter.api.condition.EnabledIf in project junit5 by junit-team.

the class ScriptExecutionCondition method createEnabledIfScriptOrNull.

private Script createEnabledIfScriptOrNull(AnnotatedElement annotatedElement) {
    Optional<EnabledIf> enabled = findAnnotation(annotatedElement, EnabledIf.class);
    if (!enabled.isPresent()) {
        return null;
    }
    EnabledIf annotation = enabled.get();
    String source = createSource(annotation.value());
    return new Script(annotation, annotation.engine(), source, annotation.reason());
}
Also used : Script(org.junit.jupiter.engine.script.Script) EnabledIf(org.junit.jupiter.api.condition.EnabledIf)

Example 2 with EnabledIf

use of org.junit.jupiter.api.condition.EnabledIf in project junit5 by junit-team.

the class EnabledIfTests method multiLineAndImportJavaPackage.

@Test
@EnabledIf({ // 
"load('nashorn:mozilla_compat.js')", // 
"importPackage(java.nio.file)", // 
"", // 
"var path = Files.createTempFile('volatile-', '.temp')", // 
"java.lang.System.getProperties().put('volatile', path)", // 
"Files.exists(path)" })
void multiLineAndImportJavaPackage() throws IOException {
    Path path = (Path) System.getProperties().get("volatile");
    assertTrue(Files.exists(path));
    Files.deleteIfExists(path);
}
Also used : Path(java.nio.file.Path) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test) EnabledIf(org.junit.jupiter.api.condition.EnabledIf)

Example 3 with EnabledIf

use of org.junit.jupiter.api.condition.EnabledIf in project junit5 by junit-team.

the class ConditionalTestExecutionDemo method theDayAfterTomorrow.

// Multi-line script, custom engine name and custom reason.
@Test
// tag::user_guide_scripts[]
@EnabledIf(value = { "load('nashorn:mozilla_compat.js')", "importPackage(java.time)", "", "var today = LocalDate.now()", "var tomorrow = today.plusDays(1)", "tomorrow.isAfter(today)" }, engine = "nashorn", reason = "Self-fulfilling: {result}")
// tag::user_guide_scripts[]
void theDayAfterTomorrow() {
    LocalDate today = LocalDate.now();
    LocalDate tomorrow = today.plusDays(1);
    assertTrue(tomorrow.isAfter(today));
}
Also used : LocalDate(java.time.LocalDate) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test) EnabledIf(org.junit.jupiter.api.condition.EnabledIf)

Example 4 with EnabledIf

use of org.junit.jupiter.api.condition.EnabledIf in project junit5 by junit-team.

the class ScriptExecutionConditionTests method annotationDefaultValues.

@Test
@EnabledIf("true")
@DisabledIf("false")
void annotationDefaultValues(TestInfo info) {
    EnabledIf e = info.getTestMethod().orElseThrow(Error::new).getDeclaredAnnotation(EnabledIf.class);
    assertEquals("Nashorn", e.engine());
    assertEquals("Script `{source}` evaluated to: {result}", e.reason());
    DisabledIf d = info.getTestMethod().orElseThrow(Error::new).getDeclaredAnnotation(DisabledIf.class);
    assertEquals("Nashorn", d.engine());
    assertEquals("Script `{source}` evaluated to: {result}", d.reason());
}
Also used : EnabledIf(org.junit.jupiter.api.condition.EnabledIf) DisabledIf(org.junit.jupiter.api.condition.DisabledIf) Test(org.junit.jupiter.api.Test) EnabledIf(org.junit.jupiter.api.condition.EnabledIf) DisabledIf(org.junit.jupiter.api.condition.DisabledIf)

Aggregations

EnabledIf (org.junit.jupiter.api.condition.EnabledIf)4 Test (org.junit.jupiter.api.Test)3 RepeatedTest (org.junit.jupiter.api.RepeatedTest)2 Path (java.nio.file.Path)1 LocalDate (java.time.LocalDate)1 DisabledIf (org.junit.jupiter.api.condition.DisabledIf)1 Script (org.junit.jupiter.engine.script.Script)1