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   *
16   * @since 0.25.1
17   */
18  final class PmdUnusedPrivateFieldTest {
19  
20      @Test
21      void allowsPrivateStaticFieldAccessedViaFullyQualifiedName()
22          throws Exception {
23          new PmdAssert(
24              "UnusedPrivateFieldInLambda.java",
25              Matchers.any(Boolean.class),
26              Matchers.not(
27                  Matchers.containsString("(UnusedPrivateField)")
28              )
29          ).assertOk();
30      }
31  
32      @Test
33      void reportsTrulyUnusedPrivateField() throws Exception {
34          new PmdAssert(
35              "UnusedPrivateFieldTrulyUnused.java",
36              Matchers.any(Boolean.class),
37              Matchers.containsString("(UnusedPrivateField)")
38          ).assertOk();
39      }
40  }