### Question:
PmdProfileExporter extends ProfileExporter { @Override public void exportProfile(RulesProfile profile, Writer writer) { String profileName = profile.getName(); PmdRuleset tree = createPmdRuleset(PmdConstants.REPOSITORY_KEY, profile.getActiveRulesByRepository(PmdConstants.REPOSITORY_KEY), profileName); exportPmdRulesetToXml(tree, writer, profileName); } PmdProfileExporter(); @Override void exportProfile(RulesProfile profile, Writer writer); String exportProfile(String repositoryKey, RulesProfile profile);  }### Answer:
@Test public void should_export_pmd_profile_on_writer() { String importedXml = PmdTestUtils.getResourceContent("/org/sonar/plugins/pmd/export_simple.xml"); StringWriter stringWriter = new StringWriter(); exporter.exportProfile(importProfile(importedXml), stringWriter); assertThat(stringWriter.toString()).satisfies(equalsIgnoreEOL(importedXml)); }
@Test public void should_export_pmd_profile_on_writer_exception() throws IOException { thrown.expect(IllegalStateException.class); thrown.expectMessage("An exception occurred while generating the PMD configuration file from profile: null"); String importedXml = PmdTestUtils.getResourceContent("/org/sonar/plugins/pmd/export_simple.xml"); Writer writer = mock(Writer.class); doThrow(new IOException("test exception")).when(writer).write(anyString()); exporter.exportProfile(importProfile(importedXml), writer); }
@Test public void should_export_pmd_profile() { String importedXml = PmdTestUtils.getResourceContent("/org/sonar/plugins/pmd/export_simple.xml"); String exportedXml = exporter.exportProfile(PmdConstants.REPOSITORY_KEY, importProfile(importedXml)); assertThat(exportedXml).satisfies(equalsIgnoreEOL(importedXml)); }
@Test public void should_export_empty_configuration_as_xml() { String exportedXml = exporter.exportProfile(PmdConstants.REPOSITORY_KEY, RulesProfile.create()); assertThat(exportedXml).satisfies(equalsIgnoreEOL("<?xml version=\"1.0\" encoding=\"UTF-8\"?><ruleset />")); }
@Test public void should_export_xPath_rule() { Rule rule = Rule.create(PmdConstants.REPOSITORY_KEY, "MyOwnRule", "This is my own xpath rule.") .setConfigKey(PmdConstants.XPATH_CLASS) .setRepositoryKey(PmdConstants.REPOSITORY_KEY); rule.createParameter(PmdConstants.XPATH_EXPRESSION_PARAM); rule.createParameter(PmdConstants.XPATH_MESSAGE_PARAM); RulesProfile profile = RulesProfile.create(); ActiveRule xpath = profile.activateRule(rule, null); xpath.setParameter(PmdConstants.XPATH_EXPRESSION_PARAM, " xpath.setParameter(PmdConstants.XPATH_MESSAGE_PARAM, "This is bad"); String exportedXml = exporter.exportProfile(PmdConstants.REPOSITORY_KEY, profile); assertThat(exportedXml).satisfies(equalsIgnoreEOL(PmdTestUtils.getResourceContent("/org/sonar/plugins/pmd/export_xpath_rules.xml"))); }