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.ce.task.projectanalysis.issue;
22 import org.junit.Before;
23 import org.junit.Rule;
24 import org.junit.Test;
25 import org.sonar.ce.task.projectanalysis.component.Component;
26 import org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule;
27 import org.sonar.core.issue.DefaultIssue;
29 import static org.assertj.core.api.Assertions.assertThat;
30 import static org.mockito.Mockito.mock;
31 import static org.sonar.ce.task.projectanalysis.component.ReportComponent.builder;
33 public class IssuesRepositoryVisitorTest {
34 static final String FILE_UUID = "FILE_UUID";
35 static final String FILE_KEY = "FILE_KEY";
36 static final int FILE_REF = 2;
37 static final Component FILE = builder(Component.Type.FILE, FILE_REF)
42 static final String PROJECT_KEY = "PROJECT_KEY";
43 static final String PROJECT_UUID = "PROJECT_UUID";
44 static final int PROJECT_REF = 1;
45 static final Component PROJECT = builder(Component.Type.PROJECT, PROJECT_REF)
47 .setUuid(PROJECT_UUID)
52 public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
55 public ComponentIssuesRepositoryRule componentIssuesRepository = new ComponentIssuesRepositoryRule(treeRootHolder);
57 IssuesRepositoryVisitor underTest = new IssuesRepositoryVisitor(componentIssuesRepository);
61 treeRootHolder.setRoot(PROJECT);
65 public void feed_component_issues_repo() {
66 DefaultIssue i1 = mock(DefaultIssue.class);
67 DefaultIssue i2 = mock(DefaultIssue.class);
69 underTest.beforeComponent(FILE);
70 underTest.onIssue(FILE, i1);
71 underTest.onIssue(FILE, i2);
72 underTest.afterComponent(FILE);
74 assertThat(componentIssuesRepository.getIssues(FILE_REF)).hasSize(2);
78 public void empty_component_issues_repo_when_no_issue() {
79 DefaultIssue i1 = mock(DefaultIssue.class);
80 DefaultIssue i2 = mock(DefaultIssue.class);
82 underTest.beforeComponent(FILE);
83 underTest.onIssue(FILE, i1);
84 underTest.onIssue(FILE, i2);
85 underTest.afterComponent(FILE);
86 assertThat(componentIssuesRepository.getIssues(FILE)).hasSize(2);
88 underTest.beforeComponent(PROJECT);
89 underTest.afterComponent(PROJECT);
90 assertThat(componentIssuesRepository.getIssues(PROJECT)).isEmpty();