View Javadoc
1   /*
2    * SPDX-FileCopyrightText: Copyright (c) 2011-2026 Yegor Bugayenko
3    * SPDX-License-Identifier: MIT
4    */
5   package com.qulice.checkstyle;
6   
7   import com.qulice.spi.Environment;
8   import com.qulice.spi.Violation;
9   import java.io.File;
10  import java.util.Collections;
11  import org.hamcrest.MatcherAssert;
12  import org.hamcrest.Matchers;
13  import org.junit.jupiter.params.ParameterizedTest;
14  import org.junit.jupiter.params.provider.ValueSource;
15  
16  /**
17   * Test case for {@link CheckstyleValidator} and the directories Qulice
18   * ignores by default, which it must leave alone without being told to.
19   *
20   * <p>The very same source, when it sits in {@code src/main/java},
21   * produces violations, as {@link CheckstyleValidatorTest} shows.</p>
22   *
23   * @since 1.0
24   */
25  final class CheckstyleIgnoredTest {
26  
27      @ParameterizedTest
28      @ValueSource(
29          strings = {
30              "src/test/resources/com/qulice/Bad.java",
31              "src/test/resources/foo/bar/Bad.java",
32              "src/site/apt/Bad.java",
33              "src/it/violations/src/main/java/foo/Bad.java"
34          }
35      )
36      void ignoresJavaFilesInIgnoredDirectories(final String file) throws Exception {
37          final Environment env = new Environment.Mock()
38              .withFile(file, "class Bad { public int x = 0; }");
39          MatcherAssert.assertThat(
40              String.format("%s must not be checked", file),
41              new CheckstyleValidator(env).validate(
42                  Collections.singletonList(new File(env.basedir(), file))
43              ),
44              Matchers.<Violation>empty()
45          );
46      }
47  }