Search in sources :

Example 1 with ConditionEvaluationResult

use of org.junit.jupiter.api.extension.ConditionEvaluationResult in project junit5 by junit-team.

the class ScriptExecutionConditionTests method enabledDueToAnnotationNotPresent.

@Test
void enabledDueToAnnotationNotPresent() {
    ScriptExecutionCondition condition = new ScriptExecutionCondition();
    ExtensionContext context = Mockito.mock(ExtensionContext.class);
    Optional<AnnotatedElement> optionalElement = Optional.of(ScriptExecutionConditionTests.class);
    Mockito.when(context.getElement()).thenReturn(optionalElement);
    ConditionEvaluationResult result = condition.evaluateExecutionCondition(context);
    assertFalse(result.isDisabled());
    assertThat(result.getReason()).contains("Annotation not present");
}
Also used : ConditionEvaluationResult(org.junit.jupiter.api.extension.ConditionEvaluationResult) AnnotatedElement(java.lang.reflect.AnnotatedElement) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) Test(org.junit.jupiter.api.Test)

Example 2 with ConditionEvaluationResult

use of org.junit.jupiter.api.extension.ConditionEvaluationResult 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: !");
}
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 3 with ConditionEvaluationResult

use of org.junit.jupiter.api.extension.ConditionEvaluationResult in project junit5 by junit-team.

the class ConditionEvaluator method evaluate.

private ConditionEvaluationResult evaluate(ExecutionCondition condition, ExtensionContext context) {
    try {
        ConditionEvaluationResult result = condition.evaluateExecutionCondition(context);
        logResult(condition.getClass(), result);
        return result;
    } catch (Exception ex) {
        throw evaluationException(condition.getClass(), ex);
    }
}
Also used : ConditionEvaluationResult(org.junit.jupiter.api.extension.ConditionEvaluationResult)

Example 4 with ConditionEvaluationResult

use of org.junit.jupiter.api.extension.ConditionEvaluationResult in project junit5 by junit-team.

the class ScriptExecutionConditionTests method enabledDueToAnnotatedElementNotPresent.

@Test
void enabledDueToAnnotatedElementNotPresent() {
    ScriptExecutionCondition condition = new ScriptExecutionCondition();
    ExtensionContext context = Mockito.mock(ExtensionContext.class);
    ConditionEvaluationResult result = condition.evaluateExecutionCondition(context);
    assertFalse(result.isDisabled());
    assertThat(result.getReason()).contains("AnnotatedElement not present");
}
Also used : ConditionEvaluationResult(org.junit.jupiter.api.extension.ConditionEvaluationResult) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) Test(org.junit.jupiter.api.Test)

Example 5 with ConditionEvaluationResult

use of org.junit.jupiter.api.extension.ConditionEvaluationResult 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)

Aggregations

ConditionEvaluationResult (org.junit.jupiter.api.extension.ConditionEvaluationResult)6 Test (org.junit.jupiter.api.Test)5 DynamicTest (org.junit.jupiter.api.DynamicTest)3 DynamicTest.dynamicTest (org.junit.jupiter.api.DynamicTest.dynamicTest)3 Script (org.junit.jupiter.engine.script.Script)3 ExtensionContext (org.junit.jupiter.api.extension.ExtensionContext)2 AnnotatedElement (java.lang.reflect.AnnotatedElement)1