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 public class AbstractStateContextLookupTest extends TestCase {
37
38 public void testLookup() throws Exception {
39 Map<String, StateContext> map = new HashMap<String, StateContext>();
40 AbstractStateContextLookup lookup = new AbstractStateContextLookup(
41 new DefaultStateContextFactory()) {
42 protected boolean supports(Class<?> c) {
43 return Map.class.isAssignableFrom(c);
44 }
45 @SuppressWarnings("unchecked")
46 protected StateContext lookup(Object eventArg) {
47 Map<String, StateContext> map = (Map<String, StateContext>) eventArg;
48 return map.get("context");
49 }
50 @SuppressWarnings("unchecked")
51 protected void store(Object eventArg, StateContext context) {
52 Map<String, StateContext> map = (Map<String, StateContext>) eventArg;
53 map.put("context", context);
54 }
55 };
56 Object[] args1 = new Object[] {new Object(), map, new Object()};
57 Object[] args2 = new Object[] {map, new Object()};
58 StateContext sc = lookup.lookup(args1);
59 assertSame(map.get("context"), sc);
60 assertSame(map.get("context"), lookup.lookup(args1));
61 assertSame(map.get("context"), lookup.lookup(args2));
62 }
63
64 }