### Question:
DialogConversionServlet extends SlingAllMethodsServlet { private List<DialogRewriteRule> getRules(ResourceResolver resolver) throws ServletException { final List<DialogRewriteRule> rules = new LinkedList<DialogRewriteRule>(); synchronized (this.rules) { rules.addAll(this.rules); } int nb = rules.size(); Resource resource = resolver.getResource(RULES_SEARCH_PATH); if (resource != null) { try { Node rulesContainer = resource.adaptTo(Node.class); NodeIterator iterator = rulesContainer.getNodes(); while (iterator.hasNext()) { Node nextNode = iterator.nextNode(); if (isFolder(nextNode)) { NodeIterator nodeIterator = nextNode.getNodes(); while (nodeIterator.hasNext()) { Node nestedNode = nodeIterator.nextNode(); if (!isFolder(nestedNode)) { rules.add(new NodeBasedDialogRewriteRule(nestedNode)); } } } else { rules.add(new NodeBasedDialogRewriteRule(nextNode)); } } } catch (RepositoryException e) { throw new ServletException("Caught exception while collecting rewrite rules", e); } } Collections.sort(rules, new RuleComparator()); logger.debug("Found {} rules ({} Java-based, {} node-based)", nb, rules.size() - nb); for (DialogRewriteRule rule : rules) { logger.debug(rule.toString()); } return rules; }  @SuppressWarnings("unused") void bindRule(DialogRewriteRule rule); @SuppressWarnings("unused") void unbindRule(DialogRewriteRule rule); static final String RULES_SEARCH_PATH; static final String PARAM_PATHS; }### Answer:
@Test public void testGetRules() throws Exception { List<String> expectedRulePaths = new ArrayList<String>(); expectedRulePaths.addAll(Arrays.asList( RULES_PATH + "/rewriteRanking", RULES_PATH + "/simple", RULES_PATH + "/rewriteOptional", RULES_PATH + "/rewriteFinal", RULES_PATH + "/rewriteFinalOnReplacement", RULES_PATH + "/rewriteMapChildren", RULES_PATH + "/rewriteCommonAttrs", RULES_PATH + "/rewriteCommonAttrsData", RULES_PATH + "/rewriteRenderCondition", RULES_PATH + "/mapProperties", RULES_PATH + "/rewriteProperties", RULES_PATH + "/nested1/rule1", RULES_PATH + "/nested1/rule2", RULES_PATH + "/nested2/rule1")); Class[] cArgs = new Class[1]; cArgs[0] = ResourceResolver.class; Method method = dialogConversionServlet.getClass().getDeclaredMethod("getRules", cArgs); method.setAccessible(true); Object[] args = new Object[1]; args[0] = context.resourceResolver(); List<DialogRewriteRule> rules = (List<DialogRewriteRule>) method.invoke(dialogConversionServlet, args); assertEquals(expectedRulePaths.size(), rules.size()); int index = 0; for (DialogRewriteRule rule : rules) { String path = expectedRulePaths.get(index); assertTrue(rule.toString().contains("path=" + path + ",")); index++; } }