Search in sources :

Example 1 with DetailsSupplier

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

the class NotificationFactoryTest method newNewIssuesNotification_DetailsSupplier_getComponentNameByUuid_returns_name_of_project_in_TreeRootHolder.

@Test
public void newNewIssuesNotification_DetailsSupplier_getComponentNameByUuid_returns_name_of_project_in_TreeRootHolder() {
    treeRootHolder.setRoot(ReportComponent.builder(PROJECT, 1).setUuid("rootUuid").setName("root").build());
    NewIssuesNotification underTest = this.underTest.newNewIssuesNotification(emptyMap());
    DetailsSupplier detailsSupplier = readDetailsSupplier(underTest);
    assertThat(detailsSupplier.getComponentNameByUuid("rootUuid")).contains("root");
    assertThat(detailsSupplier.getComponentNameByUuid("foo")).isEmpty();
}
Also used : NewIssuesNotification(org.sonar.server.issue.notification.NewIssuesNotification) MyNewIssuesNotification(org.sonar.server.issue.notification.MyNewIssuesNotification) DetailsSupplier(org.sonar.server.issue.notification.NewIssuesNotification.DetailsSupplier) Test(org.junit.Test)

Example 2 with DetailsSupplier

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

the class NotificationFactoryTest method newNewIssuesNotification_DetailsSupplier_getUserNameByUuid_returns_name_of_user_from_map_argument.

@Test
public void newNewIssuesNotification_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());
    NewIssuesNotification underTest = this.underTest.newNewIssuesNotification(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) NewIssuesNotification(org.sonar.server.issue.notification.NewIssuesNotification) MyNewIssuesNotification(org.sonar.server.issue.notification.MyNewIssuesNotification) UserDto(org.sonar.db.user.UserDto) DetailsSupplier(org.sonar.server.issue.notification.NewIssuesNotification.DetailsSupplier) Test(org.junit.Test)

Example 3 with DetailsSupplier

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

the class NotificationFactoryTest method newMyNewIssuesNotification_DetailsSupplier_getUserNameByUuid_fails_with_NPE_if_uuid_is_null.

@Test
public void newMyNewIssuesNotification_DetailsSupplier_getUserNameByUuid_fails_with_NPE_if_uuid_is_null() {
    MyNewIssuesNotification underTest = this.underTest.newMyNewIssuesNotification(emptyMap());
    DetailsSupplier detailsSupplier = readDetailsSupplier(underTest);
    assertThatThrownBy(() -> detailsSupplier.getUserNameByUuid(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 4 with DetailsSupplier

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

the class NotificationFactoryTest method newNewIssuesNotification_DetailsSupplier_getUserNameByUuid_fails_with_NPE_if_uuid_is_null.

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

Example 5 with DetailsSupplier

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

the class NotificationFactoryTest method newNewIssuesNotification_DetailsSupplier_getUserNameByUuid_always_returns_empty_if_map_argument_is_empty.

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

Aggregations

DetailsSupplier (org.sonar.server.issue.notification.NewIssuesNotification.DetailsSupplier)23 Test (org.junit.Test)22 MyNewIssuesNotification (org.sonar.server.issue.notification.MyNewIssuesNotification)22 NewIssuesNotification (org.sonar.server.issue.notification.NewIssuesNotification)12 RuleKey (org.sonar.api.rule.RuleKey)4 DumbRule (org.sonar.ce.task.projectanalysis.issue.DumbRule)4 RuleDefinition (org.sonar.server.issue.notification.NewIssuesNotification.RuleDefinition)4 Field (java.lang.reflect.Field)3 UserDto (org.sonar.db.user.UserDto)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)2 DataProviderRunner (com.tngtech.java.junit.dataprovider.DataProviderRunner)2 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)2 Collections (java.util.Collections)2 Collections.emptyMap (java.util.Collections.emptyMap)2 Map (java.util.Map)2 Random (java.util.Random)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2