CodeNarcRulesDefinition implements RulesDefinition { @Override public void define(Context context) { NewRepository repository = context .createRepository(REPOSITORY_KEY, Groovy.KEY) .setName(REPOSITORY_NAME); RulesDefinitionXmlLoader ruleLoader = new RulesDefinitionXmlLoader(); ruleLoader.load(repository, CodeNarcRulesDefinition.class.getResourceAsStream("/org/sonar/plugins/groovy/rules.xml"), "UTF-8"); addRemediationCost(repository.rules()); repository.done(); }  @Override void define(Context context); static final String REPOSITORY_KEY; static final String REPOSITORY_NAME; }
@Test public void test() { CodeNarcRulesDefinition definition = new CodeNarcRulesDefinition(); RulesDefinition.Context context = new RulesDefinition.Context(); definition.define(context); RulesDefinition.Repository repository = context.repository(CodeNarcRulesDefinition.REPOSITORY_KEY); assertThat(repository.name()).isEqualTo(CodeNarcRulesDefinition.REPOSITORY_NAME); assertThat(repository.language()).isEqualTo(Groovy.KEY); List<Rule> rules = repository.rules(); assertThat(rules).hasSize(347); List<String> missingDebt = new LinkedList<>(); for (Rule rule : rules) { assertThat(rule.key()).isNotNull(); assertThat(rule.internalKey()).isNotNull(); assertThat(rule.name()).isNotNull(); assertThat(rule.htmlDescription()).isNotNull(); if (rule.debtRemediationFunction() == null) { missingDebt.add(rule.key()); } } assertThat(missingDebt).containsOnly("org.codenarc.rule.generic.IllegalSubclassRule.fixed"); Rule rule = repository.rule("org.codenarc.rule.braces.ElseBlockBracesRule"); assertThat(rule.params()).hasSize(1); assertThat(rule.params().get(0).defaultValue()).isEqualToIgnoringCase("false"); }