KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > annotations > TestAnnotationUtils


1 // Copyright 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.tapestry.annotations;
16
17 import java.lang.reflect.Method JavaDoc;
18
19 import org.apache.hivemind.ApplicationRuntimeException;
20
21 /**
22  * Tests for {@link org.apache.tapestry.annotations.AnnotationUtils}.
23  *
24  * @author Howard M. Lewis Ship
25  * @since 4.0
26  */

27 public class TestAnnotationUtils extends BaseAnnotationTestCase
28 {
29     private String JavaDoc attemptGetPropertyName(Class JavaDoc clazz, String JavaDoc name)
30     {
31         Method JavaDoc m = findMethod(clazz, name);
32
33         return AnnotationUtils.getPropertyName(m);
34     }
35
36     public void testGetPropertyName()
37     {
38         assertEquals("stringValue", attemptGetPropertyName(Target.class, "getStringValue"));
39         assertEquals("intValue", attemptGetPropertyName(Target.class, "setIntValue"));
40         assertEquals("booleanValue", attemptGetPropertyName(Target.class, "isBooleanValue"));
41     }
42
43     public void testGetPropertyNameNotAGetter()
44     {
45         try
46         {
47             attemptGetPropertyName(Target.class, "notAGetter");
48             unreachable();
49         }
50         catch (ApplicationRuntimeException ex)
51         {
52             assertEquals(
53                     "Annotated method public abstract java.lang.String org.apache.tapestry.annotations.Target.notAGetter() "
54                             + "should be an accessor (no parameters), or a mutator (single parameter, returns void).",
55                     ex.getMessage());
56         }
57     }
58
59     public void testGetPropertyNameSetterNoParameters()
60     {
61         try
62         {
63             attemptGetPropertyName(Target.class, "setNoParameters");
64             unreachable();
65         }
66         catch (ApplicationRuntimeException ex)
67         {
68             assertEquals(
69                     "Annotated method public abstract void org.apache.tapestry.annotations.Target.setNoParameters() is named like a mutator method,"
70                             + " but takes an incorrect number of parameters (it should have exactly one parameter).",
71                     ex.getMessage());
72         }
73     }
74
75     public void testNonVoidSetter()
76     {
77         try
78         {
79             attemptGetPropertyName(Target.class, "setNonVoidMethod");
80             unreachable();
81         }
82         catch (ApplicationRuntimeException ex)
83         {
84             assertEquals(
85                     "Annotated method public abstract java.lang.String org.apache.tapestry.annotations.Target.setNonVoidMethod(java.lang.String) "
86                             + "is named like a mutator method, but does not return void.",
87                     ex.getMessage());
88         }
89     }
90
91     public void testGetterWithParameters()
92     {
93         try
94         {
95             attemptGetPropertyName(Target.class, "getHasParameters");
96             unreachable();
97         }
98         catch (ApplicationRuntimeException ex)
99         {
100             assertEquals(
101                     "Annotated method public abstract java.lang.String org.apache.tapestry.annotations.Target.getHasParameters(java.lang.String) "
102                             + "is expected to be an accessor, and should have no parameters.",
103                     ex.getMessage());
104         }
105     }
106
107     public void testGetterReturnsVoid()
108     {
109         try
110         {
111             attemptGetPropertyName(Target.class, "isVoidGetter");
112             unreachable();
113         }
114         catch (ApplicationRuntimeException ex)
115         {
116             assertEquals(
117                     "Annotated method public abstract void org.apache.tapestry.annotations.Target.isVoidGetter() "
118                             + "is named like an accessor method, but returns void.",
119                     ex.getMessage());
120         }
121     }
122
123 }
124
Popular Tags