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