01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
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: * Tests {@link AbstractStateContextLookup}.
33: *
34: * @author The Apache MINA Project (dev@mina.apache.org)
35: * @version $Rev: 589475 $, $Date: 2007-10-28 21:12:59 -0600 (Sun, 28 Oct 2007) $
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:
47: @SuppressWarnings("unchecked")
48: protected StateContext lookup(Object eventArg) {
49: Map<String, StateContext> map = (Map<String, StateContext>) eventArg;
50: return map.get("context");
51: }
52:
53: @SuppressWarnings("unchecked")
54: protected void store(Object eventArg, StateContext context) {
55: Map<String, StateContext> map = (Map<String, StateContext>) eventArg;
56: map.put("context", context);
57: }
58: };
59: Object[] args1 = new Object[] { new Object(), map, new Object() };
60: Object[] args2 = new Object[] { map, new Object() };
61: StateContext sc = lookup.lookup(args1);
62: assertSame(map.get("context"), sc);
63: assertSame(map.get("context"), lookup.lookup(args1));
64: assertSame(map.get("context"), lookup.lookup(args2));
65: }
66:
67: }
|