TripleSubjectFunction implements Function { @Override public Value evaluate(ValueFactory vf, Value... args) throws ValueExprEvaluationException { if (args.length != 1) { throw new ValueExprEvaluationException("expect exactly 1 argument"); } if (!(args[0] instanceof Triple)) { throw new ValueExprEvaluationException("arg1 must be a Triple"); } return ((Triple) args[0]).getSubject(); }  @Override String getURI(); @Override Value evaluate(ValueFactory vf, Value... args);  }
@Test public void testEvaluateWithTriple() { IRI subj = f.createIRI("urn:a"); IRI pred = f.createIRI("urn:b"); IRI obj = f.createIRI("urn:c"); Triple testValue = f.createTriple(subj, pred, obj); Value value = function.evaluate(f, testValue); assertNotNull(value); assertTrue("expect IRI", value instanceof IRI); assertEquals("expect same value", subj, value); }
@Test(expected = ValueExprEvaluationException.class) public void testNegativeWrongArguments() { IRI subj = f.createIRI("urn:a"); IRI pred = f.createIRI("urn:b"); IRI obj = f.createIRI("urn:c"); Triple testValue = f.createTriple(subj, pred, obj); function.evaluate(f, testValue, subj); fail("expect ValueExprEvaluationException"); }
@Test(expected = ValueExprEvaluationException.class) public void testWrongArguments() { IRI subj = f.createIRI("urn:a"); function.evaluate(f, subj); fail("expect ValueExprEvaluationException"); }