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.hamcrest.core.IsEqual;
9   import org.hamcrest.text.IsEmptyString;
10  import org.junit.jupiter.api.Test;
11  
12  /**
13   * Test case for {@link com.qulice.pmd.rules.UseCollectionsSingletonListRule}.
14   * @since 0.26.0
15   */
16  final class UseCollectionsSingletonListRuleTest {
17  
18      /**
19       * Error message produced by the rule.
20       */
21      private static final String MESSAGE =
22          "Use Collections.singletonList instead of Arrays.asList with a single non-array argument";
23  
24      @Test
25      void detectsArraysAsListWithSingleScalar() throws Exception {
26          new PmdAssert(
27              "ArraysAsListSingleScalar.java",
28              new IsEqual<>(false),
29              Matchers.containsString(
30                  UseCollectionsSingletonListRuleTest.MESSAGE
31              )
32          ).assertOk();
33      }
34  
35      @Test
36      void allowsMultipleArgumentsAndArrayArgument() throws Exception {
37          new PmdAssert(
38              "ArraysAsListAllowedCases.java",
39              new IsEqual<>(true),
40              IsEmptyString.emptyString()
41          ).assertOk();
42      }
43  }