You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ChangesOnMyIssuesNotificationTest.java 3.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2020 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  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.
  10. *
  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.
  15. *
  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.
  19. */
  20. package org.sonar.server.issue.notification;
  21. import com.google.common.collect.ImmutableSet;
  22. import java.util.Random;
  23. import org.junit.Test;
  24. import org.sonar.api.notifications.Notification;
  25. import org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.AnalysisChange;
  26. import org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue;
  27. import org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.User;
  28. import org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.UserChange;
  29. import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
  30. import static org.assertj.core.api.Assertions.assertThat;
  31. import static org.mockito.Mockito.mock;
  32. import static org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newRandomNotAHotspotRule;
  33. public class ChangesOnMyIssuesNotificationTest {
  34. @Test
  35. public void key_is_ChangesOnMyIssues() {
  36. ChangesOnMyIssuesNotification underTest = new ChangesOnMyIssuesNotification(
  37. new UserChange(new Random().nextLong(), new User(randomAlphabetic(2), randomAlphabetic(3), randomAlphabetic(4))),
  38. ImmutableSet.of());
  39. assertThat(underTest.getType()).isEqualTo("ChangesOnMyIssues");
  40. }
  41. @Test
  42. public void equals_is_based_on_change_and_issues() {
  43. AnalysisChange analysisChange = new AnalysisChange(new Random().nextLong());
  44. ChangedIssue changedIssue = IssuesChangesNotificationBuilderTesting.newChangedIssue("doo", IssuesChangesNotificationBuilderTesting.newProject("prj"),
  45. newRandomNotAHotspotRule("rul"));
  46. ChangesOnMyIssuesNotification underTest = new ChangesOnMyIssuesNotification(analysisChange, ImmutableSet.of(changedIssue));
  47. assertThat(underTest)
  48. .isEqualTo(new ChangesOnMyIssuesNotification(analysisChange, ImmutableSet.of(changedIssue)))
  49. .isNotEqualTo(mock(Notification.class))
  50. .isNotEqualTo(null)
  51. .isNotEqualTo(new ChangesOnMyIssuesNotification(new AnalysisChange(analysisChange.getDate() + 10), ImmutableSet.of(changedIssue)))
  52. .isNotEqualTo(new ChangesOnMyIssuesNotification(analysisChange, ImmutableSet.of()));
  53. }
  54. @Test
  55. public void hashcode_is_based_on_change_and_issues() {
  56. AnalysisChange analysisChange = new AnalysisChange(new Random().nextLong());
  57. ChangedIssue changedIssue = IssuesChangesNotificationBuilderTesting.newChangedIssue("doo", IssuesChangesNotificationBuilderTesting.newProject("prj"),
  58. newRandomNotAHotspotRule("rul"));
  59. ChangesOnMyIssuesNotification underTest = new ChangesOnMyIssuesNotification(analysisChange, ImmutableSet.of(changedIssue));
  60. assertThat(underTest.hashCode())
  61. .isEqualTo(new ChangesOnMyIssuesNotification(analysisChange, ImmutableSet.of(changedIssue)).hashCode())
  62. .isNotEqualTo(mock(Notification.class).hashCode())
  63. .isNotEqualTo(null)
  64. .isNotEqualTo(new ChangesOnMyIssuesNotification(new AnalysisChange(analysisChange.getDate() + 10), ImmutableSet.of(changedIssue)).hashCode())
  65. .isNotEqualTo(new ChangesOnMyIssuesNotification(analysisChange, ImmutableSet.of())).hashCode();
  66. }
  67. }