2 * Sonar, open source software quality management tool.
3 * Copyright (C) 2008-2012 SonarSource
4 * mailto:contact AT sonarsource DOT com
6 * Sonar 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 * Sonar 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
17 * License along with Sonar; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
20 package org.sonar.plugins.core.batch;
22 import org.apache.commons.configuration.PropertiesConfiguration;
23 import org.junit.Test;
24 import org.sonar.api.CoreProperties;
25 import org.sonar.api.resources.Project;
26 import org.sonar.api.resources.Qualifiers;
27 import org.sonar.api.resources.Resource;
29 import static org.hamcrest.core.Is.is;
30 import static org.junit.Assert.assertThat;
31 import static org.mockito.Mockito.mock;
32 import static org.mockito.Mockito.when;
34 public class ExcludedResourceFilterTest {
37 public void doNotFailIfNoPatterns() {
38 PropertiesConfiguration conf = new PropertiesConfiguration();
39 Project project = new Project("foo").setConfiguration(conf);
40 ExcludedResourceFilter filter = new ExcludedResourceFilter(project);
41 assertThat(filter.isIgnored(mock(Resource.class)), is(false));
45 public void noPatternsMatch() {
46 PropertiesConfiguration conf = new PropertiesConfiguration();
47 conf.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, new String[]{"**/foo/*.java", "**/bar/*"});
48 Project project = new Project("foo").setConfiguration(conf);
49 ExcludedResourceFilter filter = new ExcludedResourceFilter(project);
50 assertThat(filter.isIgnored(mock(Resource.class)), is(false));
54 * See SONAR-1115 Exclusion patterns do not apply to unit tests.
57 public void ignoreResourceIfMatchesPattern() {
58 PropertiesConfiguration conf = new PropertiesConfiguration();
59 conf.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, new String[]{"**/foo/*.java", "**/bar/*"});
60 Project project = new Project("foo").setConfiguration(conf);
61 ExcludedResourceFilter filter = new ExcludedResourceFilter(project);
63 Resource resource = mock(Resource.class);
64 when(resource.matchFilePattern("**/bar/*")).thenReturn(true);
66 assertThat(filter.isIgnored(resource), is(true));
70 public void doNotExcludeUnitTestFiles() {
71 PropertiesConfiguration conf = new PropertiesConfiguration();
72 conf.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, new String[]{"**/foo/*.java", "**/bar/*"});
73 Project project = new Project("foo").setConfiguration(conf);
74 ExcludedResourceFilter filter = new ExcludedResourceFilter(project);
76 Resource unitTest = mock(Resource.class);
77 when(unitTest.getQualifier()).thenReturn(Qualifiers.UNIT_TEST_FILE);
79 // match exclusion pattern
80 when(unitTest.matchFilePattern("**/bar/*")).thenReturn(true);
82 assertThat(filter.isIgnored(unitTest), is(false));