### Question:
XPathResolver implements LogicalSourceResolver<XdmItem> { @Override public ExpressionEvaluatorFactory<XdmItem> getExpressionEvaluatorFactory() { return entry -> expression -> { try { XPathSelector selector = xpath.compile(expression).load(); selector.setContextItem(entry); XdmValue value = selector.evaluate(); if (value.size() > 1) { List<String> results = new ArrayList<>(); value.forEach(i -> { String sValue = getItemStringValue(i, value); if (sValue != null) { results.add(sValue); } } ); return Optional.of(results); } else if (value.size() == 0) { return Optional.empty(); } XdmItem item = value.itemAt(0); return Optional.ofNullable(getItemStringValue(item, value)); } catch (SaxonApiException e) { throw new RuntimeException(String.format( "Error applying XPath expression [%s] to entry [%s]", entry, expression), e); } }; } XPathResolver();  XPathResolver(boolean autoNodeTextExtraction); boolean autoExtractsNodeText(); @Override SourceIterator<XdmItem> getSourceIterator(); @Override ExpressionEvaluatorFactory<XdmItem> getExpressionEvaluatorFactory();  }### Answer:
@Test public void expressionEvaluator_givenExpression_shoulReturnCorrectValue() { String expression = "./author/lower-case(.)"; ExpressionEvaluatorFactory<XdmItem> evaluatorFactory = xpathResolver.getExpressionEvaluatorFactory(); EvaluateExpression evaluateExpression = evaluatorFactory.apply(nodes.get(0)); assertThat(evaluateExpression.apply(expression).get(), is("giada de laurentiis")); }
@Test public void expressionEvaluatorWithoutAutoTextExtraction_givenExpression_shoulReturnCorrectValue() { String expression = "./author"; ExpressionEvaluatorFactory<XdmItem> evaluatorFactory = xpathResolver.getExpressionEvaluatorFactory(); EvaluateExpression evaluateExpression = evaluatorFactory.apply(nodes.get(0)); assertThat(evaluateExpression.apply(expression).get(), is("Giada De Laurentiis")); boolean autoExtractNodeText = false; xpathResolver = new XPathResolver(autoExtractNodeText); nodeIterator = xpathResolver.bindSource(LSOURCE, sourceResolver).get(); evaluatorFactory = xpathResolver.getExpressionEvaluatorFactory(); nodes = Lists.newArrayList(nodeIterator); evaluateExpression = evaluatorFactory.apply(nodes.get(0)); assertThat(evaluateExpression.apply(expression).get(), is("<author>Giada De Laurentiis</author>")); }
@Test public void expressionEvaluator_givenExpressionWithNamespace_shoulReturnCorrectValue() { Set<TriplesMap> mapping = RmlMappingLoader .build() .load(RDFFormat.TURTLE, XPathResolverTest.class.getResourceAsStream("xmlns.rml.ttl")); TriplesMap tMap = Iterables.getOnlyElement(mapping); LogicalSource lSource = tMap.getLogicalSource(); xpathResolver = new XPathResolver(); nodeIterator = xpathResolver.bindSource(lSource, nsSourceResolver).get(); nodes = Lists.newArrayList(nodeIterator); String expression = "./ex:author/lower-case(.)"; ExpressionEvaluatorFactory<XdmItem> evaluatorFactory = xpathResolver.getExpressionEvaluatorFactory(); EvaluateExpression evaluateExpression = evaluatorFactory.apply(nodes.get(0)); assertThat(evaluateExpression.apply(expression).get(), is("j k. rowling")); }