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