ConstructHandler implements Handler { @Override public void setVars(Map<Var, Node> values) { if (values.isEmpty()) { return; } AbstractRewriter<Node> rw = new AbstractRewriter<Node>(values) { }; query.setConstructTemplate(new Template(BasicPattern.wrap(rw .rewrite(constructs)))); } ConstructHandler(Query query); void addConstruct(Triple t); void addAll(ConstructHandler handler); @Override void setVars(Map<Var, Node> values); @Override void build();  }
@Test public void testSetVars() { Var v = Var.alloc("v"); Triple t = new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), v); handler.addConstruct(t); Template template = query.getConstructTemplate(); assertNotNull(template); List<Triple> lst = template.getTriples(); assertEquals(1, lst.size()); assertEquals(t, lst.get(0)); Map<Var, Node> values = new HashMap<>(); values.put(v, NodeFactory.createURI("three")); handler.setVars(values); template = query.getConstructTemplate(); assertNotNull(template); lst = template.getTriples(); assertEquals(1, lst.size()); t = new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three")); assertEquals(t, lst.get(0)); }