StatementPatternMatcher { private boolean matchesContext(@Nullable final Var cntxVar, @Nullable final Value stmtCntx, final QueryBindingSet bs) { if(cntxVar == null) { return true; } else if(stmtCntx == null) { return false; } else { return matchesValue(cntxVar, stmtCntx, bs); } } StatementPatternMatcher(final StatementPattern pattern); Optional<BindingSet> match(final Statement statement);  }
@Test public void matchesContext() throws Exception { final StatementPatternMatcher matcher = new StatementPatternMatcher(getSp( "SELECT * WHERE {" + "GRAPH <urn:testGraph> {" + "?s ?p ?o ." + "}" + "}")); final ValueFactory vf = SimpleValueFactory.getInstance(); final Statement statement = vf.createStatement(vf.createIRI("urn:Alice"), vf.createIRI("urn:talksTo"), vf.createIRI("urn:Bob"), vf.createIRI("urn:testGraph")); final QueryBindingSet expected = new QueryBindingSet(); expected.addBinding("s", vf.createIRI("urn:Alice")); expected.addBinding("p", vf.createIRI("urn:talksTo")); expected.addBinding("o", vf.createIRI("urn:Bob")); final Optional<BindingSet> bs = matcher.match(statement); assertEquals(expected, bs.get()); }