1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.text.translate;
18
19 import static org.junit.jupiter.api.Assertions.assertEquals;
20
21 import org.junit.jupiter.api.Test;
22
23
24
25
26 class JavaUnicodeEscaperTest {
27
28 @Test
29 void testAbove() {
30 final JavaUnicodeEscaper jue = JavaUnicodeEscaper.above('F');
31 final String input = "ADFGZ";
32 final String result = jue.translate(input);
33 assertEquals("ADF\\u0047\\u005A", result, "Failed to escape Unicode characters via the above method");
34 }
35
36 @Test
37 void testBelow() {
38 final JavaUnicodeEscaper jue = JavaUnicodeEscaper.below('F');
39 final String input = "ADFGZ";
40 final String result = jue.translate(input);
41 assertEquals("\\u0041\\u0044FGZ", result, "Failed to escape Unicode characters via the below method");
42 }
43
44 @Test
45 void testBetween() {
46 final JavaUnicodeEscaper jue = JavaUnicodeEscaper.between('F', 'L');
47 final String input = "ADFGZ";
48 final String result = jue.translate(input);
49 assertEquals("AD\\u0046\\u0047Z", result, "Failed to escape Unicode characters via the between method");
50 }
51
52 @Test
53 void testToUtf16Escape() {
54 final JavaUnicodeEscaper jue = JavaUnicodeEscaper.below('F');
55
56
57
58 final String encoding = jue.toUtf16Escape(Integer.parseInt("024B62", 16));
59 assertEquals("\\uD852\\uDF62", encoding);
60 }
61 }