View Javadoc
1   package com.atlassian.refapp.sal.pluginsettings;
2   
3   import junit.framework.TestCase;
4   
5   public class TestXmlUtils extends TestCase {
6       public void testEscape() {
7           // no special code to be escaped.
8           assertEquals("hello world", XmlUtils.escape("hello world"));
9   
10          // null input should return null
11          assertEquals(null, XmlUtils.escape(null));
12  
13          // special chars should be escaped but \n is legit in XML so it doesn't have to be escaped.
14          assertEquals("hello!@#$000Cworld\nyeehaw!@#$0008hoho", XmlUtils.escape("hello\fworld\nyeehaw\bhoho"));
15      }
16  
17      public void testUnescape() {
18          // no escape should just return the input.
19          assertEquals("hello world", XmlUtils.unescape("hello world"));
20  
21          // null input should return null
22          assertEquals(null, XmlUtils.unescape(null));
23  
24          // this should deescape all the special sequences.
25          assertEquals("hello\fworld\nyeehaw\bhoho", XmlUtils.unescape("hello!@#$000Cworld\nyeehaw!@#$0008hoho"));
26  
27          // this should not get deescape since the escape sequence is incomplete.
28          assertEquals("hello!@#000Cworld", XmlUtils.unescape("hello!@#000Cworld"));
29  
30          // this should not get deescape since the escape sequence is incomplete.
31          assertEquals("hello!@#$000%world", XmlUtils.unescape("hello!@#$000%world"));
32  
33          // this should not get deescape since the escape sequence is incomplete.
34          assertEquals("hello!@ !@# !@#$ !! @@ ## $$ !@#$54", XmlUtils.unescape("hello!@ !@# !@#$ !! @@ ## $$ !@#$54"));
35  
36          // if the first escaping symbol is the last character in string. it should not try to unescape or crash.
37          assertEquals("hello!", XmlUtils.unescape("hello!"));
38      }
39  }