01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package org.apache.commons.betwixt.expression;
19:
20: import java.lang.reflect.Method;
21:
22: import junit.framework.Test;
23: import junit.framework.TestSuite;
24:
25: import org.apache.commons.betwixt.AbstractTestCase;
26:
27: /** Test harness for map updating
28: *
29: * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
30: * @version $Revision: 438373 $
31: */
32: public class TestUpdaters extends AbstractTestCase {
33:
34: public static Test suite() {
35: return new TestSuite(TestUpdaters.class);
36: }
37:
38: public TestUpdaters(String testName) {
39: super (testName);
40: }
41:
42: public void testMapUpdate() throws Exception {
43: Class[] params = { String.class, String.class };
44: Method method = AdderBean.class.getMethod("add", params);
45: MapEntryAdder adder = new MapEntryAdder(method);
46:
47: AdderBean bean = new AdderBean();
48: bean.add("UNSET", "UNSET");
49:
50: Updater keyUpdater = adder.getKeyUpdater();
51: Updater valueUpdater = adder.getValueUpdater();
52:
53: Context context = new Context();
54: context.setBean(bean);
55:
56: keyUpdater.update(context, "key");
57: valueUpdater.update(context, "value");
58:
59: assertEquals("AdderBean not updated (1)", "key", bean.getKey());
60: assertEquals("AdderBean not updated (2)", "value", bean
61: .getValue());
62:
63: keyUpdater.update(context, "new-key");
64: valueUpdater.update(context, "new-value");
65:
66: assertEquals("AdderBean not updated (1)", "new-key", bean
67: .getKey());
68: assertEquals("AdderBean not updated (2)", "new-value", bean
69: .getValue());
70:
71: }
72: }
|