diff options
| author | Elena Vilchik | 2018-06-27 15:22:56 +0200 | 
|---|---|---|
| committer | GitHub | 2018-06-27 15:22:56 +0200 | 
| commit | cea9681a811f5bced88e443d5fda14ba15396343 (patch) | |
| tree | 3746b822ead44cf60de9336e6454770710c76960 /sonar-css-plugin/src/test | |
| parent | bde3e646ffe1b1ba1b513cac042f5c1e379da4ff (diff) | |
| download | sonar-css-cea9681a811f5bced88e443d5fda14ba15396343.tar.bz2 | |
Exclude minified files (#93)
Diffstat (limited to 'sonar-css-plugin/src/test')
| -rw-r--r-- | sonar-css-plugin/src/test/java/org/sonar/css/plugin/CssPluginTest.java | 4 | ||||
| -rw-r--r-- | sonar-css-plugin/src/test/java/org/sonar/css/plugin/MinifiedFilesFilterTest.java | 57 | 
2 files changed, 59 insertions, 2 deletions
| diff --git a/sonar-css-plugin/src/test/java/org/sonar/css/plugin/CssPluginTest.java b/sonar-css-plugin/src/test/java/org/sonar/css/plugin/CssPluginTest.java index 7dfe16b..21a944a 100644 --- a/sonar-css-plugin/src/test/java/org/sonar/css/plugin/CssPluginTest.java +++ b/sonar-css-plugin/src/test/java/org/sonar/css/plugin/CssPluginTest.java @@ -36,7 +36,7 @@ public class CssPluginTest {      Plugin.Context context = new Plugin.Context(runtime);      Plugin underTest = new CssPlugin();      underTest.define(context); -    assertThat(context.getExtensions()).hasSize(10); +    assertThat(context.getExtensions()).hasSize(11);    }    @Test @@ -45,6 +45,6 @@ public class CssPluginTest {      Plugin.Context context = new Plugin.Context(runtime);      Plugin underTest = new CssPlugin();      underTest.define(context); -    assertThat(context.getExtensions()).hasSize(11); +    assertThat(context.getExtensions()).hasSize(12);    }  } diff --git a/sonar-css-plugin/src/test/java/org/sonar/css/plugin/MinifiedFilesFilterTest.java b/sonar-css-plugin/src/test/java/org/sonar/css/plugin/MinifiedFilesFilterTest.java new file mode 100644 index 0000000..fc069e8 --- /dev/null +++ b/sonar-css-plugin/src/test/java/org/sonar/css/plugin/MinifiedFilesFilterTest.java @@ -0,0 +1,57 @@ +/* + * SonarCSS + * Copyright (C) 2018-2018 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. + */ +package org.sonar.css.plugin; + +import org.junit.Test; +import org.sonar.api.batch.fs.internal.DefaultInputFile; +import org.sonar.api.batch.fs.internal.TestInputFileBuilder; + +import static org.assertj.core.api.Assertions.assertThat; + +public class MinifiedFilesFilterTest { + +  private static final MinifiedFilesFilter MINIFIED_FILES_FILTER = new MinifiedFilesFilter(); + +  @Test +  public void should_exclude_by_name() throws Exception { +    DefaultInputFile jsFile = TestInputFileBuilder.create("", "foo.min.css") +      .setLanguage("css") +      .setContents("short content") +      .build(); +    assertThat(MINIFIED_FILES_FILTER.accept(jsFile)).isFalse(); +  } + +  @Test +  public void should_keep_other_lang() throws Exception { +    DefaultInputFile jsFile = TestInputFileBuilder.create("", "foo.min.css").setLanguage("js").build(); +    assertThat(MINIFIED_FILES_FILTER.accept(jsFile)).isTrue(); +  } + +  @Test +  public void should_exclude_by_content() throws Exception { +    String longContent = new String(new char[500]).replace("\0", "a") + "\n"; + +    DefaultInputFile jsFile = TestInputFileBuilder.create("", "foo.css") +      .setLanguage("css") +      .setContents(longContent) +      .build(); +    assertThat(MINIFIED_FILES_FILTER.accept(jsFile)).isFalse(); +  } +} | 
