View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.commons.codec.language.bm;
19  
20  import static org.junit.jupiter.api.Assertions.assertTrue;
21  
22  import java.util.stream.Stream;
23  
24  import org.junit.jupiter.params.ParameterizedTest;
25  import org.junit.jupiter.params.provider.Arguments;
26  import org.junit.jupiter.params.provider.MethodSource;
27  
28  /**
29   * Tests guessLanguages API.
30   */
31  public class LanguageGuessingTest {
32  
33      public static Stream<Arguments> data() {
34          return Stream.of(
35              Arguments.of("Renault", "french"),
36              Arguments.of("Mickiewicz", "polish"),
37              Arguments.of("Thompson", "english"), // this also hits german and greek latin
38              Arguments.of("Nu\u00f1ez", "spanish"), // Nuñez
39              Arguments.of("Carvalho", "portuguese"),
40              Arguments.of("\u010capek", "czech"), // Čapek
41              Arguments.of("Sjneijder", "dutch"),
42              Arguments.of("Klausewitz", "german"),
43              Arguments.of("K\u00fc\u00e7\u00fck", "turkish"), // Küçük
44              Arguments.of("Giacometti", "italian"),
45              Arguments.of("Nagy", "hungarian"),
46              Arguments.of("Ceau\u015fescu", "romanian"), // Ceauşescu
47              Arguments.of("Angelopoulos", "greeklatin"),
48              Arguments.of("\u0391\u03b3\u03b3\u03b5\u03bb\u03cc\u03c0\u03bf\u03c5\u03bb\u03bf\u03c2", "greek"), // Αγγελόπουλος
49              Arguments.of("\u041f\u0443\u0448\u043a\u0438\u043d", "cyrillic"), // Пушкин
50              Arguments.of("\u05db\u05d4\u05df", "hebrew"), // כהן
51              Arguments.of("\u00e1cz", "any"), // ácz
52              Arguments.of("\u00e1tz", "any") // átz
53          );
54      }
55  
56      private final Lang lang = Lang.instance(NameType.GENERIC);
57  
58      @ParameterizedTest
59      @MethodSource("data")
60      public void testLanguageGuessing(final String name, final String language) {
61          final Languages.LanguageSet guesses = this.lang.guessLanguages(name);
62  
63          assertTrue(guesses.contains(language),
64                  "language predicted for name '" + name + "' is wrong: " + guesses + " should contain '" + language + "'");
65      }
66  }