### Question:
ExpressionEvaluator { public Object evaluate(String expressionString) { try { return expressionCache.computeIfAbsent(expressionString, this::parse).getValue(evaluationContext); } catch (EvaluationException e) { return expressionString; } } ExpressionEvaluator(ExpressionParser expressionParser,
                               EvaluationContext evaluationContext); Object evaluate(String expressionString); Object evaluate(String expressionString, Object rootObject);  }### Answer:
@Test public void evaluateWithArgument() { String string = "publicField.length()"; Argument argument = new Argument(); Object result = expressionEvaluator.evaluate(string, argument); assertThat(result, is(6)); }
@Test public void evaluateWithArgumentError() { String string = "privateField.length()"; Argument argument = new Argument(); Object result = expressionEvaluator.evaluate(string, argument); assertThat(result, is("privateField.length()")); }
@Test public void evaluateWithArgumentNull() { String string = "null"; Argument argument = new Argument(); Object result = expressionEvaluator.evaluate(string, argument); assertThat(result, nullValue()); }
@Test public void evaluateWithArgumentNullArgument() { String string = "field.length()"; Argument argument = null; Object result = expressionEvaluator.evaluate(string, argument); assertThat(result, nullValue()); }
@Test public void evaluateWithBeanReferencing() { StandardEvaluationContext evaluationContext = new StandardEvaluationContext(); evaluationContext.setBeanResolver(new BeanFactoryResolver(applicationContext)); ExpressionEvaluator expressionEvaluator = new ExpressionEvaluator(expressionParser, evaluationContext); String string = "@string.toString()"; Object result = expressionEvaluator.evaluate(string); assertThat(result, is("bean string")); }
@Test public void evaluateWithArgumentAndBeanReferencing() { StandardEvaluationContext evaluationContext = new StandardEvaluationContext(); evaluationContext.setBeanResolver(new BeanFactoryResolver(applicationContext)); ExpressionEvaluator expressionEvaluator = new ExpressionEvaluator(expressionParser, evaluationContext); String string = "@string.toString()"; Argument argument = new Argument(); Object result = expressionEvaluator.evaluate(string, argument); assertThat(result, is("bean string")); }
@Test public void evaluateToString() { StandardEvaluationContext evaluationContext = new StandardEvaluationContext(); evaluationContext.setBeanResolver(new BeanFactoryResolver(applicationContext)); ExpressionEvaluator expressionEvaluator = new ExpressionEvaluator(expressionParser, evaluationContext); String string = "toString()"; String string2 = "#this"; String string3 = "#root"; Argument argument = new Argument(); Object result = expressionEvaluator.evaluate(string, argument); Object result2 = expressionEvaluator.evaluate(string2, argument); Object result3 = expressionEvaluator.evaluate(string3, argument); assertThat(result, is("!")); assertThat(result2, is(argument)); assertThat(result3, is(argument)); }
@Test public void evaluateChangeValue() { String string = "publicField = '123'"; Argument argument = new Argument(); Object result = expressionEvaluator.evaluate(string, argument); assertThat(result, is("123")); assertThat(argument.getPublicField(), is("123")); }
@Test public void evaluate() { String string = "1 + 1"; Object result = expressionEvaluator.evaluate(string); assertThat(result, is(2)); }
@Test public void evaluateNull() { String string = "null"; Object result = expressionEvaluator.evaluate(string); assertThat(result, nullValue()); }
@Test public void evaluateString() { String string = "'string'"; Object result = expressionEvaluator.evaluate(string); assertThat(result, is("string")); }
@Test public void evaluateAsIs() { String string = "string as is"; Object result = expressionEvaluator.evaluate(string); assertThat(result, is("string as is")); }