]> source.dussan.org Git - sonarqube.git/blob
b49c37fe7d1aa5c50b4ad08b417511c2406b92b3
[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.step;
21
22 import com.google.common.collect.ImmutableList;
23 import java.util.List;
24 import java.util.stream.Collectors;
25 import org.junit.Rule;
26 import org.junit.Test;
27 import org.sonar.ce.task.log.CeTaskMessages;
28 import org.sonar.ce.task.projectanalysis.batch.BatchReportReaderRule;
29 import org.sonar.ce.task.step.TestComputationStepContext;
30 import org.sonar.scanner.protocol.output.ScannerReport;
31
32 import static com.google.common.collect.ImmutableList.of;
33 import static java.util.Collections.emptyList;
34 import static org.assertj.core.api.Assertions.assertThat;
35 import static org.mockito.Mockito.mock;
36 import static org.mockito.Mockito.verify;
37 import static org.mockito.Mockito.verifyZeroInteractions;
38
39 public class PersistAnalysisWarningsStepTest {
40
41   @Rule
42   public BatchReportReaderRule reportReader = new BatchReportReaderRule();
43
44   private final CeTaskMessages ceTaskMessages = mock(CeTaskMessages.class);
45   private final PersistAnalysisWarningsStep underTest = new PersistAnalysisWarningsStep(reportReader, ceTaskMessages);
46
47   @Test
48   public void getDescription() {
49     assertThat(underTest.getDescription()).isEqualTo(PersistAnalysisWarningsStep.DESCRIPTION);
50   }
51
52   @Test
53   public void execute_persists_warnings_from_reportReader() {
54     ScannerReport.AnalysisWarning warning1 = ScannerReport.AnalysisWarning.newBuilder().setText("warning 1").build();
55     ScannerReport.AnalysisWarning warning2 = ScannerReport.AnalysisWarning.newBuilder().setText("warning 2").build();
56     ImmutableList<ScannerReport.AnalysisWarning> warnings = of(warning1, warning2);
57     reportReader.setAnalysisWarnings(warnings);
58
59     underTest.execute(new TestComputationStepContext());
60
61     List<CeTaskMessages.Message> messages = warnings.stream()
62       .map(w -> new CeTaskMessages.Message(w.getText(), w.getTimestamp()))
63       .collect(Collectors.toList());
64     verify(ceTaskMessages).addAll(messages);
65   }
66
67   @Test
68   public void execute_does_not_persist_warnings_from_reportReader_when_empty() {
69     reportReader.setScannerLogs(emptyList());
70
71     underTest.execute(new TestComputationStepContext());
72
73     verifyZeroInteractions(ceTaskMessages);
74   }
75 }