1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.cubby.plugins.s2.beans;
17
18 import static org.junit.Assert.assertEquals;
19 import static org.junit.Assert.assertFalse;
20 import static org.junit.Assert.assertNotNull;
21 import static org.junit.Assert.assertNull;
22
23 import org.junit.Test;
24 import org.seasar.cubby.plugins.s2.spi.S2BeanDescProvider;
25 import org.seasar.cubby.spi.BeanDescProvider;
26 import org.seasar.cubby.spi.beans.BeanDesc;
27 import org.seasar.cubby.spi.beans.PropertyDesc;
28
29 public class S2BeanDescProviderTest {
30
31 BeanDescProvider beanDescProvider = new S2BeanDescProvider();
32
33 @Test
34 public void propertyDesc() throws Exception {
35 BeanDesc beanDesc = beanDescProvider.getBeanDesc(MyBean.class);
36 assertEquals(5, beanDesc.getPropertyDescs().length);
37 PropertyDesc propDesc = beanDesc.getPropertyDesc("aaa");
38 assertEquals("aaa", propDesc.getPropertyName());
39 assertEquals(String.class, propDesc.getPropertyType());
40 assertNotNull(propDesc.getReadMethod());
41 assertNull(propDesc.getWriteMethod());
42
43 propDesc = beanDesc.getPropertyDesc("CCC");
44 assertEquals("CCC", propDesc.getPropertyName());
45 assertEquals(boolean.class, propDesc.getPropertyType());
46 assertNotNull(propDesc.getReadMethod());
47 assertNull(propDesc.getWriteMethod());
48
49 propDesc = beanDesc.getPropertyDesc("eee");
50 assertEquals("eee", propDesc.getPropertyName());
51 assertEquals(String.class, propDesc.getPropertyType());
52 assertNotNull(propDesc.getReadMethod());
53 assertNotNull(propDesc.getWriteMethod());
54
55 propDesc = beanDesc.getPropertyDesc("fff");
56 assertEquals("fff", propDesc.getPropertyName());
57 assertEquals(Boolean.class, propDesc.getPropertyType());
58
59 assertFalse(beanDesc.hasPropertyDesc("hhh"));
60 assertFalse(beanDesc.hasPropertyDesc("iii"));
61 }
62
63 @Test
64 public void invalidProperty() throws Exception {
65 BeanDesc beanDesc = beanDescProvider.getBeanDesc(MyBean2.class);
66 assertEquals("1", false, beanDesc.hasPropertyDesc("aaa"));
67 }
68
69
70
71
72 public static interface MyInterface {
73
74
75
76 String HOGE = "hoge";
77 }
78
79
80
81
82 public static interface MyInterface2 extends MyInterface {
83
84
85
86 String HOGE = "hoge2";
87 }
88
89
90
91
92 public static class MyBean implements MyInterface2 {
93
94 private String aaa;
95
96 private String eee;
97
98
99
100
101 public String ggg;
102
103
104
105
106 public String getAaa() {
107 return aaa;
108 }
109
110
111
112
113
114 public String getBbb(Object a) {
115 return null;
116 }
117
118
119
120
121 public boolean isCCC() {
122 return true;
123 }
124
125
126
127
128 public Object isDdd() {
129 return null;
130 }
131
132
133
134
135 public String getEee() {
136 return eee;
137 }
138
139
140
141
142 public void setEee(String eee) {
143 this.eee = eee;
144 }
145
146
147
148
149 public Boolean isFff() {
150 return null;
151 }
152
153
154
155
156
157 public MyBean setHhh(String hhh) {
158 return this;
159 }
160
161
162
163
164 public void getIii() {
165 }
166
167
168
169
170
171
172 public Number add(Number arg1, Number arg2) {
173 return new Integer(3);
174 }
175
176
177
178
179
180
181 public int add2(int arg1, int arg2) {
182 return arg1 + arg2;
183 }
184
185
186
187
188
189 public Integer echo(Integer arg) {
190 return arg;
191 }
192
193
194
195
196 public void throwException() {
197 throw new IllegalStateException("hoge");
198 }
199 }
200
201
202
203
204 public class MyBean2 {
205
206
207
208 public MyBean2() {
209 }
210
211
212
213
214
215
216
217 public MyBean2(int num, String text, MyBean bean1, MyBean2 bean2) {
218 }
219
220
221
222
223 public void setAaa(int i) {
224 }
225
226
227
228
229 public void setAaa(String s) {
230 }
231 }
232
233 }