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());
}
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);
}
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));
}
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());
}
Aggregations