1 package org.apache.velocity.test;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.ArrayList;
23 import java.util.List;
24
25 import junit.framework.Test;
26 import junit.framework.TestSuite;
27
28 import org.apache.velocity.runtime.RuntimeInstance;
29 import org.apache.velocity.util.StringUtils;
30
31
32
33
34
35
36
37
38 public class MiscTestCase extends BaseTestCase
39 {
40 public MiscTestCase (String name)
41 {
42 super(name);
43 }
44
45 public static Test suite ()
46 {
47 return new TestSuite(MiscTestCase.class);
48 }
49
50 public void testRuntimeInstanceProperties()
51 {
52
53 RuntimeInstance ri = new RuntimeInstance();
54 ri.setProperty("baabaa.test","the answer");
55 assertEquals("the answer",ri.getProperty("baabaa.test"));
56 }
57
58 public void testStringUtils()
59 {
60
61
62
63
64 String eol = "XY";
65
66 String arg = "XY";
67 String res = StringUtils.chop(arg, 1, eol );
68 assertTrue( "Test 1", res.equals("") );
69
70 arg = "X";
71 res = StringUtils.chop( arg, 1, eol );
72 assertTrue( "Test 2", res.equals("") );
73
74 arg = "ZXY";
75 res = StringUtils.chop( arg, 1, eol );
76 assertTrue( "Test 3", res.equals("Z") );
77
78
79 arg = "Hello!";
80 res = StringUtils.chop( arg, 2, eol );
81 assertTrue( "Test 4", res.equals("Hell"));
82
83 arg = null;
84 res = StringUtils.nullTrim(arg);
85 assertNull(arg);
86
87 arg = " test ";
88 res = StringUtils.nullTrim(arg);
89 assertEquals("test",res);
90
91 arg = "test";
92 res = StringUtils.nullTrim(arg);
93 assertEquals("test",res);
94
95 List list = null;
96 assertNull(StringUtils.trimStrings(list));
97
98 list = new ArrayList();
99 assertEquals(new ArrayList(),StringUtils.trimStrings(list));
100
101 list.add("test");
102 list.add(" abc");
103 StringUtils.trimStrings(list);
104 assertEquals("test",list.get(0));
105 assertEquals("abc",list.get(1));
106
107 }
108
109 }