1 /**
2 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3 */
4 package test.net.sourceforge.pmd.util;
5
6 import static org.junit.Assert.assertEquals;
7 import net.sourceforge.pmd.util.StringUtil;
8
9 import org.junit.Ignore;
10 import org.junit.Test;
11 public class StringUtilTest {
12
13 @Test
14 public void testReplaceWithOneChar() {
15 assertEquals("faa", StringUtil.replaceString("foo", 'o', "a"));
16 }
17
18 @Test
19 public void testReplaceWithMultipleChars() {
20 assertEquals("faaaa", StringUtil.replaceString("foo", 'o', "aa"));
21 }
22
23 @Test
24 public void testReplaceStringWithString() {
25 assertEquals("foo]]>bar", StringUtil.replaceString("foo]]>bar", "]]>", "]]>"));
26 }
27
28 @Test
29 public void testReplaceStringWithString2() {
30 assertEquals("replaceString didn't work with a >", "foobar", StringUtil.replaceString("foobar", "]]>", "]]>"));
31 }
32
33 @Test
34 public void testReplaceWithNull() {
35 assertEquals("replaceString didn't work with a char", "f", StringUtil.replaceString("foo", 'o', null));
36 }
37
38 @Ignore
39 @Test
40 public void testUTF8NotSupported() {
41 System.setProperty("net.sourceforge.pmd.supportUTF8","no");
42 StringBuffer sb = new StringBuffer();
43 String test = "?";
44 StringUtil.appendXmlEscaped(sb, test);
45 assertEquals("é", sb.toString());
46 }
47
48 @Ignore
49 @Test
50 public void testUTF8Supported() {
51 System.setProperty("net.sourceforge.pmd.supportUTF8","yes");
52 StringBuffer sb = new StringBuffer();
53 String test = "?";
54 StringUtil.appendXmlEscaped(sb, test);
55 assertEquals("?", sb.toString());
56 System.setProperty("net.sourceforge.pmd.supportUTF8","no");
57 }
58
59 public static junit.framework.Test suite() {
60 return new junit.framework.JUnit4TestAdapter(StringUtilTest.class);
61 }
62 }
63