01: /*
02: * Copyright 2005-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
05: * in compliance with the License. You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * Unless required by applicable law or agreed to in writing, software distributed under the License
10: * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11: * or implied. See the License for the specific language governing permissions and limitations under
12: * the License.
13: */
14:
15: package org.strecks.injection.annotation;
16:
17: import org.strecks.injection.handler.impl.TestAction;
18: import org.strecks.injection.internal.InjectionSetter;
19: import org.testng.annotations.Test;
20:
21: /**
22: * @author Phil Zoio
23: */
24: public class TestInjectionSetter {
25:
26: @Test
27: public void testInjectionSetter() {
28: InjectionSetter setter = new InjectionSetter(TestAction.class,
29: "setIntegerInput", "integerInput", Integer.class);
30: TestAction action = new TestAction();
31: setter.setInput(action, new Integer(1));
32:
33: assert action.getIntegerInput().equals(1);
34: }
35:
36: @Test
37: public void testPrimitives() {
38: TestAction action = new TestAction();
39:
40: InjectionSetter setter = new InjectionSetter(TestAction.class,
41: "setByteInput", "byteInput", Byte.TYPE);
42: setter.setInput(action, null);
43: assert action.getByteInput() == 0;
44:
45: setter.setInput(action, Byte.valueOf((byte) 1));
46: assert action.getByteInput() == 1;
47:
48: setter = new InjectionSetter(TestAction.class,
49: "setBooleanInput", "booleanInput", Boolean.TYPE);
50: setter.setInput(action, null);
51: assert action.isBooleanInput() == false;
52:
53: setter.setInput(action, Boolean.TRUE);
54: assert action.isBooleanInput() == true;
55:
56: setter = new InjectionSetter(TestAction.class, "setShortInput",
57: "shortInput", Short.TYPE);
58: setter.setInput(action, null);
59: assert action.getShortInput() == 0;
60:
61: setter.setInput(action, (short) 2);
62: assert action.getShortInput() == 2;
63:
64: setter = new InjectionSetter(TestAction.class, "setIntInput",
65: "intInput", Integer.TYPE);
66: setter.setInput(action, null);
67: assert action.getIntInput() == 0;
68:
69: setter.setInput(action, 3);
70: assert action.getIntInput() == 3;
71:
72: setter = new InjectionSetter(TestAction.class,
73: "setPrimitiveLongInput", "primitiveLongInput",
74: Long.TYPE);
75: setter.setInput(action, null);
76: assert action.getPrimitiveLongInput() == 0;
77:
78: setter.setInput(action, 4L);
79: assert action.getPrimitiveLongInput() == 4;
80:
81: setter = new InjectionSetter(TestAction.class, "setFloatInput",
82: "floatInput", Float.TYPE);
83: setter.setInput(action, null);
84: assert action.getFloatInput() == 0;
85:
86: setter.setInput(action, 5.0F);
87: assert action.getFloatInput() == 5.0F;
88:
89: setter = new InjectionSetter(TestAction.class,
90: "setDoubleInput", "doubleInput", Double.TYPE);
91: setter.setInput(action, null);
92: assert action.getDoubleInput() == 0;
93:
94: setter.setInput(action, 6.2);
95: assert action.getDoubleInput() == 6.2;
96: }
97:
98: }
|