01: /**
02: * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
03: */package test.net.sourceforge.pmd.util;
04:
05: import static org.junit.Assert.assertEquals;
06: import net.sourceforge.pmd.util.StringUtil;
07:
08: import org.junit.Ignore;
09: import org.junit.Test;
10:
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
21: .replaceString("foo", 'o', "aa"));
22: }
23:
24: @Test
25: public void testReplaceStringWithString() {
26: assertEquals("foo]]>bar", StringUtil.replaceString(
27: "foo]]>bar", "]]>", "]]>"));
28: }
29:
30: @Test
31: public void testReplaceStringWithString2() {
32: assertEquals("replaceString didn't work with a >", "foobar",
33: StringUtil.replaceString("foobar", "]]>", "]]>"));
34: }
35:
36: @Test
37: public void testReplaceWithNull() {
38: assertEquals("replaceString didn't work with a char", "f",
39: StringUtil.replaceString("foo", 'o', null));
40: }
41:
42: @Ignore
43: @Test
44: public void testUTF8NotSupported() {
45: System.setProperty("net.sourceforge.pmd.supportUTF8", "no");
46: StringBuffer sb = new StringBuffer();
47: String test = "é";
48: StringUtil.appendXmlEscaped(sb, test);
49: assertEquals("é", sb.toString());
50: }
51:
52: @Ignore
53: @Test
54: public void testUTF8Supported() {
55: System.setProperty("net.sourceforge.pmd.supportUTF8", "yes");
56: StringBuffer sb = new StringBuffer();
57: String test = "é";
58: StringUtil.appendXmlEscaped(sb, test);
59: assertEquals("é", sb.toString());
60: System.setProperty("net.sourceforge.pmd.supportUTF8", "no");
61: }
62:
63: public static junit.framework.Test suite() {
64: return new junit.framework.JUnit4TestAdapter(
65: StringUtilTest.class);
66: }
67: }
|