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.api.Test;
14  
15  /**
16   * Test case for {@link PmdValidator}'s short-circuit when every
17   * source file is excluded (issue #759). PMD must not be invoked
18   * on the excluded file and must report no violations.
19   *
20   * @since 0.25.1
21   */
22  final class PmdExclusionTest {
23  
24      @Test
25      void skipsAnalysisWhenAllFilesExcluded() throws Exception {
26          final String file = "src/main/java/Main.java";
27          final Environment env = new ExcludingEnvironment(
28              new Environment.Mock()
29                  .withFile(file, "class Main { int x = 0; }")
30          );
31          MatcherAssert.assertThat(
32              "Excluded files must not yield violations",
33              new PmdValidator(env).validate(
34                  Collections.singletonList(new File(env.basedir(), file))
35              ),
36              Matchers.<Violation>empty()
37          );
38      }
39  }