3 * Copyright (C) 2009-2020 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 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;
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;
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);
44 when(component.getUuid()).thenReturn(UUID);
48 public void remove_processed_files() {
49 when(movedFilesRepository.getOriginalFile(any(Component.class))).thenReturn(Optional.absent());
50 underTest.afterComponent(component);
52 verify(movedFilesRepository).getOriginalFile(component);
53 verify(componentsWithUnprocessedIssues).remove(UUID);
54 verifyNoMoreInteractions(componentsWithUnprocessedIssues);
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));
63 underTest.afterComponent(component);
65 verify(movedFilesRepository).getOriginalFile(component);
66 verify(componentsWithUnprocessedIssues).remove(UUID);
67 verify(componentsWithUnprocessedIssues).remove(uuid2);
69 verifyNoMoreInteractions(componentsWithUnprocessedIssues);