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    *      https://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.lang3.text.translate;
19  
20  import static org.junit.jupiter.api.Assertions.assertEquals;
21  import static org.junit.jupiter.api.Assertions.assertTrue;
22  
23  import java.util.HashSet;
24  import java.util.Set;
25  
26  import org.apache.commons.lang3.AbstractLangTest;
27  import org.junit.jupiter.api.Test;
28  
29  /**
30   * Tests for {@link org.apache.commons.lang3.text.translate.EntityArrays}.
31   */
32  @Deprecated
33  class EntityArraysTest extends AbstractLangTest {
34  
35      @Test
36      void testBasicApostrophe() {
37          assertEquals("'", new LookupTranslator(EntityArrays.BASIC_ESCAPE()).translate("'"));
38          assertEquals("'", new LookupTranslator(EntityArrays.BASIC_UNESCAPE()).translate("'"));
39      }
40  
41      @Test
42      void testConstructorExists() {
43          new EntityArrays();
44      }
45  
46      // LANG-659 - check arrays for duplicate entries
47      @Test
48      void testHTML40_EXTENDED_ESCAPE() {
49          final Set<String> col0 = new HashSet<>();
50          final Set<String> col1 = new HashSet<>();
51          final String[][] sa = EntityArrays.HTML40_EXTENDED_ESCAPE();
52          for (int i = 0; i < sa.length; i++) {
53              assertTrue(col0.add(sa[i][0]), "Already added entry 0: " + i + " " + sa[i][0]);
54              assertTrue(col1.add(sa[i][1]), "Already added entry 1: " + i + " " + sa[i][1]);
55          }
56      }
57  
58      // LANG-658 - check arrays for duplicate entries
59      @Test
60      void testISO8859_1_ESCAPE() {
61          final Set<String> col0 = new HashSet<>();
62          final Set<String> col1 = new HashSet<>();
63          final String[][] sa = EntityArrays.ISO8859_1_ESCAPE();
64          boolean success = true;
65          for (int i = 0; i < sa.length; i++) {
66              final boolean add0 = col0.add(sa[i][0]);
67              final boolean add1 = col1.add(sa[i][1]);
68              if (!add0) {
69                  success = false;
70                  System.out.println("Already added entry 0: " + i + " " + sa[i][0] + " " + sa[i][1]);
71              }
72              if (!add1) {
73                  success = false;
74                  System.out.println("Already added entry 1: " + i + " " + sa[i][0] + " " + sa[i][1]);
75              }
76          }
77          assertTrue(success, "One or more errors detected");
78      }
79  
80  }