3 * Copyright (C) 2009-2024 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.server.issue.notification;
22 import com.google.common.collect.ImmutableSet;
23 import java.util.Random;
24 import org.junit.Test;
25 import org.sonar.api.notifications.Notification;
26 import org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.AnalysisChange;
27 import org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue;
28 import org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.User;
29 import org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.UserChange;
31 import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
32 import static org.assertj.core.api.Assertions.assertThat;
33 import static org.mockito.Mockito.mock;
34 import static org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newRandomNotAHotspotRule;
36 public class ChangesOnMyIssuesNotificationTest {
38 public void key_is_ChangesOnMyIssues() {
39 ChangesOnMyIssuesNotification underTest = new ChangesOnMyIssuesNotification(
40 new UserChange(new Random().nextLong(), new User(randomAlphabetic(2), randomAlphabetic(3), randomAlphabetic(4))),
43 assertThat(underTest.getType()).isEqualTo("ChangesOnMyIssues");
47 public void equals_is_based_on_change_and_issues() {
48 AnalysisChange analysisChange = new AnalysisChange(new Random().nextLong());
49 ChangedIssue changedIssue = IssuesChangesNotificationBuilderTesting.newChangedIssue("doo", IssuesChangesNotificationBuilderTesting.newProject("prj"),
50 newRandomNotAHotspotRule("rul"));
51 ChangesOnMyIssuesNotification underTest = new ChangesOnMyIssuesNotification(analysisChange, ImmutableSet.of(changedIssue));
54 .isEqualTo(new ChangesOnMyIssuesNotification(analysisChange, ImmutableSet.of(changedIssue)))
55 .isNotEqualTo(mock(Notification.class))
57 .isNotEqualTo(new ChangesOnMyIssuesNotification(new AnalysisChange(analysisChange.getDate() + 10), ImmutableSet.of(changedIssue)))
58 .isNotEqualTo(new ChangesOnMyIssuesNotification(analysisChange, ImmutableSet.of()));
62 public void hashcode_is_based_on_change_and_issues() {
63 AnalysisChange analysisChange = new AnalysisChange(new Random().nextLong());
64 ChangedIssue changedIssue = IssuesChangesNotificationBuilderTesting.newChangedIssue("doo", IssuesChangesNotificationBuilderTesting.newProject("prj"),
65 newRandomNotAHotspotRule("rul"));
66 ChangesOnMyIssuesNotification underTest = new ChangesOnMyIssuesNotification(analysisChange, ImmutableSet.of(changedIssue));
68 assertThat(underTest.hashCode())
69 .isEqualTo(new ChangesOnMyIssuesNotification(analysisChange, ImmutableSet.of(changedIssue)).hashCode())
70 .isNotEqualTo(mock(Notification.class).hashCode())
71 .isNotEqualTo(new ChangesOnMyIssuesNotification(new AnalysisChange(analysisChange.getDate() + 10), ImmutableSet.of(changedIssue)).hashCode())
72 .isNotEqualTo(new ChangesOnMyIssuesNotification(analysisChange, ImmutableSet.of())).hashCode();