SpelExpressionEvaluator implements ExpressionEvaluator { @Override public Object getValue(String exprValue, Object rootObject) { return getValue(exprValue, rootObject, (expr, ctx)->expr.getValue(ctx)); }  @Override Object getValue(String exprValue, Object rootObject); @Override T getValue(String exprValue, Object rootObject, Class<T> returnType);  }
@Test public void t13_evaluate_findParamByState_expression() { Param<?> onChangeParam = Mockito.mock(Param.class); @SuppressWarnings("rawtypes") ParamStateHolder holder = Mockito.mock(ParamStateHolder.class); Mockito.when(holder.getState()).thenReturn("foo"); Mockito.when(holder.findStateByPath("somepath")).thenReturn("foo"); String expr = "state == findStateByPath('somepath')"; Boolean result = expressionEvaluator.getValue(expr, new ParamStateHolder<>(onChangeParam), Boolean.class); assertTrue(result); }
@Test public void t01_evaluate_null_array_expressions() { String expr = "state != null"; Boolean result = expressionEvaluator.getValue(expr, new Holder<>(strArr), Boolean.class); assertTrue(result); }
@Test public void t02_evaluate_exact_equals_expression() { String expr = "state == new String[]{'Apple','Google','Facebook',' ','Hewlett Packard', null}"; Boolean result = expressionEvaluator.getValue(expr, new Holder<>(strArr), Boolean.class); assertTrue(result); }
@Test public void t03a_PREFERRED_UNORDERED_evaluate_contains_multiple_and_elements_expression() { String expr = "state != null && state.?[#this=='Apple'] != new String[]{} && state.?[#this=='Google'] != new String[]{}"; Boolean result = expressionEvaluator.getValue(expr, new Holder<>(strArr), Boolean.class); assertTrue(result); }
@Test public void t03b_ORDER_KNOWN_evaluate_contains_multiple_and_elements_expression() { String expr = "state!=null && state.?[#this=='Apple' || #this=='Google'] == new String[]{'Apple', 'Google'}"; Boolean result = expressionEvaluator.getValue(expr, new Holder<>(strArr), Boolean.class); assertTrue(result); }
@Test public void t03b_ORDER_UNKNOWN_FAIL_evaluate_contains_multiple_and_elements_expression() { String expr = "state!=null && state.?[#this=='Apple' || #this=='Google'] == new String[]{'Google', 'Apple'}"; Boolean result = expressionEvaluator.getValue(expr, new Holder<>(strArr), Boolean.class); assertFalse(result); }
@Test public void t03d_PREFERRED_NEGATIVE_evaluate_contains_multiple_and_elements_expression() { String expr = "state != null && state.?[#this=='XYZ'] != new String[]{} && state.?[#this=='Google'] != new String[]{}"; Boolean result = expressionEvaluator.getValue(expr, new Holder<>(strArr), Boolean.class); assertFalse(result); }
@Test public void t04_evaluate_equals_non_empty_expression() { String expr = "state == new String[]{'Apple','Google','Facebook','Hewlett Packard', null}"; Boolean result = expressionEvaluator.getValue(expr, new Holder<>(strArr), Boolean.class); assertFalse(result); }
@Test public void t05_evaluate_equals_non_null_expression() { String expr = "state == new String[]{'Apple','Google','Facebook','Hewlett Packard'}"; Boolean result = expressionEvaluator.getValue(expr, new Holder<>(strArr), Boolean.class); assertFalse(result); }
@Test public void t06_evaluate_contains_multiple_or_elements_elements_expression() { String expr = "state!=null && state.?[#this=='Apple' || #this=='Google'] != new String[]{}"; Boolean result = expressionEvaluator.getValue(expr, new Holder<>(strArr), Boolean.class); assertTrue(result); }
@Test public void t07_evaluate_compare_arraylength_expression() { String expr = "state != null && state.length > 2"; Boolean result = expressionEvaluator.getValue(expr, new Holder<>(strArr), Boolean.class); assertTrue(result); }
@Test public void t08a_evaluate_contains_single_element_expression() { String expr = "state != null && state.?[#this=='Apple'] != new String[]{}"; Boolean result = expressionEvaluator.getValue(expr, new Holder<>(strArr), Boolean.class); assertTrue(result); }
@Test public void t08b_evaluate_exatcly_one_single_element_expression() { String expr = "state == new String[]{'Apple'}"; Boolean result = expressionEvaluator.getValue(expr, new Holder<>(new String[]{"Apple"}), Boolean.class); assertTrue(result); }
@Test public void t09_evaluate_invalid_elements_expression() { String expr = "state != null && state.?[#this=='Twitter'] != new String[]{}"; Boolean result = expressionEvaluator.getValue(expr, new Holder<>(strArr), Boolean.class); assertFalse(result); }
@Test public void t10_evaluate_type_mismatch_expression() { String expr = "state != null && state == 'Apple'"; Boolean result = expressionEvaluator.getValue(expr, new Holder<>(strArr), Boolean.class); assertFalse(result); }
@Test public void t12_evaluate_contains_multiple_and_elements_withinvalid_expression() { String expr = "state != null && state.?[#this=='Apple'] != new String[]{} && state.?[#this=='Twitter'] != new String[]{}"; Boolean result = expressionEvaluator.getValue(expr, new Holder<>(strArr), Boolean.class); assertFalse(result); }