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   import org.junit.jupiter.params.ParameterizedTest;
10  import org.junit.jupiter.params.provider.ValueSource;
11  
12  /**
13   * Test case for {@link PmdValidator}'s rejection of unicode
14   * characters inside method names under the
15   * {@code MethodNamingConventions} rule.
16   *
17   * @since 0.25.1
18   */
19  final class PmdMethodNamingConventionsTest {
20  
21      @ParameterizedTest
22      @ValueSource(
23          strings = {
24              "JnaLibraryNames.java",
25              "JnaDirectNames.java",
26              "StdCallNames.java"
27          }
28      )
29      void allowsNativeNamesInJnaBinding(final String file) throws Exception {
30          new PmdAssert(
31              file,
32              Matchers.any(Boolean.class),
33              Matchers.not(
34                  Matchers.containsString("MethodNamingConventions")
35              )
36          ).assertOk();
37      }
38  
39      @Test
40      void rejectsNativeNamesOutsideJna() throws Exception {
41          new PmdAssert(
42              "FakeLibraryNames.java",
43              Matchers.is(false),
44              Matchers.containsString("MethodNamingConventions")
45          ).assertOk();
46      }
47  
48      @Test
49      void prohibitsUnicodeCharactersInMethodNames() throws Exception {
50          new PmdAssert(
51              "UnicodeCharactersInMethodNames.java",
52              Matchers.is(false),
53              Matchers.containsString("MethodNamingConventions")
54          ).assertOk();
55      }
56  }