1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.lang3.text.translate;
19
20 import static org.junit.jupiter.api.Assertions.assertEquals;
21
22 import java.io.StringWriter;
23
24 import org.apache.commons.lang3.AbstractLangTest;
25 import org.junit.jupiter.api.Test;
26
27
28
29
30 @Deprecated
31 class NumericEntityEscaperTest extends AbstractLangTest {
32
33 @Test
34 void testAbove() {
35 final NumericEntityEscaper nee = NumericEntityEscaper.above('F');
36 final String input = "ADFGZ";
37 final String result = nee.translate(input);
38 assertEquals("ADFGZ", result, "Failed to escape numeric entities via the above method");
39 }
40
41 @Test
42 void testBelow() {
43 final NumericEntityEscaper nee = NumericEntityEscaper.below('F');
44 final String input = "ADFGZ";
45 final String result = nee.translate(input);
46 assertEquals("ADFGZ", result, "Failed to escape numeric entities via the below method");
47 }
48
49 @Test
50 void testBetween() {
51 final NumericEntityEscaper nee = NumericEntityEscaper.between('F', 'L');
52 final String input = "ADFGZ";
53 final String result = nee.translate(input);
54 assertEquals("ADFGZ", result, "Failed to escape numeric entities via the between method");
55 }
56
57 @Test
58 void testNumericEntityOverflow() throws Exception {
59
60
61
62 final NumericEntityUnescaper u = new NumericEntityUnescaper();
63 final StringWriter sw = new StringWriter();
64 int consumed = u.translate("�", 0, sw);
65 assertEquals(0, consumed);
66 assertEquals("", sw.toString());
67 consumed = u.translate("---�---", 0, sw);
68 assertEquals(0, consumed);
69 assertEquals("", sw.toString());
70 }
71
72
73 @Test
74 void testSupplementary() {
75 final NumericEntityEscaper nee = new NumericEntityEscaper();
76 final String input = "\uD803\uDC22";
77 final String expected = "𐰢";
78 final String result = nee.translate(input);
79 assertEquals(expected, result, "Failed to escape numeric entities supplementary characters");
80 }
81
82 @Test
83 void testValidCodePoint() throws Exception {
84
85 final NumericEntityUnescaper u = new NumericEntityUnescaper();
86 final StringWriter sw = new StringWriter();
87 final int consumed = u.translate("A", 0, sw);
88 assertEquals("A", sw.toString());
89 assertEquals(5, consumed);
90 }
91 }