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