### Question:
PmdProfileExporter extends ProfileExporter { static void processXPathRule(String sonarRuleKey, PmdRule rule) { if (PmdConstants.XPATH_CLASS.equals(rule.getRef())) { rule.setRef(null); PmdProperty xpathMessage = rule.getProperty(PmdConstants.XPATH_MESSAGE_PARAM); if (xpathMessage == null) { throw new IllegalArgumentException("Property '" + PmdConstants.XPATH_MESSAGE_PARAM + "' should be set for PMD rule " + sonarRuleKey); } rule.setMessage(xpathMessage.getValue()); rule.removeProperty(PmdConstants.XPATH_MESSAGE_PARAM); PmdProperty xpathExp = rule.getProperty(PmdConstants.XPATH_EXPRESSION_PARAM); if (xpathExp == null) { throw new IllegalArgumentException("Property '" + PmdConstants.XPATH_EXPRESSION_PARAM + "' should be set for PMD rule " + sonarRuleKey); } xpathExp.setCdataValue(xpathExp.getValue()); rule.setClazz(PmdConstants.XPATH_CLASS); rule.setLanguage(PmdConstants.LANGUAGE_KEY); rule.setName(sonarRuleKey); } } PmdProfileExporter(); @Override void exportProfile(RulesProfile profile, Writer writer); String exportProfile(String repositoryKey, RulesProfile profile);  }### Answer:
@Test void should_fail_if_message_not_provided_for_xPath_rule() { final PmdRule rule = new PmdRule(PmdConstants.XPATH_CLASS); rule.addProperty(new PmdProperty(PmdConstants.XPATH_EXPRESSION_PARAM, "xpathExpression")); rule.setName("MyOwnRule"); final Throwable thrown = catchThrowable(() -> PmdProfileExporter.processXPathRule("xpathKey", rule)); assertThat(thrown).isInstanceOf(IllegalArgumentException.class); }
@Test void should_process_xPath_rule() { PmdRule rule = new PmdRule(PmdConstants.XPATH_CLASS); rule.setName("MyOwnRule"); rule.addProperty(new PmdProperty(PmdConstants.XPATH_EXPRESSION_PARAM, "xpathExpression")); rule.addProperty(new PmdProperty(PmdConstants.XPATH_MESSAGE_PARAM, "message")); PmdProfileExporter.processXPathRule("xpathKey", rule); assertThat(rule.getMessage()).isEqualTo("message"); assertThat(rule.getRef()).isNull(); assertThat(rule.getClazz()).isEqualTo(PmdConstants.XPATH_CLASS); assertThat(rule.getProperty(PmdConstants.XPATH_MESSAGE_PARAM)).isNull(); assertThat(rule.getName()).isEqualTo("xpathKey"); assertThat(rule.getProperty(PmdConstants.XPATH_EXPRESSION_PARAM).getValue()).isEqualTo("xpathExpression"); }
@Test void should_fail_if_xPath_not_provided() { final PmdRule rule = new PmdRule(PmdConstants.XPATH_CLASS); rule.setName("MyOwnRule"); rule.addProperty(new PmdProperty(PmdConstants.XPATH_MESSAGE_PARAM, "This is bad")); final Throwable thrown = catchThrowable(() -> PmdProfileExporter.processXPathRule("xpathKey", rule)); assertThat(thrown).isInstanceOf(IllegalArgumentException.class); }