View Javadoc

1   package com.atlassian.sal.core.pluginsettings;
2   
3   import org.junit.Test;
4   
5   import static org.junit.Assert.assertEquals;
6   
7   public class TestEscapeUtils {
8       @Test
9       public void testNoEscape() {
10          String value = "this is the value";
11          assertEquals(value, EscapeUtils.escape(value));
12      }
13  
14      @Test
15      public void testEscape() {
16          String value = "this is \fthe \nvalue";
17          assertEquals("this is \\fthe \\nvalue", EscapeUtils.escape(value));
18      }
19  
20      @Test
21      public void testUnescape() {
22          String value = "this \\fis \\nthe value";
23          assertEquals("this \fis \nthe value", EscapeUtils.unescape(value));
24      }
25  
26      @Test
27      public void testUnescapeNonescape() {
28          String value = "this \nis the \fvalue";
29          assertEquals(value, EscapeUtils.unescape(value));
30      }
31  
32      @Test
33      public void testFullCycle() {
34          runCheckFullCycle("this \nis the \fvalue");
35          runCheckFullCycle("this \\nis the \\fvalue");
36      }
37  
38      private void runCheckFullCycle(String value) {
39          assertEquals(value, EscapeUtils.unescape(EscapeUtils.escape(value)));
40      }
41  }