MockNode node1 = new MockNode("/node1");
MockNode node2 = new MockNode("/node2");
node1.addNode("node3");
node1.setProperty("name", "node1");
node2.setProperty("name", "node2");
final NodeIterator it = new MockNodeIterator(new Node[]{node1, node2});
final StringWriter sw = new StringWriter();
writer.dump(it, sw);
Pattern testPattern = Pattern.compile("\\{(.[^\\}]*)\\}"); // Pattern to look for a {...}
Matcher matcher = testPattern.matcher(sw.toString());
assertTrue("Did not produce a JSON object", matcher.find()); // Find first JSON object