Search in sources :

Example 6 with Script

use of org.junit.jupiter.engine.script.Script in project junit5 by junit-team.

the class ScriptExecutionEvaluatorTests method computeConditionEvaluationResultFailsForUnsupportedAnnotationType.

private void computeConditionEvaluationResultFailsForUnsupportedAnnotationType(Class<? extends Annotation> type) {
    Script script = new Script(type, "annotation", "engine", "source", "reason");
    Exception e = assertThrows(ScriptEvaluationException.class, () -> evaluator.computeConditionEvaluationResult(script, "!"));
    String expected = "Unsupported annotation type: " + type;
    String actual = e.getMessage();
    assertEquals(expected, actual);
}
Also used : Script(org.junit.jupiter.engine.script.Script) ScriptEvaluationException(org.junit.jupiter.api.extension.ScriptEvaluationException)

Example 7 with Script

use of org.junit.jupiter.engine.script.Script in project junit5 by junit-team.

the class ScriptExecutionEvaluatorTests method getJUnitConfigurationParameterWithJavaScriptAndCheckForNull.

@Test
void getJUnitConfigurationParameterWithJavaScriptAndCheckForNull() {
    Script script = script(DisabledIf.class, "junitConfigurationParameter.get('XXX') == null");
    ConditionEvaluationResult result = evaluate(script);
    assertTrue(result.isDisabled());
    // 
    assertThat(result.getReason()).contains("Script `junitConfigurationParameter.get('XXX') == null` evaluated to: true");
}
Also used : Script(org.junit.jupiter.engine.script.Script) ConditionEvaluationResult(org.junit.jupiter.api.extension.ConditionEvaluationResult) Test(org.junit.jupiter.api.Test) DynamicTest.dynamicTest(org.junit.jupiter.api.DynamicTest.dynamicTest) DynamicTest(org.junit.jupiter.api.DynamicTest)

Example 8 with Script

use of org.junit.jupiter.engine.script.Script in project junit5 by junit-team.

the class ScriptExecutionEvaluatorTests method defaultConditionEvaluationResultProperties.

@Test
void defaultConditionEvaluationResultProperties() {
    Script script = script(EnabledIf.class, "true");
    ConditionEvaluationResult result = evaluate(script);
    assertFalse(result.isDisabled());
    assertThat(result.toString()).contains("ConditionEvaluationResult", "enabled", "true", "reason");
}
Also used : Script(org.junit.jupiter.engine.script.Script) ConditionEvaluationResult(org.junit.jupiter.api.extension.ConditionEvaluationResult) Test(org.junit.jupiter.api.Test) DynamicTest.dynamicTest(org.junit.jupiter.api.DynamicTest.dynamicTest) DynamicTest(org.junit.jupiter.api.DynamicTest)

Aggregations

Script (org.junit.jupiter.engine.script.Script)8 DynamicTest (org.junit.jupiter.api.DynamicTest)4 DynamicTest.dynamicTest (org.junit.jupiter.api.DynamicTest.dynamicTest)4 Test (org.junit.jupiter.api.Test)4 ConditionEvaluationResult (org.junit.jupiter.api.extension.ConditionEvaluationResult)3 ScriptEvaluationException (org.junit.jupiter.api.extension.ScriptEvaluationException)2 AnnotatedElement (java.lang.reflect.AnnotatedElement)1 ArrayList (java.util.ArrayList)1 DisabledIf (org.junit.jupiter.api.condition.DisabledIf)1 EnabledIf (org.junit.jupiter.api.condition.EnabledIf)1