CheckstyleExtensionRulesDefinition implements RulesDefinition { @Override public void define(Context context) { final NewRepository repository = context .createRepository(REPOSITORY_KEY, REPOSITORY_LANGUAGE) .setName(REPOSITORY_NAME); xmlRuleLoader.load(repository, getClass().getResourceAsStream(RULES_RELATIVE_FILE_PATH), "UTF-8"); repository.done(); } CheckstyleExtensionRulesDefinition(RulesDefinitionXmlLoader xmlRuleLoader); @Override void define(Context context);  }
@Test public void testAllRulesValid() { final CheckstyleExtensionRulesDefinition definition = new CheckstyleExtensionRulesDefinition(new RulesDefinitionXmlLoader()); final RulesDefinition.Context context = new RulesDefinition.Context(); definition.define(context); final RulesDefinition.Repository repository = context.repository("checkstyle"); Assert.assertEquals("Incorrect repository name", "Checkstyle", repository.name()); Assert.assertEquals("Incorrect repository language", "java", repository.language()); final List<RulesDefinition.Rule> rules = repository.rules(); Assert.assertEquals("Incorrect number of loaded rules", 59, rules.size()); for (RulesDefinition.Rule rule : rules) { Assert.assertNotNull("Rule key is not set", rule.key()); Assert.assertNotNull("Config key is not set for rule " + rule.key(), rule.internalKey()); Assert.assertNotNull("Name is not set for rule " + rule.key(), rule.name()); Assert.assertNotNull("Description is not set for rule " + rule.key(), rule.htmlDescription()); for (RulesDefinition.Param param : rule.params()) { Assert.assertNotNull("Key is not set for a parameter of rule " + rule.key(), param.key()); Assert.assertNotNull("Description is not set for a parameter '" + param.name() + "' of rule " + rule.key(), param.description()); } } }