3 * Copyright (C) 2009-2016 SonarSource SA
4 * mailto:contact 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.scanner.cpd.deprecated;
22 import java.io.IOException;
23 import org.junit.Before;
24 import org.junit.Rule;
25 import org.junit.Test;
26 import org.junit.rules.TemporaryFolder;
27 import org.sonar.api.batch.fs.internal.DefaultFileSystem;
28 import org.sonar.api.config.PropertyDefinitions;
29 import org.sonar.api.config.Settings;
30 import org.sonar.scanner.FakeJava;
31 import org.sonar.scanner.cpd.CpdComponents;
33 import static org.assertj.core.api.Assertions.assertThat;
35 public class DeprecatedCpdBlockIndexerSensorTest {
38 public TemporaryFolder temp = new TemporaryFolder();
40 JavaCpdBlockIndexer sonarEngine;
41 DefaultCpdBlockIndexer sonarBridgeEngine;
42 DeprecatedCpdBlockIndexerSensor sensor;
46 public void setUp() throws IOException {
47 sonarEngine = new JavaCpdBlockIndexer(null, null, null);
48 sonarBridgeEngine = new DefaultCpdBlockIndexer(new CpdMappings(), null, null, null);
49 settings = new Settings(new PropertyDefinitions(CpdComponents.class));
51 DefaultFileSystem fs = new DefaultFileSystem(temp.newFolder().toPath());
52 sensor = new DeprecatedCpdBlockIndexerSensor(sonarEngine, sonarBridgeEngine, settings, fs);
56 public void test_global_skip() {
57 settings.setProperty("sonar.cpd.skip", true);
58 assertThat(sensor.isSkipped(FakeJava.KEY)).isTrue();
62 public void should_not_skip_by_default() {
63 assertThat(sensor.isSkipped(FakeJava.KEY)).isFalse();
67 public void should_skip_by_language() {
68 settings.setProperty("sonar.cpd.skip", false);
69 settings.setProperty("sonar.cpd.php.skip", true);
71 assertThat(sensor.isSkipped("php")).isTrue();
72 assertThat(sensor.isSkipped(FakeJava.KEY)).isFalse();
76 public void test_engine() {
77 assertThat(sensor.getBlockIndexer(FakeJava.KEY)).isSameAs(sonarEngine);
78 assertThat(sensor.getBlockIndexer("PHP")).isSameAs(sonarBridgeEngine);