1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.commons.exec.util;
20
21 import java.util.HashMap;
22 import java.util.Map;
23
24 import junit.framework.TestCase;
25
26 public class StringUtilTest extends TestCase
27 {
28
29
30
31 public void testNoStringSubstitution() throws Exception
32 {
33 Map vars = new HashMap();
34 vars.put("foo", "FOO");
35 vars.put("bar", "BAR");
36
37 assertEquals("This is a FOO & BAR test", StringUtils.stringSubstitution("This is a FOO & BAR test", vars, true).toString());
38 }
39
40
41
42
43
44 public void testDefaultStringSubstitution() throws Exception
45 {
46 Map vars = new HashMap();
47 vars.put("foo", "FOO");
48 vars.put("bar", "BAR");
49
50 assertEquals("This is a FOO & BAR test", StringUtils.stringSubstitution("This is a ${foo} & ${bar} test", vars, true).toString());
51 assertEquals("This is a FOO & BAR test", StringUtils.stringSubstitution("This is a ${foo} & ${bar} test", vars, false).toString());
52 }
53
54
55
56
57
58 public void testIncompleteSubstitution() throws Exception {
59
60 Map vars = new HashMap();
61 vars.put("foo", "FOO");
62
63 assertEquals("This is a FOO & ${bar} test", StringUtils.stringSubstitution("This is a ${foo} & ${bar} test", vars, true).toString());
64
65 try
66 {
67 StringUtils.stringSubstitution("This is a ${foo} & ${bar} test", vars, false).toString();
68 fail();
69 }
70 catch(RuntimeException e)
71 {
72
73 }
74 }
75
76
77
78
79 public void testErroneousTemplate() throws Exception
80 {
81 Map vars = new HashMap();
82 vars.put("foo", "FOO");
83
84 assertEquals("This is a FOO & ${}} test", StringUtils.stringSubstitution("This is a ${foo} & ${}} test", vars, true).toString());
85 }
86 }