KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > nodes > PropertiesTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.openide.nodes;
21
22 import junit.textui.TestRunner;
23 import org.netbeans.junit.NbTestCase;
24 import org.netbeans.junit.NbTestSuite;
25
26
27
28 /**
29  * @author Some Czech
30  */

31 public class PropertiesTest extends NbTestCase {
32
33     public PropertiesTest(String JavaDoc name) {
34         super(name);
35     }
36
37     public static void main(String JavaDoc[] args) {
38         TestRunner.run(new NbTestSuite(PropertiesTest.class));
39     }
40
41     public void testReflection() throws Exception JavaDoc {
42
43         Node.Property np = null;
44
45         // Test normal property
46
TestBean tb = new TestBean();
47         np = new PropertySupport.Reflection( tb, int.class, "number" );
48         assertEquals( "Value", np.getValue(), new Integer JavaDoc( 1 ) );
49         
50         // Test setter only of type String
51
NoSuchMethodException JavaDoc thrownException = null;
52         try {
53             np = new PropertySupport.Reflection( tb, String JavaDoc.class, "setterOnlyString" );
54         }
55         catch ( NoSuchMethodException JavaDoc e ){
56             thrownException = e;
57         }
58         assertNotNull( "Exception should be thrown", thrownException );
59         
60         // Test setter only of type boolean
61
thrownException = null;
62         try {
63             np = new PropertySupport.Reflection( tb, boolean.class, "setterOnlyBoolean" );
64         }
65         catch ( NoSuchMethodException JavaDoc e ){
66             thrownException = e;
67         }
68         assertNotNull( "Exception should be thrown", thrownException );
69         
70         // Test no boolean with is
71
thrownException = null;
72         try {
73             np = new PropertySupport.Reflection( tb, long.class, "isSetLong" );
74         }
75         catch ( NoSuchMethodException JavaDoc e ){
76             thrownException = e;
77         }
78         assertNotNull( "Exception should be thrown", thrownException );
79         
80         
81         // Test get/set boolean
82
np = new PropertySupport.Reflection( tb, boolean.class, "getSetBoolean" );
83         assertEquals( "Value", np.getValue(), Boolean.TRUE );
84                 
85         // Test is/set boolean
86
np = new PropertySupport.Reflection( tb, boolean.class, "isSetBoolean" );
87         assertEquals( "Value", np.getValue(), Boolean.TRUE );
88         
89     }
90     
91     public static class TestBean {
92         
93         public int getNumber() {
94             return 1;
95         }
96         
97         public void setNumber( int number ) {
98         }
99         
100         public void setSetterOnlyString( String JavaDoc text ) {
101         }
102         
103         public void setSetterOnlyBoolean( boolean value ) {
104         }
105         
106         public long isIsSetLong() {
107             return 10L;
108         }
109         
110         public void setIsSetLong( long value ) {
111         }
112         
113         public boolean getGetSetBoolean() {
114             return true;
115         }
116         
117         public void setGetSetBoolean( boolean value ) {
118         }
119         
120         
121         public boolean isIsSetBoolean() {
122             return true;
123         }
124         
125         public void setIsSetBoolean( boolean value ) {
126         }
127     }
128     
129
130 }
131
Popular Tags