### Question:
RulesDefinitionUtils { public static void setDefaultValuesForParameters(RulesDefinition.NewRepository repository, List<Class> checks, Language language) { for (Class check : checks) { org.sonar.check.Rule ruleAnnotation = AnnotationUtils.getAnnotation(check, org.sonar.check.Rule.class); String ruleKey = ruleAnnotation.key(); for (Field field : check.getDeclaredFields()) { RuleProperty ruleProperty = field.getAnnotation(RuleProperty.class); PropertyDefaultValues defaultValues = field.getAnnotation(PropertyDefaultValues.class); if (ruleProperty == null || defaultValues == null) { continue; } String paramKey = ruleProperty.key(); List<PropertyDefaultValue> valueForLanguage = Arrays.stream(defaultValues.value()) .filter(defaultValue -> defaultValue.language() == language) .collect(Collectors.toList()); if (valueForLanguage.size() != 1) { throw new IllegalStateException("Invalid @PropertyDefaultValue on " + check.getSimpleName() + " for language " + language); } valueForLanguage .forEach(defaultValue -> repository.rule(ruleKey).param(paramKey).setDefaultValue(defaultValue.defaultValue())); } } } private  RulesDefinitionUtils(); static void setDefaultValuesForParameters(RulesDefinition.NewRepository repository, List<Class> checks, Language language);  }### Answer:
@Test public void test_setDefaultValuesForParameters_kotlin() { initRepository(); RulesDefinitionUtils.setDefaultValuesForParameters(repository, Collections.singletonList(Check.class), Language.KOTLIN); repository.done(); RulesDefinition.Repository repository = context.repository(REPOSITORY); RulesDefinition.Rule check = repository.rule("check"); RulesDefinition.Param param = check.param("param"); assertThat(param.defaultValue()).isEqualTo("kotlin"); }
@Test public void test_setDefaultValuesForParameters_ruby() { initRepository(); RulesDefinitionUtils.setDefaultValuesForParameters(repository, Collections.singletonList(Check.class), Language.RUBY); repository.done(); RulesDefinition.Repository repository = context.repository(REPOSITORY); RulesDefinition.Rule check = repository.rule("check"); RulesDefinition.Param param = check.param("param"); assertThat(param.defaultValue()).isEqualTo("ruby"); }
@Test public void test_setDefaultValuesForParameters_scala() { initRepository(); RulesDefinitionUtils.setDefaultValuesForParameters(repository, Collections.singletonList(Check.class), Language.SCALA); repository.done(); RulesDefinition.Repository repository = context.repository(REPOSITORY); RulesDefinition.Rule check = repository.rule("check"); RulesDefinition.Param param = check.param("param"); assertThat(param.defaultValue()).isEqualTo("scala"); }
@Test public void wrong_annotation() { context = new RulesDefinition.Context(); repository = context.createRepository(REPOSITORY, Language.KOTLIN.toString()); new RulesDefinitionAnnotationLoader().load(repository, WrongAnnotationUsage.class); assertThatThrownBy( () -> RulesDefinitionUtils.setDefaultValuesForParameters(repository, Collections.singletonList(WrongAnnotationUsage.class), Language.RUBY)) .isInstanceOf(IllegalStateException.class) .hasMessage("Invalid @PropertyDefaultValue on WrongAnnotationUsage for language RUBY"); assertThatThrownBy( () -> RulesDefinitionUtils.setDefaultValuesForParameters(repository, Collections.singletonList(WrongAnnotationUsage.class), Language.KOTLIN)) .isInstanceOf(IllegalStateException.class) .hasMessage("Invalid @PropertyDefaultValue on WrongAnnotationUsage for language KOTLIN"); }