### Question:
Concat implements Function { @Override public Literal evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { if (args.length == 0) { throw new ValueExprEvaluationException("CONCAT requires at least 1 argument, got " + args.length); } StringBuilder concatBuilder = new StringBuilder(); String commonLanguageTag = null; boolean useLanguageTag = true; for (Value arg : args) { if (arg instanceof Literal) { Literal lit = (Literal) arg; if (!QueryEvaluationUtil.isStringLiteral(lit)) { throw new ValueExprEvaluationException("unexpected datatype for CONCAT operand: " + lit); } if (useLanguageTag && Literals.isLanguageLiteral(lit)) { if (commonLanguageTag == null) { commonLanguageTag = lit.getLanguage().get(); } else if (!commonLanguageTag.equals(lit.getLanguage().orElse(null))) { commonLanguageTag = null; useLanguageTag = false; } } else { useLanguageTag = false; } concatBuilder.append(lit.getLabel()); } else { throw new ValueExprEvaluationException("unexpected argument type for CONCAT operator: " + arg); } } Literal result = null; if (useLanguageTag) { result = valueFactory.createLiteral(concatBuilder.toString(), commonLanguageTag); } else { result = valueFactory.createLiteral(concatBuilder.toString()); } return result; }  @Override String getURI(); @Override Literal evaluate(ValueFactory valueFactory, Value... args);  }### Answer:
@Test public void stringLiteralHandling() { Literal result = concatFunc.evaluate(vf, foo, bar); assertThat(result.stringValue()).isEqualTo("foobar"); assertThat(result.getDatatype()).isEqualTo(XMLSchema.STRING); assertThat(result.getLanguage().isPresent()).isFalse(); }
@Test public void mixedLanguageLiteralHandling() { Literal result = concatFunc.evaluate(vf, foo_nl, bar_en); assertThat(result.stringValue()).isEqualTo("foobar"); assertThat(result.getDatatype()).isEqualTo(XMLSchema.STRING); assertThat(result.getLanguage().isPresent()).isFalse(); }
@Test public void mixedLiteralHandling() { Literal result = concatFunc.evaluate(vf, foo, bar_en); assertThat(result.stringValue()).isEqualTo("foobar"); assertThat(result.getDatatype()).isEqualTo(XMLSchema.STRING); assertThat(result.getLanguage().isPresent()).isFalse(); }
@Test public void stringLiteralHandling() { Literal result = concatFunc.evaluate(vf, foo, bar); assertThat(result.stringValue()).isEqualTo("foobar"); assertThat(result.getDatatype()).isEqualTo(XSD.STRING); assertThat(result.getLanguage().isPresent()).isFalse(); }
@Test public void commonLanguageLiteralHandling() { Literal result = concatFunc.evaluate(vf, foo_en, bar_en); assertThat(result.stringValue()).isEqualTo("foobar"); assertThat(result.getDatatype()).isEqualTo(RDF.LANGSTRING); assertThat(result.getLanguage().get()).isEqualTo("en"); }
@Test public void mixedLanguageLiteralHandling() { Literal result = concatFunc.evaluate(vf, foo_nl, bar_en); assertThat(result.stringValue()).isEqualTo("foobar"); assertThat(result.getDatatype()).isEqualTo(XSD.STRING); assertThat(result.getLanguage().isPresent()).isFalse(); }
@Test public void mixedLiteralHandling() { Literal result = concatFunc.evaluate(vf, foo, bar_en); assertThat(result.stringValue()).isEqualTo("foobar"); assertThat(result.getDatatype()).isEqualTo(XSD.STRING); assertThat(result.getLanguage().isPresent()).isFalse(); }
@Test public void nonStringLiteralHandling() { try { concatFunc.evaluate(vf, RDF.TYPE, BooleanLiteral.TRUE); fail("CONCAT expected to fail on non-stringliteral argument"); } catch (ValueExprEvaluationException e) { } }
@Test public void nonLiteralHandling() { try { concatFunc.evaluate(vf, RDF.TYPE, bar_en); fail("CONCAT expected to fail on non-literal argument"); } catch (ValueExprEvaluationException e) { } }