SidebarGenerator { List<Map<String, Object>> generateRuleReferenceSection(Map<Language, List<RuleSet>> sortedRulesets) { List<Map<String, Object>> newFolderItems = new ArrayList<>(); for (Map.Entry<Language, List<RuleSet>> entry : sortedRulesets.entrySet()) { Map<String, Object> newFolderItem = new LinkedHashMap<>(); newFolderItem.put("title", null); newFolderItem.put("output", "web, pdf"); Map<String, Object> subfolder = new LinkedHashMap<>(); newFolderItem.put("subfolders", Arrays.asList(subfolder)); subfolder.put("title", entry.getKey().getName() + " Rules"); subfolder.put("output", "web, pdf"); List<Map<String, Object>> subfolderitems = new ArrayList<>(); subfolder.put("subfolderitems", subfolderitems); Map<String, Object> ruleIndexSubfolderItem = new LinkedHashMap<>(); ruleIndexSubfolderItem.put("title", "Index"); ruleIndexSubfolderItem.put("output", "web, pdf"); ruleIndexSubfolderItem.put("url", "/pmd_rules_" + entry.getKey().getTerseName() + ".html"); subfolderitems.add(ruleIndexSubfolderItem); for (RuleSet ruleset : entry.getValue()) { Map<String, Object> subfolderitem = new LinkedHashMap<>(); subfolderitem.put("title", ruleset.getName()); subfolderitem.put("output", "web, pdf"); subfolderitem.put("url", "/pmd_rules_" + entry.getKey().getTerseName() + "_" + RuleSetUtils.getRuleSetFilename(ruleset) + ".html"); subfolderitems.add(subfolderitem); } newFolderItems.add(newFolderItem); } return newFolderItems; } SidebarGenerator(FileWriter writer, Path basePath); void generateSidebar(Map<Language, List<RuleSet>> sortedRulesets); Map<String, Object> loadSidebar(); void writeSidebar(Map<String, Object> sidebar);  }
@Test public void testSidebar() throws IOException { Map<Language, List<RuleSet>> rulesets = new HashMap<>(); RuleSet ruleSet1 = RulesetsFactoryUtils.defaultFactory().createNewRuleSet("test", "test", "bestpractices.xml", Collections.emptyList(), Collections.emptyList(), Collections.emptyList()); RuleSet ruleSet2 = RulesetsFactoryUtils.defaultFactory().createNewRuleSet("test2", "test", "codestyle.xml", Collections.emptyList(), Collections.emptyList(), Collections.emptyList()); rulesets.put(LanguageRegistry.findLanguageByTerseName("java"), Arrays.asList(ruleSet1, ruleSet2)); rulesets.put(LanguageRegistry.findLanguageByTerseName("ecmascript"), Arrays.asList(ruleSet1)); SidebarGenerator generator = new SidebarGenerator(writer, FileSystems.getDefault().getPath("..")); List<Map<String, Object>> result = generator.generateRuleReferenceSection(rulesets); DumperOptions options = new DumperOptions(); options.setDefaultFlowStyle(FlowStyle.BLOCK); if (SystemUtils.IS_OS_WINDOWS) { options.setLineBreak(LineBreak.WIN); } String yaml = new Yaml(options).dump(result); String expected = MockedFileWriter.normalizeLineSeparators( IOUtils.toString(SidebarGeneratorTest.class.getResourceAsStream("sidebar.yml"), StandardCharsets.UTF_8)); assertEquals(expected, yaml); }