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