Search in sources :

Example 1 with OperatorOverloader

use of org.springframework.expression.OperatorOverloader in project spring-security by spring-projects.

the class DelegatingEvaluationContextTests method getOperatorOverloader.

@Test
public void getOperatorOverloader() {
    OperatorOverloader expected = mock(OperatorOverloader.class);
    when(this.delegate.getOperatorOverloader()).thenReturn(expected);
    assertThat(this.context.getOperatorOverloader()).isEqualTo(expected);
}
Also used : OperatorOverloader(org.springframework.expression.OperatorOverloader) Test(org.junit.Test)

Example 2 with OperatorOverloader

use of org.springframework.expression.OperatorOverloader in project spring-framework by spring-projects.

the class StandardComponentsTests method testStandardOperatorOverloader.

@Test(expected = EvaluationException.class)
public void testStandardOperatorOverloader() throws EvaluationException {
    OperatorOverloader oo = new StandardOperatorOverloader();
    assertFalse(oo.overridesOperation(Operation.ADD, null, null));
    oo.operate(Operation.ADD, 2, 3);
}
Also used : OperatorOverloader(org.springframework.expression.OperatorOverloader) Test(org.junit.Test)

Example 3 with OperatorOverloader

use of org.springframework.expression.OperatorOverloader in project spring-framework by spring-projects.

the class ExpressionState method operate.

public TypedValue operate(Operation op, Object left, Object right) throws EvaluationException {
    OperatorOverloader overloader = this.relatedContext.getOperatorOverloader();
    if (overloader.overridesOperation(op, left, right)) {
        Object returnValue = overloader.operate(op, left, right);
        return new TypedValue(returnValue);
    } else {
        String leftType = (left == null ? "null" : left.getClass().getName());
        String rightType = (right == null ? "null" : right.getClass().getName());
        throw new SpelEvaluationException(SpelMessage.OPERATOR_NOT_SUPPORTED_BETWEEN_TYPES, op, leftType, rightType);
    }
}
Also used : OperatorOverloader(org.springframework.expression.OperatorOverloader) TypedValue(org.springframework.expression.TypedValue)

Aggregations

OperatorOverloader (org.springframework.expression.OperatorOverloader)3 Test (org.junit.Test)2 TypedValue (org.springframework.expression.TypedValue)1