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