### Question:
PmdConfiguration implements BatchExtension { public File dumpXmlRuleSet(String repositoryKey, String rulesXml) { try { File configurationFile = writeToWorkingDirectory(rulesXml, repositoryKey + ".xml"); LOG.info("PMD configuration: " + configurationFile.getAbsolutePath()); return configurationFile; } catch (IOException e) { throw new IllegalStateException("Fail to save the PMD configuration", e); } } PmdConfiguration(FileSystem fileSystem, Settings settings); File dumpXmlRuleSet(String repositoryKey, String rulesXml); File dumpXmlReport(Report report); static final String PROPERTY_GENERATE_XML; static final String PMD_RESULT_XML; }### Answer:
@Test public void should_dump_xml_rule_set() throws IOException { when(fs.workDir()).thenReturn(WORK_DIR); File rulesFile = configuration.dumpXmlRuleSet("pmd", "<rules>"); assertThat(rulesFile).isEqualTo(new File(WORK_DIR, "pmd.xml")); assertThat(Files.readLines(rulesFile, Charsets.UTF_8)).containsExactly("<rules>"); }
@Test public void should_fail_to_dump_xml_rule_set() throws IOException { when(fs.workDir()).thenReturn(new File("xxx")); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Fail to save the PMD configuration"); configuration.dumpXmlRuleSet("pmd", "<xml>"); }