### Question:
GetTemplateValue implements Function<EvaluateExpression, Optional<Object>> { @Override public Optional<Object> apply(EvaluateExpression evaluateExpression) { if (LOG.isTraceEnabled()) { LOG.trace("Processing template: {}", template.toTemplateString()); } Template.Builder templateBuilder = template.newBuilder(); expressions.forEach(e -> bindTemplateExpression(e, evaluateExpression, templateBuilder)); return templateBuilder.create(); } GetTemplateValue(
		Template template,
		Set<Expression> expressions,
		Function<String, String> transformValue,
		Function<Object, String> createNaturalRdfLexicalForm
	); @Override Optional<Object> apply(EvaluateExpression evaluateExpression);  }### Answer:
@Test public void getTemplateValue_givenValidInputAndFindingValue_performsAsExpected() { when(evaluateExpression.apply("xyz")).thenReturn(Optional.of("evaluated")); when(createNaturalRdfLexicalForm.apply("evaluated")).thenReturn("natural"); when(transformValue.apply("natural")).thenReturn("transformed"); Template template = TemplateParser.build().parse("abc{xyz}"); GetTemplateValue getTemplateValue = new GetTemplateValue( template, template.getExpressions(), transformValue, createNaturalRdfLexicalForm ); Optional<Object> templateValue = getTemplateValue.apply(evaluateExpression); String result = unpackTemplateValue(templateValue); assertThat(result, is("abctransformed")); }
@Test public void getTemplateValue_givenValidInputWithMultipleExpressions_performsAsExpected() { when(evaluateExpression.apply("xyz")).thenReturn(Optional.of("evaluated")); when(createNaturalRdfLexicalForm.apply("evaluated")).thenReturn("natural"); when(transformValue.apply("natural")).thenReturn("transformed"); Template template = TemplateParser.build().parse("abc{xyz}{xyz}"); GetTemplateValue getTemplateValue = new GetTemplateValue( template, template.getExpressions(), transformValue, createNaturalRdfLexicalForm ); Optional<Object>templateValue = getTemplateValue.apply(evaluateExpression); String result = unpackTemplateValue(templateValue); assertThat(result, is("abctransformedtransformed")); }
@Test public void getTemplateValue_givenValidInputAndNotFindingValue_returnsNoValues() { when(evaluateExpression.apply("xyz")).thenReturn(Optional.empty()); Template template = TemplateParser.build().parse("abc{xyz}"); GetTemplateValue getTemplateValue = new GetTemplateValue( template, template.getExpressions(), transformValue, createNaturalRdfLexicalForm ); Optional<Object> templateValue = getTemplateValue.apply(evaluateExpression); assertThat(templateValue, is(Optional.empty())); }