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.core.IsEqual;
8   import org.hamcrest.core.StringContains;
9   import org.junit.jupiter.api.Test;
10  
11  /**
12   * Test case for LocalVariableCouldBeFinal.
13   * @since 0.18
14   */
15  final class LocalVariableCouldBeFinalRuleTest {
16  
17      /**
18       * LocalVariableCouldBeFinal can detect when variable is not
19       * final and shows correct message.
20       * @throws Exception If something goes wrong
21       */
22      @Test
23      void detectLocalVariableCouldBeFinal() throws Exception {
24          new PmdAssert(
25              "LocalVariableCouldBeFinal.java",
26              new IsEqual<>(false),
27              new StringContains(
28                  String.join(
29                      " ",
30                      "PMD: LocalVariableCouldBeFinal.java[10-10]:",
31                      "Local variable 'nonfinal' could be declared final",
32                      "(LocalVariableCouldBeFinal)"
33                  )
34              )
35          ).assertOk();
36      }
37  }