Search in sources :

Example 1 with MoreCollectors.index

use of org.sonar.core.util.stream.MoreCollectors.index in project sonarqube by SonarSource.

the class ChangesOnMyIssueNotificationHandlerTest method deliver_checks_by_projectKeys_if_notifications_have_subscribed_assignee_to_ChangesOnMyIssues_notifications.

@Test
public void deliver_checks_by_projectKeys_if_notifications_have_subscribed_assignee_to_ChangesOnMyIssues_notifications() {
    when(emailNotificationChannel.isActivated()).thenReturn(true);
    Set<ChangedIssue> issues = IntStream.range(0, 1 + new Random().nextInt(2)).mapToObj(i -> new ChangedIssue.Builder("issue_key_" + i).setNewStatus("foo").setAssignee(newUser("" + i)).setRule(newRule()).setProject(newProject(i + "")).build()).collect(toSet());
    IssuesChangesNotificationBuilder builder = new IssuesChangesNotificationBuilder(issues, new UserChange(new Random().nextLong(), new User("user_uuid", "user_login", null)));
    int deliver = underTest.deliver(ImmutableSet.of(serializer.serialize(builder)));
    assertThat(deliver).isZero();
    issues.stream().collect(MoreCollectors.index(ChangedIssue::getProject)).asMap().forEach((key, value) -> {
        String projectKey = key.getKey();
        Set<String> assigneeLogins = value.stream().map(i -> i.getAssignee().get().getLogin()).collect(toSet());
        verify(notificationManager).findSubscribedEmailRecipients(CHANGE_ON_MY_ISSUES_DISPATCHER_KEY, projectKey, assigneeLogins, ALL_MUST_HAVE_ROLE_USER);
    });
    verifyNoMoreInteractions(notificationManager);
    verify(emailNotificationChannel).isActivated();
    verifyNoMoreInteractions(emailNotificationChannel);
}
Also used : IntStream(java.util.stream.IntStream) ArgumentMatchers.anySet(org.mockito.ArgumentMatchers.anySet) ALL_MUST_HAVE_ROLE_USER(org.sonar.server.notification.NotificationManager.SubscriberPermissionsOnProject.ALL_MUST_HAVE_ROLE_USER) ListMultimap(com.google.common.collect.ListMultimap) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) Random(java.util.Random) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) DataProviderRunner(com.tngtech.java.junit.dataprovider.DataProviderRunner) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) ArgumentCaptor(org.mockito.ArgumentCaptor) EmailDeliveryRequest(org.sonar.server.notification.email.EmailNotificationChannel.EmailDeliveryRequest) MoreCollectors.index(org.sonar.core.util.stream.MoreCollectors.index) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) ChangedIssue(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue) AnalysisChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.AnalysisChange) NotificationManager(org.sonar.server.notification.NotificationManager) MoreCollectors(org.sonar.core.util.stream.MoreCollectors) Nullable(javax.annotation.Nullable) Collectors.toSet(java.util.stream.Collectors.toSet) MoreCollectors.unorderedIndex(org.sonar.core.util.stream.MoreCollectors.unorderedIndex) User(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.User) ImmutableSet(com.google.common.collect.ImmutableSet) Project(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Project) RandomStringUtils.randomAlphabetic(org.apache.commons.lang.RandomStringUtils.randomAlphabetic) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider) Set(java.util.Set) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) UserChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.UserChange) PER_PROJECT_NOTIFICATION(org.sonar.server.notification.NotificationDispatcherMetadata.PER_PROJECT_NOTIFICATION) Mockito.verify(org.mockito.Mockito.verify) IssuesChangesNotificationBuilderTesting.newRandomNotAHotspotRule(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newRandomNotAHotspotRule) Mockito(org.mockito.Mockito) Rule(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Rule) List(java.util.List) Stream(java.util.stream.Stream) GLOBAL_NOTIFICATION(org.sonar.server.notification.NotificationDispatcherMetadata.GLOBAL_NOTIFICATION) Change(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Change) NotificationDispatcherMetadata(org.sonar.server.notification.NotificationDispatcherMetadata) EmailNotificationChannel(org.sonar.server.notification.email.EmailNotificationChannel) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) UserChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.UserChange) User(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.User) Random(java.util.Random) ChangedIssue(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue) Test(org.junit.Test)

Aggregations

ImmutableSet (com.google.common.collect.ImmutableSet)1 ListMultimap (com.google.common.collect.ListMultimap)1 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)1 DataProviderRunner (com.tngtech.java.junit.dataprovider.DataProviderRunner)1 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)1 Collections (java.util.Collections)1 List (java.util.List)1 Random (java.util.Random)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 IntStream (java.util.stream.IntStream)1 Stream (java.util.stream.Stream)1 Nullable (javax.annotation.Nullable)1 RandomStringUtils.randomAlphabetic (org.apache.commons.lang.RandomStringUtils.randomAlphabetic)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Test (org.junit.Test)1 RunWith (org.junit.runner.RunWith)1 ArgumentCaptor (org.mockito.ArgumentCaptor)1 ArgumentMatchers.anySet (org.mockito.ArgumentMatchers.anySet)1