]> source.dussan.org Git - sonarqube.git/blob
5cfb4e01bbe41bb8f1bafd20f2f06d68a49dc0f9
[sonarqube.git] /
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.ce.task.projectanalysis.issue;
21
22 import com.google.common.base.Optional;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.sonar.ce.task.projectanalysis.component.Component;
26 import org.sonar.ce.task.projectanalysis.filemove.MovedFilesRepository;
27 import org.sonar.ce.task.projectanalysis.filemove.MovedFilesRepository.OriginalFile;
28
29 import static org.mockito.ArgumentMatchers.any;
30 import static org.mockito.Mockito.mock;
31 import static org.mockito.Mockito.verify;
32 import static org.mockito.Mockito.verifyNoMoreInteractions;
33 import static org.mockito.Mockito.when;
34
35 public class RemoveProcessedComponentsVisitorTest {
36   private static final String UUID = "uuid";
37   private ComponentsWithUnprocessedIssues componentsWithUnprocessedIssues = mock(ComponentsWithUnprocessedIssues.class);
38   private MovedFilesRepository movedFilesRepository = mock(MovedFilesRepository.class);
39   private Component component = mock(Component.class);
40   private RemoveProcessedComponentsVisitor underTest = new RemoveProcessedComponentsVisitor(componentsWithUnprocessedIssues, movedFilesRepository);
41
42   @Before
43   public void setUp() {
44     when(component.getUuid()).thenReturn(UUID);
45   }
46
47   @Test
48   public void remove_processed_files() {
49     when(movedFilesRepository.getOriginalFile(any(Component.class))).thenReturn(Optional.absent());
50     underTest.afterComponent(component);
51
52     verify(movedFilesRepository).getOriginalFile(component);
53     verify(componentsWithUnprocessedIssues).remove(UUID);
54     verifyNoMoreInteractions(componentsWithUnprocessedIssues);
55   }
56
57   @Test
58   public void also_remove_moved_files() {
59     String uuid2 = "uuid2";
60     OriginalFile movedFile = new OriginalFile(0, uuid2, "key");
61     when(movedFilesRepository.getOriginalFile(any(Component.class))).thenReturn(Optional.of(movedFile));
62
63     underTest.afterComponent(component);
64
65     verify(movedFilesRepository).getOriginalFile(component);
66     verify(componentsWithUnprocessedIssues).remove(UUID);
67     verify(componentsWithUnprocessedIssues).remove(uuid2);
68
69     verifyNoMoreInteractions(componentsWithUnprocessedIssues);
70   }
71 }