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 ExcessiveParameterList} rule, which skips constructors but stays
13   * active on methods, and which lets
14   * {@code UnnecessaryWarningSuppression} report a suppression left on a
15   * constructor.
16   * Regression test for https://github.com/yegor256/qulice/issues/1763
17   * and https://github.com/yegor256/qulice/issues/1775
18   *
19   * @since 1.0
20   */
21  final class PmdExcessiveParameterListTest {
22  
23      @Test
24      void doesNotFireOnConstructorWithManyParameters() throws Exception {
25          new PmdAssert(
26              "ExcessiveParameterListInConstructor.java",
27              Matchers.any(Boolean.class),
28              Matchers.not(
29                  Matchers.containsString("(ExcessiveParameterList)")
30              )
31          ).assertOk();
32      }
33  
34      @Test
35      void firesOnMethodWithManyParameters() throws Exception {
36          new PmdAssert(
37              "ExcessiveParameterListInMethod.java",
38              Matchers.is(false),
39              Matchers.containsString("(ExcessiveParameterList)")
40          ).assertOk();
41      }
42  
43      @Test
44      void reportsRedundantSuppressionOnConstructor() throws Exception {
45          new PmdAssert(
46              "ExcessiveParameterListSuppressedInConstructor.java",
47              Matchers.is(false),
48              Matchers.containsString("(UnnecessaryWarningSuppression)")
49          ).assertOk();
50      }
51  
52      @Test
53      void honoursSuppressionOnMethod() throws Exception {
54          new PmdAssert(
55              "ExcessiveParameterListSuppressedInMethod.java",
56              Matchers.any(Boolean.class),
57              Matchers.allOf(
58                  Matchers.not(
59                      Matchers.containsString("(ExcessiveParameterList)")
60                  ),
61                  Matchers.not(
62                      Matchers.containsString("(UnnecessaryWarningSuppression)")
63                  )
64              )
65          ).assertOk();
66      }
67  }