public RewriteGroupedCode rewrite(String context) {
        BlockStatementGrouperVisitor visitor =
                new BlockStatementGrouperVisitor(maxMethodLength, parameters);

        visitor.visitStatement(topStatement, context);
        final Map<String, List<String>> groupStrings = visitor.rewrite(rewriter);

        return new RewriteGroupedCode(rewriter.getText(), groupStrings);
    }
@Test
    public void testExtractWhileInIfGroups() {
        String parameters = "a, b";
        String givenBlock = readResource("groups/code/WhileInIf.txt");
        String expectedBlock = readResource("groups/expected/WhileInIf.txt");

        BlockStatementGrouper grouper = new BlockStatementGrouper(givenBlock, 10, parameters);

        RewriteGroupedCode rewriteGroupedCode = grouper.rewrite("myFun");

        String rewriteCode = rewriteGroupedCode.getRewriteCode();
        Map<String, List<String>> groups = rewriteGroupedCode.getGroups();

        // Trying to mitigate any indentation issues between all sort of platforms by simply
        // trim every line of the "class". Before this change, code-splitter test could fail on
        // Windows machines while passing on Unix.
        assertThat(trimLines(rewriteCode)).isEqualTo(trimLines(expectedBlock));

        assertThat(groups).hasSize(5);
        List<String> group1 = groups.get("myFun_rewriteGroup0_1_rewriteGroup2_3_rewriteGroup5");
        assertThat(group1).hasSize(2);
        assertThat(group1.get(0)).isEqualTo("myFun_whileBody0_0(a, b);");
        assertThat(trimLines(group1.get(1)))
                .isEqualTo(
                        trimLines(
                                ""
                                        + " if (a[0] > 0) {\n"
                                        + "     myFun_whileBody0_0_ifBody0(a, b);\n"
                                        + " } else {\n"
                                        + "     myFun_whileBody0_0_ifBody1(a, b);\n"
                                        + " }"));

        List<String> group2 = groups.get("myFun_rewriteGroup0_1_rewriteGroup6");
        assertThat(group2).hasSize(1);
        assertThat(trimLines(group2.get(0)))
                .isEqualTo(
                        trimLines(
                                ""
                                        + "while (counter > 0) {\n"
                                        + "    myFun_rewriteGroup0_1_rewriteGroup2_3_rewriteGroup5(a, b);\n"
                                        + "    counter--;\n"
                                        + "}"));

        List<String> group3 = groups.get("myFun_rewriteGroup0_1_rewriteGroup7");
        assertThat(group3).containsExactly("a[2] += b[2];", "b[3] += a[3];");

        List<String> group4 = groups.get("myFun_rewriteGroup8");
        assertThat(group4).hasSize(3);
        assertThat(group4.get(0)).isEqualTo("a[0] += b[1];");
        assertThat(group4.get(1)).isEqualTo("b[1] += a[1];");
        assertThat(trimLines(group4.get(2)))
                .isEqualTo(
                        trimLines(
                                "if (a.length < 100) {\n"
                                        + "      myFun_rewriteGroup0_1_rewriteGroup6(a, b);\n"
                                        + "     \n"
                                        + "      myFun_rewriteGroup0_1_rewriteGroup7(a, b);\n"
                                        + "    } else {\n"
                                        + "      while (counter < 100) {\n"
                                        + "          b[4] = b[4]++;\n"
                                        + "          counter++;\n"
                                        + "      }\n"
                                        + "}"));

        List<String> group5 = groups.get("myFun_rewriteGroup9");
        assertThat(group5).containsExactly("a[5] += b[5];", "b[6] += a[6];");
    }