### Question:
PmdRulesDefinition implements RulesDefinition { @Override public void define(Context context) { NewRepository repository = context .createRepository(PmdConstants.REPOSITORY_KEY, Java.KEY) .setName(PmdConstants.REPOSITORY_NAME); extractRulesData(repository, "/org/sonar/plugins/pmd/rules.xml", "/org/sonar/l10n/pmd/rules/pmd"); extractRulesData(repository, "/org/sonar/plugins/pmd/rules-p3c.xml", "/org/sonar/l10n/pmd/rules/pmd-p3c"); repository.done(); NewRepository xmlRepository = context .createRepository(PmdConstants.XML_REPOSITORY_KEY, Xml.KEY) .setName(PmdConstants.XML_REPOSITORY_NAME); extractRulesData(xmlRepository, "/org/sonar/plugins/pmd/rules-xml.xml", "/org/sonar/l10n/pmd/rules/pmd-xml"); xmlRepository.done(); } PmdRulesDefinition(); @Override void define(Context context);  }### Answer:
@Test public void test() { PmdRulesDefinition definition = new PmdRulesDefinition(); RulesDefinition.Context context = new RulesDefinition.Context(); definition.define(context); RulesDefinition.Repository repository = context.repository(PmdConstants.REPOSITORY_KEY); assertThat(repository.name()).isEqualTo(PmdConstants.REPOSITORY_NAME); assertThat(repository.language()).isEqualTo(Java.KEY); List<Rule> rules = repository.rules(); for (Rule rule : rules) { assertThat(rule.key()).isNotNull(); assertThat(rule.internalKey()).isNotNull(); assertThat(rule.name()).isNotNull(); assertThat(rule.htmlDescription()).isNotNull(); assertThat(rule.severity()).isNotNull(); for (Param param : rule.params()) { assertThat(param.name()).isNotNull(); assertThat(param.description()) .overridingErrorMessage("Description is not set for parameter '" + param.name() + "' of rule '" + rule.key()) .isNotNull(); } if (!"XPathRule".equals(rule.key())) { assertThat(rule.debtRemediationFunction()) .overridingErrorMessage("Sqale remediation function is not set for rule '" + rule.key()) .isNotNull(); assertThat(rule.debtSubCharacteristic()) .overridingErrorMessage("Sqale characteristic is not set for rule '" + rule.key()) .isNotNull(); } } }
@Test public void should_exclude_junit_rules() { PmdRulesDefinition definition = new PmdRulesDefinition(); RulesDefinition.Context context = new RulesDefinition.Context(); definition.define(context); RulesDefinition.Repository repository = context.repository(PmdConstants.REPOSITORY_KEY); for (Rule rule : repository.rules()) { assertThat(rule.key()).excludes("JUnitStaticSuite"); } }
@Test public void should_use_text_parameter_for_xpath_rule() { PmdRulesDefinition definition = new PmdRulesDefinition(); RulesDefinition.Context context = new RulesDefinition.Context(); definition.define(context); RulesDefinition.Repository repository = context.repository(PmdConstants.REPOSITORY_KEY); Rule xpathRule = Iterables.find(repository.rules(), new Predicate<Rule>() { @Override public boolean apply(Rule rule) { return rule.key().equals("XPathRule"); } }); assertThat(xpathRule.param("xpath").type().type()).isEqualTo(PropertyType.TEXT.name()); }