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 general {@link PmdValidator} behavior that is
17   * not tied to a single PMD rule. Per-rule coverage lives in the
18   * dedicated {@code Pmd*Test.java} files in this package.
19   * @since 0.3
20   */
21  final class PmdValidatorTest {
22  
23      @Test
24      void findsProblemsInJavaFiles() throws Exception {
25          final String file = "src/main/java/Main.java";
26          final Environment env = new Environment.Mock()
27              .withFile(file, "class Main { int x = 0; }");
28          MatcherAssert.assertThat(
29              "Violations should be found",
30              new PmdValidator(env).validate(
31                  Collections.singletonList(new File(env.basedir(), file))
32              ),
33              Matchers.not(Matchers.<Violation>empty())
34          );
35      }
36  
37      @Test
38      void acceptsJavaFilesWithUppercaseExtension() throws Exception {
39          final String file = "src/main/java/Main.JAVA";
40          final Environment env = new Environment.Mock()
41              .withFile(file, "class Main { int x = 0; }");
42          MatcherAssert.assertThat(
43              "File with uppercase .JAVA extension should not be filtered out",
44              new PmdValidator(env).getNonExcludedFiles(
45                  Collections.singletonList(new File(env.basedir(), file))
46              ),
47              Matchers.not(Matchers.empty())
48          );
49      }
50  }