### Question:
GraphExtractionWriter implements ResultDataContentWriter { @Override public void write( JsonGenerator out, Iterable<String> columns, Result.ResultRow row, TransactionStateChecker txStateChecker ) throws IOException { Set<Node> nodes = new HashSet<>(); Set<Relationship> relationships = new HashSet<>(); extract( nodes, relationships, map( columns, row ) ); out.writeObjectFieldStart( "graph" ); try { writeNodes( out, nodes, txStateChecker ); writeRelationships( out, relationships, txStateChecker ); } finally { out.writeEndObject(); } }  @Override void write( JsonGenerator out, Iterable<String> columns, Result.ResultRow row,
            TransactionStateChecker txStateChecker );  }### Answer:
@Test public void shouldExtractNodesFromRow() throws Exception { Map<String, Object> row = new HashMap<>(); row.put( "n1", n1 ); row.put( "n2", n2 ); row.put( "n3", n3 ); row.put( "other.thing", "hello" ); row.put( "some.junk", 0x0099cc ); JsonNode result = write( row ); assertNodes( result ); assertEquals( "there should be no relationships", 0, result.get( "graph" ).get( "relationships" ).size() ); }
@Test public void shouldExtractRelationshipsFromRowAndNodesFromRelationships() throws Exception { Map<String, Object> row = new HashMap<>(); row.put( "r1", r1 ); row.put( "r2", r2 ); JsonNode result = write( row ); assertNodes( result ); assertRelationships( result ); }
@Test public void shouldExtractPathFromRowAndExtractNodesAndRelationshipsFromPath() throws Exception { Map<String, Object> row = new HashMap<>(); row.put( "p", path( n2, link( r1, n1 ), link( r2, n3 ) ) ); JsonNode result = write( row ); assertNodes( result ); assertRelationships( result ); }
@Test public void shouldExtractGraphFromMapInTheRow() throws Exception { Map<String, Object> row = new HashMap<>(); Map<String, Object> map = new HashMap<>(); row.put( "map", map ); map.put( "r1", r1 ); map.put( "r2", r2 ); JsonNode result = write( row ); assertNodes( result ); assertRelationships( result ); }
@Test public void shouldExtractGraphFromListInTheRow() throws Exception { Map<String, Object> row = new HashMap<>(); List<Object> list = new ArrayList<>(); row.put( "list", list ); list.add( r1 ); list.add( r2 ); JsonNode result = write( row ); assertNodes( result ); assertRelationships( result ); }
@Test public void shouldExtractGraphFromListInMapInTheRow() throws Exception { Map<String, Object> row = new HashMap<>(); Map<String, Object> map = new HashMap<>(); List<Object> list = new ArrayList<>(); map.put( "list", list ); row.put( "map", map ); list.add( r1 ); list.add( r2 ); JsonNode result = write( row ); assertNodes( result ); assertRelationships( result ); }
@Test public void shouldExtractGraphFromMapInListInTheRow() throws Exception { Map<String, Object> row = new HashMap<>(); Map<String, Object> map = new HashMap<>(); List<Object> list = new ArrayList<>(); list.add( map ); row.put( "list", list ); map.put( "r1", r1 ); map.put( "r2", r2 ); JsonNode result = write( row ); assertNodes( result ); assertRelationships( result ); }