use of org.junit.jupiter.engine.script.Script in project junit5 by junit-team.
the class ScriptExecutionEvaluatorTests method getJUnitConfigurationParameterWithJavaScript.
@Test
void getJUnitConfigurationParameterWithJavaScript() {
Script script = script(DisabledIf.class, "junitConfigurationParameter.get('XXX')");
Exception exception = assertThrows(ScriptEvaluationException.class, () -> evaluate(script));
assertThat(exception.getMessage()).contains("Script returned `null`");
}
use of org.junit.jupiter.engine.script.Script in project junit5 by junit-team.
the class ScriptExecutionEvaluatorTests method computeConditionEvaluationResultWithDefaultReasonMessage.
@Test
void computeConditionEvaluationResultWithDefaultReasonMessage() {
Script script = script(EnabledIf.class, "?");
ConditionEvaluationResult result = evaluator.computeConditionEvaluationResult(script, "!");
assertTrue(result.isDisabled());
assertThat(result.getReason()).contains("Script `?` evaluated to: !");
}
use of org.junit.jupiter.engine.script.Script in project junit5 by junit-team.
the class ScriptExecutionCondition method createDisabledIfScriptOrNull.
private Script createDisabledIfScriptOrNull(AnnotatedElement annotatedElement) {
Optional<DisabledIf> disabled = findAnnotation(annotatedElement, DisabledIf.class);
if (!disabled.isPresent()) {
return null;
}
DisabledIf annotation = disabled.get();
String source = createSource(annotation.value());
return new Script(annotation, annotation.engine(), source, annotation.reason());
}
use of org.junit.jupiter.engine.script.Script 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.engine.script.Script in project junit5 by junit-team.
the class ScriptExecutionCondition method evaluateExecutionCondition.
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
// Context without an annotated element?
Optional<AnnotatedElement> element = context.getElement();
if (!element.isPresent()) {
return ENABLED_NO_ELEMENT;
}
AnnotatedElement annotatedElement = element.get();
// Always try to create script instances.
Script disabledScript = createDisabledIfScriptOrNull(annotatedElement);
Script enabledScript = createEnabledIfScriptOrNull(annotatedElement);
// If no scripts are created, no annotation of interest is attached to the underlying element.
if (disabledScript == null && enabledScript == null) {
return ENABLED_NO_ANNOTATION;
}
// Prepare list with single or two script elements.
List<Script> scripts = new ArrayList<>();
if (disabledScript != null) {
scripts.add(disabledScript);
}
if (enabledScript != null) {
scripts.add(enabledScript);
}
// Let the evaluator do its work.
return evaluator.evaluate(context, scripts);
}
Aggregations