### Question:
JsonCoercingUtil { public static Object parseLiteral(Object input, Map<String, Object> variables) throws CoercingParseLiteralException { if (!(input instanceof Value)) { log.error("Expected 'Value', got: {}", input); throw new CoercingParseLiteralException("Expected 'Value', got: " + input); } Object result = null; if (input instanceof StringValue) { result = ((StringValue) input).getValue(); } else if (input instanceof IntValue) { result = ((IntValue) input).getValue(); } else if (input instanceof FloatValue) { result = ((FloatValue) input).getValue(); } else if (input instanceof BooleanValue) { result = ((BooleanValue) input).isValue(); } else if (input instanceof EnumValue) { result = ((EnumValue) input).getName(); } else if (input instanceof VariableReference) { result = variables.get(((VariableReference) input).getName()); } else if (input instanceof ArrayValue) { result = ((ArrayValue) input).getValues().stream() .map(v -> parseLiteral(v, variables)) .collect(toList()); } else if (input instanceof ObjectValue) { result = ((ObjectValue) input).getObjectFields().stream() .collect(toMap(ObjectField::getName, f -> parseLiteral(f.getValue(), variables))); } return result; }  static Object parseLiteral(Object input, Map<String, Object> variables);  }### Answer:
@Test(expected = CoercingParseLiteralException.class) public void notAValue() { JsonCoercingUtil.parseLiteral(null, emptyMap()); }
@Test public void stringValue() { Value value = StringValue.newStringValue("a").build(); Object result = JsonCoercingUtil.parseLiteral(value, emptyMap()); assertThat(result, is("a")); }
@Test public void intValue() { Value value = IntValue.newIntValue(new BigInteger("1")).build(); Object result = JsonCoercingUtil.parseLiteral(value, emptyMap()); assertThat(result, is(new BigInteger("1"))); }
@Test public void floatValue() { Value value = FloatValue.newFloatValue(new BigDecimal("1.2")).build(); Object result = JsonCoercingUtil.parseLiteral(value, emptyMap()); assertThat(result, is(new BigDecimal("1.2"))); }
@Test public void booleanValue() { Value value = BooleanValue.newBooleanValue(true).build(); Object result = JsonCoercingUtil.parseLiteral(value, emptyMap()); assertThat(result, is(true)); }
@Test public void enumValue() { Value value = EnumValue.newEnumValue("a").build(); Object result = JsonCoercingUtil.parseLiteral(value, emptyMap()); assertThat(result, is("a")); }
@Test public void variableReferenceValue() { Value value = VariableReference.newVariableReference().name("a").build(); Object result = JsonCoercingUtil.parseLiteral(value, Map.of("a", "b")); assertThat(result, is("b")); }
@Test public void arrayValue() { Value value = ArrayValue.newArrayValue() .value(StringValue.newStringValue("a").build()) .build(); Object result = JsonCoercingUtil.parseLiteral(value, emptyMap()); assertThat(result, is(List.of("a"))); }
@Test public void objectValue() { Value value = ObjectValue.newObjectValue() .objectField(ObjectField.newObjectField() .name("a") .value(StringValue.newStringValue("b").build()) .build()) .build(); Object result = JsonCoercingUtil.parseLiteral(value, emptyMap()); assertThat(result, is(Map.of("a", "b"))); }