1 package org.codehaus.plexus.context;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import java.io.StringReader;
20 import java.io.StringWriter;
21
22 import junit.framework.TestCase;
23 import org.codehaus.plexus.util.IOUtil;
24 import org.codehaus.plexus.util.InterpolationFilterReader;
25
26
27
28
29
30
31 public class ContextMapAdapterTest extends TestCase {
32 public ContextMapAdapterTest(String name) {
33 super(name);
34 }
35
36 public void testInterpolation() throws Exception {
37 DefaultContext context = new DefaultContext();
38
39 context.put("name", "jason");
40
41 context.put("occupation", "exotic dancer");
42
43 ContextMapAdapter adapter = new ContextMapAdapter(context);
44
45 assertEquals("jason", (String) adapter.get("name"));
46
47 assertEquals("exotic dancer", (String) adapter.get("occupation"));
48
49 assertNull(adapter.get("foo"));
50 }
51
52 public void testInterpolationWithContext() throws Exception {
53 DefaultContext context = new DefaultContext();
54 context.put("name", "jason");
55 context.put("noun", "asshole");
56
57 String foo = "${name} is an ${noun}. ${not.interpolated}";
58
59 InterpolationFilterReader reader =
60 new InterpolationFilterReader(new StringReader(foo), new ContextMapAdapter(context));
61
62 StringWriter writer = new StringWriter();
63 IOUtil.copy(reader, writer);
64
65 String bar = writer.toString();
66 assertEquals("jason is an asshole. ${not.interpolated}", bar);
67 }
68 }