Search in sources :

Example 1 with RuleDefinition

use of org.sonar.server.issue.notification.NewIssuesNotification.RuleDefinition in project sonarqube by SonarSource.

the class NotificationFactoryTest method newMyNewIssuesNotification_DetailsSupplier_getRuleDefinitionByRuleKey_returns_name_and_language_from_RuleRepository.

@Test
public void newMyNewIssuesNotification_DetailsSupplier_getRuleDefinitionByRuleKey_returns_name_and_language_from_RuleRepository() {
    RuleKey rulekey1 = RuleKey.of("foo", "bar");
    RuleKey rulekey2 = RuleKey.of("foo", "donut");
    RuleKey rulekey3 = RuleKey.of("no", "language");
    DumbRule rule1 = ruleRepository.add(rulekey1).setName("rule1").setLanguage("lang1");
    DumbRule rule2 = ruleRepository.add(rulekey2).setName("rule2").setLanguage("lang2");
    DumbRule rule3 = ruleRepository.add(rulekey3).setName("rule3");
    MyNewIssuesNotification underTest = this.underTest.newMyNewIssuesNotification(emptyMap());
    DetailsSupplier detailsSupplier = readDetailsSupplier(underTest);
    assertThat(detailsSupplier.getRuleDefinitionByRuleKey(rulekey1)).contains(new RuleDefinition(rule1.getName(), rule1.getLanguage()));
    assertThat(detailsSupplier.getRuleDefinitionByRuleKey(rulekey2)).contains(new RuleDefinition(rule2.getName(), rule2.getLanguage()));
    assertThat(detailsSupplier.getRuleDefinitionByRuleKey(rulekey3)).contains(new RuleDefinition(rule3.getName(), null));
    assertThat(detailsSupplier.getRuleDefinitionByRuleKey(RuleKey.of("donut", "foo"))).isEmpty();
}
Also used : RuleKey(org.sonar.api.rule.RuleKey) DumbRule(org.sonar.ce.task.projectanalysis.issue.DumbRule) MyNewIssuesNotification(org.sonar.server.issue.notification.MyNewIssuesNotification) DetailsSupplier(org.sonar.server.issue.notification.NewIssuesNotification.DetailsSupplier) RuleDefinition(org.sonar.server.issue.notification.NewIssuesNotification.RuleDefinition) Test(org.junit.Test)

Example 2 with RuleDefinition

use of org.sonar.server.issue.notification.NewIssuesNotification.RuleDefinition in project sonarqube by SonarSource.

the class NewIssuesNotificationTest method RuleDefinition_implements_hashcode_base_on_name_and_language.

@Test
public void RuleDefinition_implements_hashcode_base_on_name_and_language() {
    String name = randomAlphabetic(5);
    String language = randomAlphabetic(6);
    RuleDefinition underTest = new RuleDefinition(name, language);
    assertThat(underTest).hasSameHashCodeAs(underTest).hasSameHashCodeAs(new RuleDefinition(name, language));
    assertThat(underTest.hashCode()).isNotEqualTo(new RuleDefinition(language, name).hashCode()).isNotEqualTo(new RuleDefinition(randomAlphabetic(7), name).hashCode()).isNotEqualTo(new RuleDefinition(language, randomAlphabetic(7)).hashCode()).isNotEqualTo(new RuleDefinition(language, null).hashCode()).isNotEqualTo(new Object().hashCode());
}
Also used : RuleDefinition(org.sonar.server.issue.notification.NewIssuesNotification.RuleDefinition) Test(org.junit.Test)

Example 3 with RuleDefinition

use of org.sonar.server.issue.notification.NewIssuesNotification.RuleDefinition in project sonarqube by SonarSource.

the class NotificationFactoryTest method newNewIssuesNotification_DetailsSupplier_getRuleDefinitionByRuleKey_returns_name_and_language_from_RuleRepository.

@Test
public void newNewIssuesNotification_DetailsSupplier_getRuleDefinitionByRuleKey_returns_name_and_language_from_RuleRepository() {
    RuleKey rulekey1 = RuleKey.of("foo", "bar");
    RuleKey rulekey2 = RuleKey.of("foo", "donut");
    RuleKey rulekey3 = RuleKey.of("no", "language");
    DumbRule rule1 = ruleRepository.add(rulekey1).setName("rule1").setLanguage("lang1");
    DumbRule rule2 = ruleRepository.add(rulekey2).setName("rule2").setLanguage("lang2");
    DumbRule rule3 = ruleRepository.add(rulekey3).setName("rule3");
    NewIssuesNotification underTest = this.underTest.newNewIssuesNotification(emptyMap());
    DetailsSupplier detailsSupplier = readDetailsSupplier(underTest);
    assertThat(detailsSupplier.getRuleDefinitionByRuleKey(rulekey1)).contains(new RuleDefinition(rule1.getName(), rule1.getLanguage()));
    assertThat(detailsSupplier.getRuleDefinitionByRuleKey(rulekey2)).contains(new RuleDefinition(rule2.getName(), rule2.getLanguage()));
    assertThat(detailsSupplier.getRuleDefinitionByRuleKey(rulekey3)).contains(new RuleDefinition(rule3.getName(), null));
    assertThat(detailsSupplier.getRuleDefinitionByRuleKey(RuleKey.of("donut", "foo"))).isEmpty();
}
Also used : RuleKey(org.sonar.api.rule.RuleKey) NewIssuesNotification(org.sonar.server.issue.notification.NewIssuesNotification) MyNewIssuesNotification(org.sonar.server.issue.notification.MyNewIssuesNotification) DumbRule(org.sonar.ce.task.projectanalysis.issue.DumbRule) DetailsSupplier(org.sonar.server.issue.notification.NewIssuesNotification.DetailsSupplier) RuleDefinition(org.sonar.server.issue.notification.NewIssuesNotification.RuleDefinition) Test(org.junit.Test)

Example 4 with RuleDefinition

use of org.sonar.server.issue.notification.NewIssuesNotification.RuleDefinition in project sonarqube by SonarSource.

the class NewIssuesNotificationTest method RuleDefinition_implements_equals_base_on_name_and_language.

@Test
public void RuleDefinition_implements_equals_base_on_name_and_language() {
    String name = randomAlphabetic(5);
    String language = randomAlphabetic(6);
    RuleDefinition underTest = new RuleDefinition(name, language);
    assertThat(underTest).isEqualTo(underTest).isEqualTo(new RuleDefinition(name, language)).isNotEqualTo(new RuleDefinition(language, name)).isNotEqualTo(new RuleDefinition(randomAlphabetic(7), name)).isNotEqualTo(new RuleDefinition(language, randomAlphabetic(7))).isNotEqualTo(new RuleDefinition(language, null)).isNotNull().isNotEqualTo(new Object());
}
Also used : RuleDefinition(org.sonar.server.issue.notification.NewIssuesNotification.RuleDefinition) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 RuleDefinition (org.sonar.server.issue.notification.NewIssuesNotification.RuleDefinition)4 RuleKey (org.sonar.api.rule.RuleKey)2 DumbRule (org.sonar.ce.task.projectanalysis.issue.DumbRule)2 MyNewIssuesNotification (org.sonar.server.issue.notification.MyNewIssuesNotification)2 DetailsSupplier (org.sonar.server.issue.notification.NewIssuesNotification.DetailsSupplier)2 NewIssuesNotification (org.sonar.server.issue.notification.NewIssuesNotification)1