View Javadoc
1   /*
2    * SPDX-FileCopyrightText: Copyright (c) 2011-2026 Yegor Bugayenko
3    * SPDX-License-Identifier: MIT
4    */
5   package com.qulice.pmd;
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 PmdValidator} and the directories Qulice ignores
18   * by default, which it must leave alone without being told to.
19   *
20   * <p>The same source in {@code src/main/java} does produce violations,
21   * as {@link PmdValidatorTest} shows.</p>
22   *
23   * @since 1.0
24   */
25  final class PmdIgnoredTest {
26  
27      @ParameterizedTest
28      @ValueSource(
29          strings = {
30              "src/test/resources/com/qulice/Main.java",
31              "src/site/apt/Main.java",
32              "src/it/violations/src/main/java/foo/Main.java"
33          }
34      )
35      void ignoresJavaFilesInIgnoredDirectories(final String file) throws Exception {
36          final Environment env = new Environment.Mock()
37              .withFile(file, "class Main { int x = 0; }");
38          MatcherAssert.assertThat(
39              String.format("%s must not be checked", file),
40              new PmdValidator(env).validate(
41                  Collections.singletonList(new File(env.basedir(), file))
42              ),
43              Matchers.<Violation>empty()
44          );
45      }
46  
47      @ParameterizedTest
48      @ValueSource(
49          strings = {
50              "src/test/resources/foo/bar/Main.java",
51              "src/site/resources/Main.java",
52              "src/it/foo/Main.java"
53          }
54      )
55      void keepsIgnoredFilesOutOfTheFileList(final String file) throws Exception {
56          final Environment env = new Environment.Mock()
57              .withFile(file, "class Main { int x = 0; }");
58          MatcherAssert.assertThat(
59              String.format("%s must not even reach the list of sources", file),
60              new PmdValidator(env).getNonExcludedFiles(
61                  Collections.singletonList(new File(env.basedir(), file))
62              ),
63              Matchers.empty()
64          );
65      }
66  }