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 org.hamcrest.Matchers;
8   import org.junit.jupiter.api.Test;
9   
10  /**
11   * Test case for {@link PmdValidator}'s handling of the
12   * {@code UnusedPrivateField} rule, including the suppression for
13   * fields referenced through a fully-qualified outer-class path
14   * inside a lambda (issue #1520).
15   * @since 0.25.1
16   */
17  final class PmdUnusedPrivateFieldTest {
18  
19      @Test
20      void allowsPrivateStaticFieldAccessedViaFullyQualifiedName()
21          throws Exception {
22          new PmdAssert(
23              "UnusedPrivateFieldInLambda.java",
24              Matchers.any(Boolean.class),
25              Matchers.not(
26                  Matchers.containsString("(UnusedPrivateField)")
27              )
28          ).assertOk();
29      }
30  
31      @Test
32      void reportsTrulyUnusedPrivateField() throws Exception {
33          new PmdAssert(
34              "UnusedPrivateFieldTrulyUnused.java",
35              Matchers.any(Boolean.class),
36              Matchers.containsString("(UnusedPrivateField)")
37          ).assertOk();
38      }
39  }