### Question:
ComponentRewriteRuleServiceImpl implements ComponentRewriteRuleService { public List<ComponentRewriteRule> getRules(ResourceResolver resolver) throws RepositoryException { final List<ComponentRewriteRule> rules = new LinkedList<>(); synchronized (this.rules) { rules.addAll(this.rules); } int jb = rules.size(); Resource resource = resolver.getResource(RULES_SEARCH_PATH); if (resource != null) { 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 NodeBasedComponentRewriteRule(nestedNode)); } } } else { rules.add(new NodeBasedComponentRewriteRule(nextNode)); } } } Collections.sort(rules, new ComponentRewriteRuleServiceImpl.RuleComparator()); logger.debug("Found {} rules ({} Java-based, {} node-based)", rules.size(), jb, rules.size() - jb); if (logger.isDebugEnabled()) { for (ComponentRewriteRule rule : rules) { logger.debug(rule.toString()); } } return rules; }  @SuppressWarnings("unused") void bindRule(ComponentRewriteRule rule); @SuppressWarnings("unused") void unbindRule(ComponentRewriteRule rule); List<ComponentRewriteRule> getRules(ResourceResolver resolver); @Override Set<String> getSlingResourceTypes(ResourceResolver resolver); static final String RULES_SEARCH_PATH; }### Answer:
@Test public void testGetRules() throws Exception { List<String> expectedRulePaths = new ArrayList<>(); expectedRulePaths.addAll(Arrays.asList( RULES_PATH + "/rewriteRanking", RULES_PATH + "/simple", RULES_PATH + "/copyChildren", RULES_PATH + "/copyChildrenOrder", RULES_PATH + "/mapProperties", RULES_PATH + "/rewriteOptional", RULES_PATH + "/rewriteMapChildren", RULES_PATH + "/rewriteFinal", RULES_PATH + "/rewriteFinalOnReplacement", RULES_PATH + "/rewriteProperties", RULES_PATH + "/nested1/rule1", RULES_PATH + "/nested1/rule2", RULES_PATH + "/nested2/rule1")); List<ComponentRewriteRule> rules = componentRewriteRuleService.getRules(context.resourceResolver()); assertEquals(expectedRulePaths.size(), rules.size()); int index = 0; for (ComponentRewriteRule rule : rules) { String path = expectedRulePaths.get(index); assertTrue(rule.toString().contains("path=" + path + ",")); index++; } }