Search in sources :

Example 11 with MyNewIssuesNotification

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

the class NotificationFactoryTest method newMyNewIssuesNotification_DetailsSupplier_getUserNameByUuid_returns_empty_if_user_has_null_name.

@Test
public void newMyNewIssuesNotification_DetailsSupplier_getUserNameByUuid_returns_empty_if_user_has_null_name() {
    UserDto user = UserTesting.newUserDto().setLogin("user_noname").setName(null);
    MyNewIssuesNotification underTest = this.underTest.newMyNewIssuesNotification(ImmutableMap.of(user.getUuid(), user));
    DetailsSupplier detailsSupplier = readDetailsSupplier(underTest);
    assertThat(detailsSupplier.getUserNameByUuid(user.getUuid())).isEmpty();
}
Also used : UserDto(org.sonar.db.user.UserDto) MyNewIssuesNotification(org.sonar.server.issue.notification.MyNewIssuesNotification) DetailsSupplier(org.sonar.server.issue.notification.NewIssuesNotification.DetailsSupplier) Test(org.junit.Test)

Example 12 with MyNewIssuesNotification

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

the class NotificationFactoryTest method newMyNewIssuesNotification_DetailsSupplier_getUserNameByUuid_returns_name_of_user_from_map_argument.

@Test
public void newMyNewIssuesNotification_DetailsSupplier_getUserNameByUuid_returns_name_of_user_from_map_argument() {
    Set<UserDto> users = IntStream.range(0, 1 + new Random().nextInt(10)).mapToObj(i -> UserTesting.newUserDto().setLogin("user" + i)).collect(Collectors.toSet());
    MyNewIssuesNotification underTest = this.underTest.newMyNewIssuesNotification(users.stream().collect(uniqueIndex(UserDto::getUuid)));
    DetailsSupplier detailsSupplier = readDetailsSupplier(underTest);
    assertThat(detailsSupplier.getUserNameByUuid("foo")).isEmpty();
    users.forEach(user -> assertThat(detailsSupplier.getUserNameByUuid(user.getUuid())).contains(user.getName()));
}
Also used : Branch(org.sonar.ce.task.projectanalysis.analysis.Branch) NewIssuesNotification(org.sonar.server.issue.notification.NewIssuesNotification) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Random(java.util.Random) DataProviderRunner(com.tngtech.java.junit.dataprovider.DataProviderRunner) DetailsSupplier(org.sonar.server.issue.notification.NewIssuesNotification.DetailsSupplier) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) Map(java.util.Map) AnalysisMetadataHolderRule(org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule) MyNewIssuesNotification(org.sonar.server.issue.notification.MyNewIssuesNotification) ChangedIssue(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue) DIRECTORY(org.sonar.ce.task.projectanalysis.component.Component.Type.DIRECTORY) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Set(java.util.Set) IssuesChangesNotification(org.sonar.server.issue.notification.IssuesChangesNotification) Collectors(java.util.stream.Collectors) PROJECT(org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT) FILE(org.sonar.ce.task.projectanalysis.component.Component.Type.FILE) Stream(java.util.stream.Stream) RuleKey(org.sonar.api.rule.RuleKey) MoreCollectors.uniqueIndex(org.sonar.core.util.stream.MoreCollectors.uniqueIndex) TreeRootHolderRule(org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule) UserTesting(org.sonar.db.user.UserTesting) IssuesChangesNotificationSerializer(org.sonar.server.issue.notification.IssuesChangesNotificationSerializer) Mockito.mock(org.mockito.Mockito.mock) IntStream(java.util.stream.IntStream) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) UserDto(org.sonar.db.user.UserDto) STATUS_OPEN(org.sonar.api.issue.Issue.STATUS_OPEN) RunWith(org.junit.runner.RunWith) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) DumbRule(org.sonar.ce.task.projectanalysis.issue.DumbRule) ArgumentCaptor(org.mockito.ArgumentCaptor) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) AnalysisChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.AnalysisChange) Collections.emptyMap(java.util.Collections.emptyMap) BranchType(org.sonar.db.component.BranchType) DefaultIssue(org.sonar.core.issue.DefaultIssue) RandomStringUtils.randomAlphabetic(org.apache.commons.lang.RandomStringUtils.randomAlphabetic) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider) Durations(org.sonar.api.utils.Durations) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Field(java.lang.reflect.Field) Mockito.verify(org.mockito.Mockito.verify) Rule(org.junit.Rule) RuleDefinition(org.sonar.server.issue.notification.NewIssuesNotification.RuleDefinition) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) RuleRepositoryRule(org.sonar.ce.task.projectanalysis.issue.RuleRepositoryRule) Collections(java.util.Collections) IssuesChangesNotificationBuilder(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder) Random(java.util.Random) UserDto(org.sonar.db.user.UserDto) MyNewIssuesNotification(org.sonar.server.issue.notification.MyNewIssuesNotification) DetailsSupplier(org.sonar.server.issue.notification.NewIssuesNotification.DetailsSupplier) Test(org.junit.Test)

Example 13 with MyNewIssuesNotification

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

the class NotificationFactoryTest method newMyNewIssuesNotification_DetailsSupplier_getUserNameByUuid_always_returns_empty_if_map_argument_is_empty.

@Test
public void newMyNewIssuesNotification_DetailsSupplier_getUserNameByUuid_always_returns_empty_if_map_argument_is_empty() {
    MyNewIssuesNotification underTest = this.underTest.newMyNewIssuesNotification(emptyMap());
    DetailsSupplier detailsSupplier = readDetailsSupplier(underTest);
    assertThat(detailsSupplier.getUserNameByUuid("foo")).isEmpty();
}
Also used : MyNewIssuesNotification(org.sonar.server.issue.notification.MyNewIssuesNotification) DetailsSupplier(org.sonar.server.issue.notification.NewIssuesNotification.DetailsSupplier) Test(org.junit.Test)

Example 14 with MyNewIssuesNotification

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

the class NotificationFactoryTest method newMyNewIssuesNotification_DetailsSupplier_getComponentNameByUuid_fails_with_NPE_if_uuid_is_null.

@Test
public void newMyNewIssuesNotification_DetailsSupplier_getComponentNameByUuid_fails_with_NPE_if_uuid_is_null() {
    treeRootHolder.setRoot(ReportComponent.builder(PROJECT, 1).setUuid("rootUuid").setName("root").build());
    MyNewIssuesNotification underTest = this.underTest.newMyNewIssuesNotification(emptyMap());
    DetailsSupplier detailsSupplier = readDetailsSupplier(underTest);
    assertThatThrownBy(() -> detailsSupplier.getComponentNameByUuid(null)).isInstanceOf(NullPointerException.class).hasMessage("uuid can't be null");
}
Also used : MyNewIssuesNotification(org.sonar.server.issue.notification.MyNewIssuesNotification) DetailsSupplier(org.sonar.server.issue.notification.NewIssuesNotification.DetailsSupplier) Test(org.junit.Test)

Example 15 with MyNewIssuesNotification

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

the class NotificationFactoryTest method newMyNewIssuesNotification_DetailsSupplier_getRuleDefinitionByRuleKey_fails_with_NPE_if_ruleKey_is_null.

@Test
public void newMyNewIssuesNotification_DetailsSupplier_getRuleDefinitionByRuleKey_fails_with_NPE_if_ruleKey_is_null() {
    MyNewIssuesNotification underTest = this.underTest.newMyNewIssuesNotification(emptyMap());
    DetailsSupplier detailsSupplier = readDetailsSupplier(underTest);
    assertThatThrownBy(() -> detailsSupplier.getRuleDefinitionByRuleKey(null)).isInstanceOf(NullPointerException.class).hasMessage("ruleKey can't be null");
}
Also used : MyNewIssuesNotification(org.sonar.server.issue.notification.MyNewIssuesNotification) DetailsSupplier(org.sonar.server.issue.notification.NewIssuesNotification.DetailsSupplier) Test(org.junit.Test)

Aggregations

MyNewIssuesNotification (org.sonar.server.issue.notification.MyNewIssuesNotification)16 Test (org.junit.Test)13 DetailsSupplier (org.sonar.server.issue.notification.NewIssuesNotification.DetailsSupplier)11 UserDto (org.sonar.db.user.UserDto)4 Date (java.util.Date)3 Map (java.util.Map)3 RuleKey (org.sonar.api.rule.RuleKey)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Random (java.util.Random)2 Set (java.util.Set)2 IntStream (java.util.stream.IntStream)2 Stream (java.util.stream.Stream)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Rule (org.junit.Rule)2 ArgumentCaptor (org.mockito.ArgumentCaptor)2 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)1 DataProviderRunner (com.tngtech.java.junit.dataprovider.DataProviderRunner)1 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)1 IOException (java.io.IOException)1