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.cactoos.text.TextOf;
12  import org.hamcrest.MatcherAssert;
13  import org.hamcrest.Matchers;
14  import org.junit.jupiter.api.Test;
15  
16  /**
17   * Test case for {@link PmdValidator}'s handling of private
18   * constants that are used only from within an inner class —
19   * they must not be reported as unused.
20   *
21   * @since 0.25.1
22   */
23  final class PmdInnerClassConstantsTest {
24  
25      @Test
26      void doesNotComplainAboutConstantsInInnerClasses() throws Exception {
27          final String file = "src/main/java/foo/Foo.java";
28          final Environment env = new Environment.Mock().withFile(
29              file,
30              new TextOf(
31                  this.getClass().getResourceAsStream("InnerClassConstants.java")
32              ).asString()
33          );
34          MatcherAssert.assertThat(
35              "Private constant in inner class is not a violation",
36              new PmdValidator(env).validate(
37                  Collections.singletonList(new File(env.basedir(), file))
38              ),
39              Matchers.<Violation>empty()
40          );
41      }
42  }