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.

ComponentsWithUnprocessedIssuesTest.java 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2021 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.ce.task.projectanalysis.issue;
  21. import java.util.Set;
  22. import org.junit.Test;
  23. import static com.google.common.collect.Sets.newHashSet;
  24. import static org.assertj.core.api.Assertions.assertThat;
  25. import static org.assertj.core.api.Assertions.assertThatThrownBy;
  26. public class ComponentsWithUnprocessedIssuesTest {
  27. ComponentsWithUnprocessedIssues sut = new ComponentsWithUnprocessedIssues();
  28. @Test
  29. public void set_uuids() {
  30. sut.setUuids(newHashSet("ABCD", "EFGH"));
  31. assertThat(sut.getUuids()).containsOnly("ABCD", "EFGH");
  32. }
  33. @Test
  34. public void set_uuids_makes_a_copy_of_input_issues() {
  35. Set<String> issues = newHashSet("ABCD", "EFGH");
  36. sut.setUuids(issues);
  37. assertThat(sut.getUuids()).containsOnly("ABCD", "EFGH");
  38. // Remove a element from the list, number of issues from the queue should remain the same
  39. issues.remove("ABCD");
  40. assertThat(sut.getUuids()).containsOnly("ABCD", "EFGH");
  41. }
  42. @Test
  43. public void fail_with_NPE_when_setting_null_uuids() {
  44. assertThatThrownBy(() -> sut.setUuids(null))
  45. .isInstanceOf(NullPointerException.class)
  46. .hasMessage("Uuids cannot be null");
  47. }
  48. @Test
  49. public void fail_with_ISE_when_setting_uuids_twice() {
  50. assertThatThrownBy(() -> {
  51. sut.setUuids(newHashSet("ABCD"));
  52. sut.setUuids(newHashSet("EFGH"));
  53. })
  54. .isInstanceOf(IllegalStateException.class)
  55. .hasMessage("Uuids have already been initialized");
  56. }
  57. @Test
  58. public void remove_uuid() {
  59. sut.setUuids(newHashSet("ABCD", "EFGH"));
  60. sut.remove("ABCD");
  61. assertThat(sut.getUuids()).containsOnly("EFGH");
  62. }
  63. @Test
  64. public void fail_with_ISE_when_removing_uuid_and_not_initialized() {
  65. assertThatThrownBy(() -> sut.remove("ABCD"))
  66. .isInstanceOf(IllegalStateException.class)
  67. .hasMessage("Uuids have not been initialized yet");
  68. }
  69. @Test
  70. public void fail_with_ISE_when_getting_uuid_and_not_initialized() {
  71. assertThatThrownBy(() -> sut.getUuids())
  72. .isInstanceOf(IllegalStateException.class)
  73. .hasMessage("Uuids have not been initialized yet");
  74. }
  75. }