3 * Copyright (C) 2009-2022 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.commonrule;
22 import java.util.Collection;
23 import org.junit.Test;
24 import org.sonar.ce.task.projectanalysis.component.Component;
25 import org.sonar.ce.task.projectanalysis.component.FileAttributes;
26 import org.sonar.ce.task.projectanalysis.component.ReportComponent;
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.mockito.Mockito.verifyZeroInteractions;
32 import static org.mockito.Mockito.when;
33 import static org.sonar.ce.task.projectanalysis.component.ReportComponent.DUMB_PROJECT;
35 public class CommonRuleEngineImplTest {
37 CommonRule rule1 = mock(CommonRule.class);
38 CommonRule rule2 = mock(CommonRule.class);
39 CommonRuleEngineImpl underTest = new CommonRuleEngineImpl(rule1, rule2);
42 public void process_files_with_known_language() {
43 ReportComponent file = ReportComponent.builder(Component.Type.FILE, 1)
44 .setKey("FILE_KEY").setUuid("FILE_UUID")
45 .setFileAttributes(new FileAttributes(false, "java", 1))
47 DefaultIssue issue = new DefaultIssue();
48 when(rule1.processFile(file, "java")).thenReturn(issue);
49 when(rule2.processFile(file, "java")).thenReturn(null);
51 Collection<DefaultIssue> issues = underTest.process(file);
52 assertThat(issues).containsOnly(issue);
56 public void do_not_process_files_with_unknown_language() {
57 ReportComponent file = ReportComponent.builder(Component.Type.FILE, 1)
58 .setKey("FILE_KEY").setUuid("FILE_UUID")
59 .setFileAttributes(new FileAttributes(false, null, 1))
62 Collection<DefaultIssue> issues = underTest.process(file);
64 assertThat(issues).isEmpty();
65 verifyZeroInteractions(rule1, rule2);
69 public void do_not_process_non_files() {
70 Collection<DefaultIssue> issues = underTest.process(DUMB_PROJECT);
72 assertThat(issues).isEmpty();
73 verifyZeroInteractions(rule1, rule2);