SonarWayProfile extends ProfileDefinition { @Override public RulesProfile createProfile(ValidationMessages messages) { return xmlProfileParser.parseResource(getClass().getClassLoader(), "org/sonar/plugins/groovy/profile-sonar-way.xml", messages); } SonarWayProfile(XMLProfileParser xmlProfileParser); @Override RulesProfile createProfile(ValidationMessages messages);  }
@Test public void shouldCreateProfile() { ProfileDefinition profileDefinition = new SonarWayProfile(new XMLProfileParser(newRuleFinder())); ValidationMessages messages = ValidationMessages.create(); RulesProfile profile = profileDefinition.createProfile(messages); assertThat(profile.getName()).isEqualTo("Sonar way"); assertThat(profile.getLanguage()).isEqualTo(Groovy.KEY); assertThat(profile.getActiveRules()).hasSize(59); assertThat(messages.hasErrors()).isFalse(); CodeNarcRulesDefinition definition = new CodeNarcRulesDefinition(); RulesDefinition.Context context = new RulesDefinition.Context(); definition.define(context); RulesDefinition.Repository repository = context.repository(CodeNarcRulesDefinition.REPOSITORY_KEY); Map<String, RulesDefinition.Rule> rules = new HashMap<>(); for (RulesDefinition.Rule rule : repository.rules()) { rules.put(rule.key(), rule); } for (ActiveRule activeRule : profile.getActiveRules()) { assertThat(rules.containsKey(activeRule.getConfigKey())).as("No such rule: " + activeRule.getConfigKey()).isTrue(); } }