Handlers { public void roots(Object... xpaths) { this.roots.clear(); this.functionRoots = null; for (Object xpath : xpaths) { this.roots.add(xpath.toString()); } } Handlers(FormatterParams fparams, Path schemaDir, Path rootFormatterDir,
                    TemplateCache templateCache); void prepareForTransformer(); void roots(Object... xpaths); @SuppressWarnings("unchecked") void roots(Closure rootFunction); Set<String> getRoots(); void root(Object xpath); SkipElement skip(Object select, Closure childSelector); SkipElement skip(Object select, Closure childSelector, int priority); SkipElement skip(Map<String, Object> properties, Closure handlerFunction); Handler add(String elementName, Closure function); Handler add(Pattern namePattern, Closure function); Handler withPath(Pattern pathPattern, Closure function); Handler add(Closure select, Closure function); Handler add(Map<String, Object> properties, Closure handlerFunction); boolean hasHandlerFor(GPathResult elem); boolean hasHandlerFor(String mode, GPathResult elem); Handler findHandlerFor(GPathResult elem); Handler findHandlerFor(String mode, GPathResult elem); FileResult fileResult(String path, Map<String, Object> model); StartEndHandler start(Closure function); StartEndHandler end(Closure function); Sorter sort(Closure select, Closure sortFunction); Sorter sort(String elemName, Closure sortFunction); Sorter sort(Pattern namePattern, Closure sortFunction); Sorter sortPathMatcher(Pattern pathSelect, Closure sortFunction); Sorter sort(Map<String, Object> properties, Closure handlerFunction); Mode mode(String id); Mode mode(String id, String fallback); Mode findMode(String id); String processElements(Iterable selection); String processElements(Iterable selection, GPathResult sortByElement); String processElementsInMode(String mode, Iterable selection); String processElementsInMode(String mode, Iterable selection, GPathResult sortByElement); List<SkipElement> getSkipElements();  }
@Test public void testRoots() throws Exception { final Handlers handlers = new Handlers(new FormatterParams(), null, null, null); handlers.roots("root1", "root2"); Assert.assertArrayEquals(new String[]{"root1", "root2"}, sort(handlers.getRoots().toArray())); handlers.root("newroot"); Assert.assertArrayEquals(new String[]{"newroot", "root1", "root2"}, sort(handlers.getRoots().toArray())); handlers.root(new GStringImpl(new Object[0], new String[]{"newroot2"})); Assert.assertArrayEquals(new String[]{"newroot", "newroot2", "root1", "root2"}, sort(handlers.getRoots().toArray())); handlers.roots("root1", new GStringImpl(new Object[0], new String[]{"root2"})); Assert.assertArrayEquals(new Object[]{"root1", "root2"}, sort(handlers.getRoots().toArray())); handlers.roots(new Closure(handlers) { @Override public Object call() { return Lists.newArrayList("cr1", "cr2"); } @Override public Object call(Object arguments) { return call(); } }); Assert.assertArrayEquals(new String[]{"cr1", "cr2"}, sort(handlers.getRoots().toArray())); handlers.roots(new Closure(handlers) { @Override public Object call() { return Lists.newArrayList(new GStringImpl(new Object[0], new String[]{"gr1"})); } @Override public Object call(Object arguments) { return call(); } }); Assert.assertArrayEquals(new String[]{"gr1"}, sort(handlers.getRoots().toArray())); }