@Test
  public void exampleQuery() throws Exception {
    // START SNIPPET: JavaQuery
    ExecutionEngine engine = new ExecutionEngine(db);
    ExecutionResult result = engine.execute("start n=node(0) where 1=1 return n");

    assertThat(result.columns(), hasItem("n"));
    Iterator<Node> n_column = result.columnAs("n");
    assertThat(asIterable(n_column), hasItem(db.getNodeById(0)));
    assertThat(result.toString(), containsString("Node[0]"));
    // END SNIPPET: JavaQuery
  }
  @Test
  public void exampleWithParameterForNodeObject() throws Exception {
    // START SNIPPET: exampleWithParameterForNodeObject
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("node", andreasNode);
    ExecutionResult result = engine.execute("start n=node({node}) return n.name", params);
    // END SNIPPET: exampleWithParameterForNodeObject

    assertThat(result.columns(), hasItem("n.name"));
    Iterator<Object> n_column = result.columnAs("n.name");
    assertEquals("Andreas", n_column.next());
  }
  @Test
  public void shouldBeAbleToEmitJavaIterables() throws Exception {
    makeFriends(michaelaNode, andreasNode);
    makeFriends(michaelaNode, johanNode);

    ExecutionEngine engine = new ExecutionEngine(db);

    ExecutionResult result =
        engine.execute("start n=node(0) match n-->friend return collect(friend)");

    Iterable<Node> friends = (Iterable<Node>) result.columnAs("collect(friend)").next();
    assertThat(friends, hasItems(andreasNode, johanNode));
    assertThat(friends, instanceOf(Iterable.class));
  }
  @Test
  public void exampleWithParameterRegularExpression() throws Exception {
    // START SNIPPET: exampleWithParameterRegularExpression
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("regex", ".*h.*");
    ExecutionResult result =
        engine.execute("start n=node(0,1,2) where n.name =~ {regex} return n.name", params);
    // END SNIPPET: exampleWithParameterRegularExpression

    assertThat(result.columns(), hasItem("n.name"));
    Iterator<Object> n_column = result.columnAs("n.name");
    assertEquals("Michaela", n_column.next());
    assertEquals("Johan", n_column.next());
  }
  @Test
  public void exampleWithParameterForSkipAndLimit() throws Exception {
    // START SNIPPET: exampleWithParameterForSkipLimit
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("s", 1);
    params.put("l", 1);
    ExecutionResult result =
        engine.execute("start n=node(0,1,2) return n.name skip {s} limit {l}", params);
    // END SNIPPET: exampleWithParameterForSkipLimit

    assertThat(result.columns(), hasItem("n.name"));
    Iterator<Object> n_column = result.columnAs("n.name");
    assertEquals("Andreas", n_column.next());
  }
 private <T> List<T> toList(ExecutionResult result, String column) {
   List<T> results = new ArrayList<T>();
   IteratorUtil.addToCollection(result.<T>columnAs(column), results);
   return results;
 }