### Question:
JsonValues { public static JsonValue evaluateJsonStaticExpression(final JsonValue value) { return new JsonValue(value, singleton(EXPRESSION_TRANSFORMER)); } private  JsonValues(); static Class<?> asClass(JsonValue value); @SuppressWarnings("unchecked") static T asNewInstance(JsonValue value, Class<T> type); static Expression<T> asExpression(JsonValue value, Class<T> expectedType); static String evaluate(JsonValue value); static JsonValue evaluate(final JsonValue value, final Logger logger); static JsonValue evaluateJsonStaticExpression(final JsonValue value); static JsonValue firstOf(final JsonValue config, final String... names); static Function<JsonValue, Expression<String>, HeapException> ofExpression(); static Function<JsonValue, T, HeapException> ofRequiredHeapObject(final Heap heap,
                                                                                 final Class<T> type); static Function<JsonValue, T, HeapException> ofEnum(final Class<T> enumType); static JsonValue getWithDeprecation(JsonValue config, Logger logger, String name,
            String... deprecatedNames); static void warnForDeprecation(final JsonValue config, final Logger logger,
            final String name, final String deprecatedName);  }### Answer:
@Test public void shouldEvaluateLeafJsonValueWithExpression() throws Exception { JsonValue value = new JsonValue("${true} is good"); JsonValue transformed = evaluateJsonStaticExpression(value); assertThat(transformed.asString()).isEqualTo("true is good"); assertThat(transformed).isNotSameAs(value); }
@Test public void shouldLeaveUnchangedLeafJsonValueWithNoExpression() throws Exception { JsonValue value = new JsonValue("remains the same"); JsonValue transformed = evaluateJsonStaticExpression(value); assertThat(transformed.asString()).isEqualTo("remains the same"); assertThat(transformed).isNotSameAs(value); }
@Test public void shouldIgnoreNonStringValues() throws Exception { JsonValue intValue = new JsonValue(42); assertThat(evaluateJsonStaticExpression(intValue).asInteger()).isEqualTo(42); JsonValue nullValue = new JsonValue(null); assertThat(evaluateJsonStaticExpression(nullValue).getObject()).isNull(); JsonValue booleanValue = new JsonValue(true); assertThat(evaluateJsonStaticExpression(booleanValue).asBoolean()).isTrue(); JsonValue listValue = json(array("one", "two", "${three}")); assertThat(evaluateJsonStaticExpression(listValue).asList(String.class)) .containsExactly("one", "two", "${three}"); JsonValue mapValue = json(object(field("one", 1), field("two", 2L), field("three", "${three}"))); assertThat(evaluateJsonStaticExpression(mapValue).asMap()) .containsExactly(entry("one", 1), entry("two", 2L), entry("three", "${three}")); }
@Test public void shouldEvaluateExpressionToRealType() throws Exception { assertThat(evaluateJsonStaticExpression(json("${1 == 1}")).isBoolean()).isTrue(); assertThat(evaluateJsonStaticExpression(json("${8 * 5 + 2}")).asInteger()).isEqualTo(42); assertThat(evaluateJsonStaticExpression(json("${join(array('foo', 'bar', 'quix'), '@')}")).asString()) .isEqualTo("foo@bar@quix"); }
@Test(expectedExceptions = JsonException.class, expectedExceptionsMessageRegExp = "Expression 'incorrect \\$\\{expression' " + "\\(in /one\\) is not syntactically correct") public void shouldFailForIncorrectValueExpression() throws Exception { JsonValue mapValue = json(object(field("one", "incorrect ${expression"))); evaluateJsonStaticExpression(mapValue.get("one")); }