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   * @since 0.25.1
20   */
21  final class PmdExclusionTest {
22  
23      @Test
24      void skipsAnalysisWhenAllFilesExcluded() throws Exception {
25          final String file = "src/main/java/Main.java";
26          final Environment env = new ExcludingEnvironment(
27              new Environment.Mock()
28                  .withFile(file, "class Main { int x = 0; }")
29          );
30          MatcherAssert.assertThat(
31              "Excluded files must not yield violations",
32              new PmdValidator(env).validate(
33                  Collections.singletonList(new File(env.basedir(), file))
34              ),
35              Matchers.<Violation>empty()
36          );
37      }
38  }