    @Test
    public void testRewriteFinal() throws Exception {

        Node ruleNode = context.resourceResolver().getResource(RULES_PATH + "/rewriteFinal").adaptTo(Node.class);
        Node rootNode = context.resourceResolver().getResource(ROOTS_PATH + "/simple").adaptTo(Node.class);

        NodeBasedRewriteRule rule = new NodeBasedRewriteRule(ruleNode);
        Set<Node> finalNodes = new LinkedHashSet<Node>();

        rule.applyTo(rootNode, finalNodes);

        Node[] finalNodesArray = finalNodes.toArray(new Node[0]);

        assertEquals(1, finalNodesArray.length);
        assertEquals("simple", finalNodesArray[0].getName());
    }