KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hudson > UtilTest


1 package hudson;
2
3 import junit.framework.TestCase;
4
5 import java.util.Map JavaDoc;
6 import java.util.HashMap JavaDoc;
7
8 /**
9  * @author Kohsuke Kawaguchi
10  */

11 public class UtilTest extends TestCase {
12     public void testReplaceMacro() {
13         Map JavaDoc<String JavaDoc,String JavaDoc> m = new HashMap JavaDoc<String JavaDoc,String JavaDoc>();
14         m.put("A","a");
15         m.put("AA","aa");
16         m.put("B","B");
17
18         // longest match
19
assertEquals("aa",Util.replaceMacro("$AA",m));
20
21         // invalid keys are ignored
22
assertEquals("$AAB",Util.replaceMacro("$AAB",m));
23
24     // test that more complex scenarios work
25
assertEquals("/a/B/aa", Util.replaceMacro("/$A/$B/$AA",m));
26         assertEquals("a-aa", Util.replaceMacro("$A-$AA",m));
27         assertEquals("/a/foo/can/B/you-believe_aa~it?", Util.replaceMacro("/$A/foo/can/$B/you-believe_$AA~it?",m));
28     }
29 }
30
Popular Tags