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.

IssuesRepositoryVisitorTest.java 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2019 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 org.junit.Before;
  22. import org.junit.Rule;
  23. import org.junit.Test;
  24. import org.sonar.ce.task.projectanalysis.component.Component;
  25. import org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule;
  26. import org.sonar.core.issue.DefaultIssue;
  27. import static org.assertj.core.api.Assertions.assertThat;
  28. import static org.mockito.Mockito.mock;
  29. import static org.sonar.ce.task.projectanalysis.component.ReportComponent.builder;
  30. public class IssuesRepositoryVisitorTest {
  31. static final String FILE_UUID = "FILE_UUID";
  32. static final String FILE_KEY = "FILE_KEY";
  33. static final int FILE_REF = 2;
  34. static final Component FILE = builder(Component.Type.FILE, FILE_REF)
  35. .setKey(FILE_KEY)
  36. .setUuid(FILE_UUID)
  37. .build();
  38. static final String PROJECT_KEY = "PROJECT_KEY";
  39. static final String PROJECT_UUID = "PROJECT_UUID";
  40. static final int PROJECT_REF = 1;
  41. static final Component PROJECT = builder(Component.Type.PROJECT, PROJECT_REF)
  42. .setKey(PROJECT_KEY)
  43. .setUuid(PROJECT_UUID)
  44. .addChildren(FILE)
  45. .build();
  46. @Rule
  47. public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
  48. @Rule
  49. public ComponentIssuesRepositoryRule componentIssuesRepository = new ComponentIssuesRepositoryRule(treeRootHolder);
  50. IssuesRepositoryVisitor underTest = new IssuesRepositoryVisitor(componentIssuesRepository);
  51. @Before
  52. public void setUp() {
  53. treeRootHolder.setRoot(PROJECT);
  54. }
  55. @Test
  56. public void feed_component_issues_repo() {
  57. DefaultIssue i1 = mock(DefaultIssue.class);
  58. DefaultIssue i2 = mock(DefaultIssue.class);
  59. underTest.beforeComponent(FILE);
  60. underTest.onIssue(FILE, i1);
  61. underTest.onIssue(FILE, i2);
  62. underTest.afterComponent(FILE);
  63. assertThat(componentIssuesRepository.getIssues(FILE_REF)).hasSize(2);
  64. }
  65. @Test
  66. public void empty_component_issues_repo_when_no_issue() {
  67. DefaultIssue i1 = mock(DefaultIssue.class);
  68. DefaultIssue i2 = mock(DefaultIssue.class);
  69. underTest.beforeComponent(FILE);
  70. underTest.onIssue(FILE, i1);
  71. underTest.onIssue(FILE, i2);
  72. underTest.afterComponent(FILE);
  73. assertThat(componentIssuesRepository.getIssues(FILE)).hasSize(2);
  74. underTest.beforeComponent(PROJECT);
  75. underTest.afterComponent(PROJECT);
  76. assertThat(componentIssuesRepository.getIssues(PROJECT)).isEmpty();
  77. }
  78. }