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.step;
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;
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;
39 public class PersistAnalysisWarningsStepTest {
42 public BatchReportReaderRule reportReader = new BatchReportReaderRule();
44 private final CeTaskMessages ceTaskMessages = mock(CeTaskMessages.class);
45 private final PersistAnalysisWarningsStep underTest = new PersistAnalysisWarningsStep(reportReader, ceTaskMessages);
48 public void getDescription() {
49 assertThat(underTest.getDescription()).isEqualTo(PersistAnalysisWarningsStep.DESCRIPTION);
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);
59 underTest.execute(new TestComputationStepContext());
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);
68 public void execute_does_not_persist_warnings_from_reportReader_when_empty() {
69 reportReader.setScannerLogs(emptyList());
71 underTest.execute(new TestComputationStepContext());
73 verifyZeroInteractions(ceTaskMessages);