1
2
3
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
14
15
16 final class UseCollectionsSingletonListRuleTest {
17
18
19
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 }