KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > test > core > ProxyValidatorTestCase


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

9 package org.jboss.portal.test.core;
10
11 import java.util.List JavaDoc;
12
13 import junit.framework.TestCase;
14
15 import org.jboss.portal.core.util.ProxyValidator;
16
17 /**
18  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
19  * @version $Revision: 1.2 $
20  */

21 public class ProxyValidatorTestCase extends TestCase
22 {
23    public ProxyValidatorTestCase(String JavaDoc key)
24    {
25       super(key);
26    }
27
28    public void testInvalidMethod()
29    {
30       ProxyValidator.Error[] errors = ProxyValidator.validate(InvalidMethod.class);
31       assertEquals(1, errors.length);
32       assertEquals(ProxyValidator.METHOD_NOT_ACCESSOR, errors[0].getCode());
33       assertNotNull(errors[0].getMethod());
34    }
35
36    public interface InvalidMethod
37    {
38       void notASetterNorAGetter();
39    }
40
41    public void testGetterDuplicateName()
42    {
43       ProxyValidator.Error[] errors = ProxyValidator.validate(GetterDuplicateName.class);
44       assertEquals(1, errors.length);
45       assertEquals(ProxyValidator.GETTER_DUPLICATE_NAME, errors[0].getCode());
46       assertNotNull(errors[0].getMethod());
47    }
48
49    public interface GetterDuplicateName
50    {
51       int getA(int a);
52       boolean getA(boolean a);
53    }
54
55    public void testGetterInvalidName()
56    {
57       ProxyValidator.Error[] errors = ProxyValidator.validate(GetterInvalidName.class);
58       assertEquals(1, errors.length);
59       assertEquals(ProxyValidator.GETTER_INVALID_NAME, errors[0].getCode());
60       assertNotNull(errors[0].getMethod());
61    }
62
63    public interface GetterInvalidName
64    {
65       int get(int a);
66    }
67
68    public void testGetterInvalidReturnType()
69    {
70       ProxyValidator.Error[] errors = ProxyValidator.validate(GetterInvalidReturnType.class);
71       assertEquals(1, errors.length);
72       assertEquals(ProxyValidator.GETTER_INVALID_RETURN_TYPE, errors[0].getCode());
73       assertNotNull(errors[0].getMethod());
74    }
75
76    public interface GetterInvalidReturnType
77    {
78       List JavaDoc getA(List JavaDoc a);
79    }
80
81    public void testGetterNoArgument()
82    {
83       ProxyValidator.Error[] errors = ProxyValidator.validate(GetterNoArgument.class);
84       assertEquals(1, errors.length);
85       assertEquals(ProxyValidator.GETTER_NO_ARGUMENT, errors[0].getCode());
86       assertNotNull(errors[0].getMethod());
87    }
88
89    public interface GetterNoArgument
90    {
91       int getA();
92    }
93
94    public void testGetterReturnTypeDoesNotMatchArgumentType()
95    {
96       ProxyValidator.Error[] errors = ProxyValidator.validate(GetterReturnTypeDoesNotMatchArgumentType.class);
97       assertEquals(1, errors.length);
98       assertEquals(ProxyValidator.GETTER_RETURN_TYPE_DOES_NOT_MATCH_ARGUMENT_TYPE, errors[0].getCode());
99       assertNotNull(errors[0].getMethod());
100    }
101
102    public interface GetterReturnTypeDoesNotMatchArgumentType
103    {
104       int getA(boolean a);
105    }
106
107    public void testGetterTooManyArgument()
108    {
109       ProxyValidator.Error[] errors = ProxyValidator.validate(GetterTooManyArgument.class);
110       assertEquals(1, errors.length);
111       assertEquals(ProxyValidator.GETTER_TOO_MANY_ARGUMENTS, errors[0].getCode());
112       assertNotNull(errors[0].getMethod());
113    }
114
115    public interface GetterTooManyArgument
116    {
117       int getA(int a, int b);
118    }
119
120    public void testSetterDuplicateName()
121    {
122       ProxyValidator.Error[] errors = ProxyValidator.validate(SetterDuplicateName.class);
123       assertEquals(1, errors.length);
124       assertEquals(ProxyValidator.SETTER_DUPLICATE_NAME, errors[0].getCode());
125       assertNotNull(errors[0].getMethod());
126    }
127
128    public interface SetterDuplicateName
129    {
130       void setA(int a);
131       void setA(boolean a);
132    }
133
134    public void testSetterInvalidName()
135    {
136       ProxyValidator.Error[] errors = ProxyValidator.validate(SetterInvalidName.class);
137       assertEquals(1, errors.length);
138       assertEquals(ProxyValidator.SETTER_INVALID_NAME, errors[0].getCode());
139       assertNotNull(errors[0].getMethod());
140    }
141
142    public interface SetterInvalidName
143    {
144       void set(int a);
145    }
146
147    public void testSetterInvalidType()
148    {
149       ProxyValidator.Error[] errors = ProxyValidator.validate(SetterInvalidType.class);
150       assertEquals(1, errors.length);
151       assertEquals(ProxyValidator.SETTER_INVALID_ARGUMENT_TYPE, errors[0].getCode());
152       assertNotNull(errors[0].getMethod());
153    }
154
155    public interface SetterInvalidType
156    {
157       void setA(List JavaDoc a);
158    }
159
160    public void testSetterNoArgument()
161    {
162       ProxyValidator.Error[] errors = ProxyValidator.validate(SetterNoArgument.class);
163       assertEquals(1, errors.length);
164       assertEquals(ProxyValidator.SETTER_NO_ARGUMENT, errors[0].getCode());
165       assertNotNull(errors[0].getMethod());
166    }
167
168    public interface SetterNoArgument
169    {
170       void setA();
171    }
172
173    public void testSetterReturnTypeIsNotVoid()
174    {
175       ProxyValidator.Error[] errors = ProxyValidator.validate(SetterReturnTypeIsNotVoid.class);
176       assertEquals(1, errors.length);
177       assertEquals(ProxyValidator.SETTER_RETURN_TYPE_IS_NOT_VOID, errors[0].getCode());
178       assertNotNull(errors[0].getMethod());
179    }
180
181    public interface SetterReturnTypeIsNotVoid
182    {
183       int setA(int a);
184    }
185
186    public void testSetterTooManyArguments()
187    {
188       ProxyValidator.Error[] errors = ProxyValidator.validate(SetterTooManyArguments.class);
189       assertEquals(1, errors.length);
190       assertEquals(ProxyValidator.SETTER_TOO_MANY_ARGUMENTS, errors[0].getCode());
191       assertNotNull(errors[0].getMethod());
192    }
193
194    public interface SetterTooManyArguments
195    {
196       void setA(int a, int b);
197    }
198 }
199
Popular Tags