### Question:
SubstitutionExpression extends AbstractExpression { @Override public Object readValue(final EvaluationContext context) { return readValue(context, TypedValue.class).value(); } SubstitutionExpression(final String original);  SubstitutionExpression(final String original,
                                  final int startIndex,
                                  final int endIndex,
                                  final Expression replacement); void addReplacement(final int startIndex,
                               final int endIndex,
                               final Expression replacement); void addReplacement(final ReplacementExpression expression); @Override Object readValue(final EvaluationContext context); @Override T readValue(final EvaluationContext context, final Class<T> expectedType); void writeValue(final Object value, final EvaluationContext context); @Override boolean canWrite(); TreeSet<ReplacementExpression> getReplacements(); @Override String toString();  }### Answer:
@Test public void testGivenSingleExpressionReplacement() { SubstitutionExpression expression = new SubstitutionExpression( DEFAULT_EXPRESSION_STRING, 0, DEFAULT_EXPRESSION_STRING.length(), DEFAULT_EXPRESSION); TypedValue evaluated = expression.readValue(context, TypedValue.class); assertNotNull(evaluated); assertEquals(Type.STRING, evaluated.type()); assertEquals(EVALUATED_VALUE, evaluated.getString()); }
@Test public void testGivenPrefixedExpressionWithReplacement() { final int startIndex = PREFIX.length(); SubstitutionExpression expression = new SubstitutionExpression(PREFIX + DEFAULT_EXPRESSION_STRING, startIndex, startIndex + DEFAULT_EXPRESSION_STRING.length(), DEFAULT_EXPRESSION); TypedValue evaluated = expression.readValue(context, TypedValue.class); assertNotNull(evaluated); assertEquals(Type.STRING, evaluated.type()); assertEquals(PREFIX + EVALUATED_VALUE, evaluated.getString()); }
@Test public void testGivenSuffixedExpressionWithReplacement() { final int startIndex = 0; final int endIndex = DEFAULT_EXPRESSION_STRING.length(); SubstitutionExpression expression = new SubstitutionExpression(DEFAULT_EXPRESSION_STRING + SUFFIX, startIndex, endIndex, DEFAULT_EXPRESSION); TypedValue evaluated = expression.readValue(context, TypedValue.class); assertNotNull(evaluated); assertEquals(Type.STRING, evaluated.type()); assertEquals(EVALUATED_VALUE + SUFFIX, evaluated.getString()); }
@Test public void testGivenBetweenExpressionWithReplacement() { final String original = PREFIX + DEFAULT_EXPRESSION_STRING + SUFFIX; SubstitutionExpression expression = new SubstitutionExpression(original, PREFIX.length(), PREFIX.length() + DEFAULT_EXPRESSION_STRING.length(), DEFAULT_EXPRESSION); TypedValue evaluated = expression.readValue(context, TypedValue.class); assertNotNull(evaluated); assertEquals(Type.STRING, evaluated.type()); assertEquals(PREFIX + EVALUATED_VALUE + SUFFIX, evaluated.getString()); }