### Question:
QueryRDFVisitor implements RDFVisitor<Object, Bindings> { @Override public NODE visit(Constant<?> expr, Bindings bindings) { if (expr.getType().equals(String.class)) { return new LIT(expr.getConstant().toString()); } else if (NODE.class.isAssignableFrom(expr.getType())) { return (NODE) expr.getConstant(); } else { UID datatype = ConverterRegistryImpl.DEFAULT.getDatatype(expr.getType()); String value = ConverterRegistryImpl.DEFAULT.toString(expr.getConstant()); return new LIT(value, datatype); } } QueryRDFVisitor(RDFConnection connection); @Override NODE visit(Constant<?> expr, Bindings bindings); @Override Object visit(FactoryExpression<?> expr, Bindings bindings); @Override Pair<Iterable<Bindings>, Bindings> visit(GraphBlock expr, Bindings bindings); @Override Pair<Iterable<Bindings>, Bindings> visit(GroupBlock expr, Bindings bindings); @SuppressWarnings("unchecked") @Override Object visit(final Operation<?> expr, Bindings bindings); @Override Pair<Iterable<Bindings>, Bindings> visit(OptionalBlock expr, final Bindings bindings); @Override NODE visit(ParamExpression<?> expr, Bindings bindings); @Override NODE visit(Path<?> expr, Bindings bindings); @Override Pair<Iterable<Bindings>, Bindings> visit(final PatternBlock expr, final Bindings bindings); @SuppressWarnings("unchecked") @Override Object visit(QueryMetadata md, QueryLanguage<?, ?> queryType); @Override Object visit(SubQueryExpression<?> expr, Bindings bindings); @Override Object visit(TemplateExpression<?> expr, Bindings bindings); @SuppressWarnings("unchecked") @Override Pair<? extends Iterable<Bindings>, Bindings> visit(UnionBlock expr, Bindings bindings);  }### Answer:
@Test public void PatternBlock() { Iterable<Bindings> iterable = visitor.visit((PatternBlock) Blocks.SPO, context).getFirst(); List<Bindings> rows = IteratorAdapter.asList(iterable.iterator()); assertEquals(2, rows.size()); assertEquals(3, rows.get(0).toMap().size()); assertEquals(3, rows.get(1).toMap().size()); assertEquals(id, rows.get(0).get("s")); assertEquals(id, rows.get(1).get("s")); }
@Test public void PatternBlock_with_unmatching_Filter() { GroupBlock block = (GroupBlock) Blocks.filter(Blocks.SPO, QNODE.p.eq(RDF.predicate)); Iterable<Bindings> iterable = visitor.visit(block, context).getFirst(); List<Bindings> rows = IteratorAdapter.asList(iterable.iterator()); assertEquals(0, rows.size()); }
@Test public void PatternBlock_with_Filter() { GroupBlock block = (GroupBlock) Blocks.filter(Blocks.SPO, QNODE.p.eq(RDF.type)); Iterator<Bindings> iterator = visitor.visit(block, context).getFirst().iterator(); Map<String, NODE> row = iterator.next().toMap(); assertFalse(iterator.hasNext()); assertEquals(3, row.size()); assertEquals(id, row.get("s")); assertEquals(RDF.type, row.get("p")); }