KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > cintoo > messages > context > TestDefaultContextMap


1 package cintoo.messages.context;
2
3 import api.cintoo.messages.context.ContextMap;
4 import api.cintoo.messages.context.Context;
5 import org.testng.annotations.*;
6 import org.testng.Assert;
7
8 import static org.easymock.EasyMock.*;
9
10 public class TestDefaultContextMap {
11
12   private ContextMap map;
13
14   @Configuration(beforeTestMethod = true)
15   public void setUp() {
16     map = new DefaultContextMap();
17   }
18
19   @Test
20   public void testSet() {
21     Context context = createMock(Context.class);
22     map.put(context, "test1");
23     Assert.assertEquals(map.get(context), "test1", "ContextMap returns correct name");
24   }
25
26   @Test
27   public void testMatchingContext() {
28     Context context = PackageContext.string("a.b");
29     map.put(context, "test1");
30     map.put(PackageContext.string("c.d"), "test2");
31     map.put(PackageContext.string("a"), "test3");
32     Context found = map.findMatchingContext(PackageContext.string("a.b.c"));
33     Assert.assertEquals(found, context, "ContextMap finds correct matching context");
34   }
35
36   @Test
37   public void testParentContextWithTwo() {
38     Context context = PackageContext.string("a.b");
39     map.put(PackageContext.string("a"), "test2");
40     map.put(context, "test1");
41     Context parent = map.findParentContext(context);
42     Assert.assertEquals(parent, PackageContext.string("a"), "ContextMap finds correct parent context");
43   }
44
45   @Test
46   public void testParentContext() {
47     Context context = PackageContext.string("a.b");
48     map.put(context, "test1");
49     map.put(PackageContext.string("a"), "test2");
50     map.put(PackageContext.string("a.b.c"), "test3");
51     Context parent = map.findParentContext(context);
52     Assert.assertEquals(parent, PackageContext.string("a"), "ContextMap finds correct parent context");
53   }
54
55   @Test
56   public void testChildContext() {
57     Context context = PackageContext.string("a.b");
58     map.put(context, "test1");
59     map.put(PackageContext.string("a"), "test2");
60     map.put(PackageContext.string("a.b.c"), "test3");
61     Context parent = map.findChildContext(context);
62     Assert.assertEquals(parent, PackageContext.string("a.b.c"), "ContextMap finds correct child context");
63   }
64
65 }
66
Popular Tags