]> source.dussan.org Git - sonarqube.git/blob
85ca73d04bf3c986daac9c2f060a7b7f4c3f290e
[sonarqube.git] /
1 /*
2  * SonarQube, open source software quality management tool.
3  * Copyright (C) 2008-2014 SonarSource
4  * mailto:contact AT sonarsource DOT com
5  *
6  * SonarQube 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  * SonarQube 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.plugins.core.sensors;
21
22 import org.junit.Before;
23 import org.junit.Test;
24 import org.sonar.api.config.PropertyDefinitions;
25 import org.sonar.api.config.Settings;
26 import org.sonar.api.measures.CoreMetrics;
27 import org.sonar.api.measures.Measure;
28 import org.sonar.api.resources.File;
29 import org.sonar.api.resources.Resource;
30 import org.sonar.core.config.ExclusionProperties;
31
32 import static org.assertj.core.api.Assertions.assertThat;
33 import static org.mockito.Mockito.mock;
34 import static org.mockito.Mockito.when;
35
36 public class CoverageMeasurementFilterTest {
37
38   private Settings settings;
39
40   private CoverageMeasurementFilter filter;
41
42   @Before
43   public void createFilter() {
44     settings = new Settings(new PropertyDefinitions(ExclusionProperties.all()));
45     filter = new CoverageMeasurementFilter(settings, new CoverageDecorator(), new LineCoverageDecorator(), new BranchCoverageDecorator());
46   }
47
48   @Test
49   public void shouldNotFilterNonCoverageMetrics() {
50     Measure otherMeasure = mock(Measure.class);
51     when(otherMeasure.getMetric()).thenReturn(CoreMetrics.LINES);
52     assertThat(filter.accept(mock(Resource.class), otherMeasure)).isTrue();
53   }
54
55   @Test
56   public void shouldFilterFileBasedOnPattern() {
57     Resource resource = File.create("src/org/polop/File.php", "org/polop/File.php", null, false);
58     Measure coverageMeasure = mock(Measure.class);
59     when(coverageMeasure.getMetric()).thenReturn(CoreMetrics.LINES_TO_COVER);
60
61     settings.setProperty("sonar.coverage.exclusions", "src/org/polop/*");
62     filter.initPatterns();
63     assertThat(filter.accept(resource, coverageMeasure)).isFalse();
64   }
65
66   @Test
67   public void shouldNotFilterFileBasedOnPattern() {
68     Resource resource = File.create("src/org/polop/File.php", "org/polop/File.php", null, false);
69     Measure coverageMeasure = mock(Measure.class);
70     when(coverageMeasure.getMetric()).thenReturn(CoreMetrics.COVERAGE);
71
72     settings.setProperty("sonar.coverage.exclusions", "src/org/other/*");
73     filter.initPatterns();
74     assertThat(filter.accept(resource, coverageMeasure)).isTrue();
75   }
76 }