Search in sources :

Example 1 with ConditionEvaluationContext

use of cn.taketoday.context.annotation.ConditionEvaluationContext in project today-infrastructure by TAKETODAY.

the class ConditionalOnExpressionTests method expressionEvaluationWithNoBeanFactoryDoesNotMatch.

@Test
void expressionEvaluationWithNoBeanFactoryDoesNotMatch() {
    OnExpressionCondition condition = new OnExpressionCondition();
    MockEnvironment environment = new MockEnvironment();
    ConditionEvaluationContext evaluationContext = mock(ConditionEvaluationContext.class);
    given(evaluationContext.getEnvironment()).willReturn(environment);
    ConditionOutcome outcome = condition.getMatchOutcome(evaluationContext, mockMetaData("invalid-spel"));
    assertThat(outcome.isMatch()).isFalse();
    assertThat(outcome.getMessage()).contains("invalid-spel").contains("no BeanFactory available");
}
Also used : MockEnvironment(cn.taketoday.mock.env.MockEnvironment) ConditionEvaluationContext(cn.taketoday.context.annotation.ConditionEvaluationContext) Test(org.junit.jupiter.api.Test)

Example 2 with ConditionEvaluationContext

use of cn.taketoday.context.annotation.ConditionEvaluationContext in project today-framework by TAKETODAY.

the class ConditionalOnExpressionTests method expressionEvaluationWithNoBeanFactoryDoesNotMatch.

@Test
void expressionEvaluationWithNoBeanFactoryDoesNotMatch() {
    OnExpressionCondition condition = new OnExpressionCondition();
    MockEnvironment environment = new MockEnvironment();
    ConditionEvaluationContext evaluationContext = mock(ConditionEvaluationContext.class);
    given(evaluationContext.getEnvironment()).willReturn(environment);
    ConditionOutcome outcome = condition.getMatchOutcome(evaluationContext, mockMetaData("invalid-spel"));
    assertThat(outcome.isMatch()).isFalse();
    assertThat(outcome.getMessage()).contains("invalid-spel").contains("no BeanFactory available");
}
Also used : MockEnvironment(cn.taketoday.mock.env.MockEnvironment) ConditionEvaluationContext(cn.taketoday.context.annotation.ConditionEvaluationContext) Test(org.junit.jupiter.api.Test)

Aggregations

ConditionEvaluationContext (cn.taketoday.context.annotation.ConditionEvaluationContext)2 MockEnvironment (cn.taketoday.mock.env.MockEnvironment)2 Test (org.junit.jupiter.api.Test)2