KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > uitags > tagutil > TagBeanInfoTest


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

18 package net.sf.uitags.tagutil;
19
20 import java.beans.PropertyDescriptor JavaDoc;
21
22 import net.sf.uitags.tagutil.bean.TagBeanInfo;
23
24 import junit.framework.TestCase;
25
26 /**
27  * Tests {@link net.sf.uitags.tagutil.bean.TagBeanInfo}.
28  *
29  * @author jonni
30  * @version $Id: TagBeanInfoTest.java,v 1.3 2006/04/25 09:36:52 jonni Exp $
31  */

32 public final class TagBeanInfoTest extends TestCase {
33   /**
34    * The test fixture.
35    */

36   private JavaBeanClassBeanInfo info;
37
38   /**
39    * Main method for the tests.
40    *
41    * @param args main arguments
42    */

43   public static void main(String JavaDoc[] args) {
44     junit.textui.TestRunner.run(TagBeanInfoTest.class);
45   }
46
47   /** {@inheritDoc} */
48   protected void setUp() throws Exception JavaDoc {
49     super.setUp();
50     this.info = new JavaBeanClassBeanInfo();
51   }
52
53   /** {@inheritDoc} */
54   protected void tearDown() throws Exception JavaDoc {
55     super.tearDown();
56     this.info = null;
57   }
58
59
60
61   //////////////////////////////////
62
////////// Test methods //////////
63
//////////////////////////////////
64

65   /**
66    * Tests {@link TagBeanInfo#getPropertyDescriptors()} to make sure
67    * that only setter methods are recognized.
68    */

69   public void testGetPropertyDescriptors() {
70     PropertyDescriptor JavaDoc[] props = this.info.getPropertyDescriptors();
71
72     assertTrue(props.length == 2);
73
74     for (int i = 0; i < props.length; i++) {
75       assertTrue(
76           props[i].getName().equals("firstProp") ||
77           props[i].getName().equals("secondProp"));
78     }
79   }
80
81
82   //////////////////////////////////////////////////////////
83
////////// Helper classes to facilitate testing //////////
84
//////////////////////////////////////////////////////////
85

86   /**
87    * Introspected by {@link TagBeanInfo}.
88    */

89   public static class JavaBeanClass {
90     String JavaDoc s;
91     Long JavaDoc l;
92
93     public String JavaDoc getFirstProp() { return ""; }
94     public void setFirstProp(String JavaDoc s) {
95       this.s = s;
96     }
97
98     public Long JavaDoc getSecondProp() { return null; }
99     public void setSecondProp(Long JavaDoc l) {
100       this.l = l;
101     }
102
103     public String JavaDoc getThirdProp() { return ""; }
104   }
105
106   /**
107    * Exposes only the setter methods of
108    * {@link TagBeanInfoTest.JavaBeanClass}.
109    */

110   private static class JavaBeanClassBeanInfo extends TagBeanInfo {
111     // The inherited getPropertyDescriptors() does all the job.
112
}
113 }
114
Popular Tags