1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.mina.statemachine.context;
21
22 import java.util.HashMap;
23 import java.util.Map;
24
25 import org.apache.mina.statemachine.context.AbstractStateContextLookup;
26 import org.apache.mina.statemachine.context.DefaultStateContextFactory;
27 import org.apache.mina.statemachine.context.StateContext;
28
29 import junit.framework.TestCase;
30
31
32
33
34
35
36
37 public class AbstractStateContextLookupTest extends TestCase {
38
39 public void testLookup() throws Exception {
40 Map<String, StateContext> map = new HashMap<String, StateContext>();
41 AbstractStateContextLookup lookup = new AbstractStateContextLookup(
42 new DefaultStateContextFactory()) {
43 protected boolean supports(Class<?> c) {
44 return Map.class.isAssignableFrom(c);
45 }
46 @SuppressWarnings("unchecked")
47 protected StateContext lookup(Object eventArg) {
48 Map<String, StateContext> map = (Map<String, StateContext>) eventArg;
49 return map.get("context");
50 }
51 @SuppressWarnings("unchecked")
52 protected void store(Object eventArg, StateContext context) {
53 Map<String, StateContext> map = (Map<String, StateContext>) eventArg;
54 map.put("context", context);
55 }
56 };
57 Object[] args1 = new Object[] {new Object(), map, new Object()};
58 Object[] args2 = new Object[] {map, new Object()};
59 StateContext sc = lookup.lookup(args1);
60 assertSame(map.get("context"), sc);
61 assertSame(map.get("context"), lookup.lookup(args1));
62 assertSame(map.get("context"), lookup.lookup(args2));
63 }
64
65 }