KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > explorer > propertysheet > PropUtilsTest


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.explorer.propertysheet;
21
22 import junit.framework.TestCase;
23 import org.openide.nodes.Node;
24
25 /**
26  * @author mkrauskopf
27  */

28 public class PropUtilsTest extends TestCase {
29
30     public PropUtilsTest(String JavaDoc testName) {
31         super(testName);
32     }
33
34     public void testCreateHtmlTooltip() {
35         System.out.println("testCreateHtmlTooltip");
36         // slash-separated
37
String JavaDoc expectedResult = "<html><b><u>TitleTest</u></b><br>/usr/share/" +
38                 "java/netbeans-cvs-current/openide/test/unit/src/org/<br>" +
39                 "openide/explorer/propertysheet/SomeTest.java</html>";
40         String JavaDoc result = PropUtils.createHtmlTooltip("TitleTest",
41                 "/usr/share/java/netbeans-cvs-current/openide/test/unit/src" +
42                 "/org/openide/explorer/propertysheet/SomeTest.java");
43         assertEquals("Unexpected result. "
44                 + "\n Expected: " + expectedResult
45                 + "\n Actual : " + result,
46                 expectedResult, result);
47         
48         // comma-separated
49
expectedResult = "<html><b><u>TitleTest</u></b><br>Overridden to " +
50                 "supply different tooltips depending on mouse position<br> " +
51                 "(name, value, custom editor button). Will HTML-ize long " +
52                 "tooltips<br></html>";
53         result = PropUtils.createHtmlTooltip("TitleTest", "Overridden to supply " +
54                 "different tooltips depending on mouse position (name, value, " +
55                 "custom editor button). Will HTML-ize long tooltips");
56         assertEquals("Unexpected result. " +
57                 "\n Expected: " + expectedResult +
58                 "\n Actual : " + result,
59                 expectedResult, result);
60     }
61     
62     /* Tests whether "Restore Default Value" enabling/disabling works well. */
63     public void testRestoreDefaultValueBehaviour() {
64         System.out.println("testRestoreDefaultValueBehaviour");
65         
66         Node.Property trueProp = new OldModulePropertyWithSDVReturningTrue();
67         assertTrue("OldModuleProperty doesn't know about Node.Property.isDefaultValue()" +
68                 " therefore it should be enabled in every case.",
69                 PropUtils.shallBeRDVEnabled(trueProp));
70         
71         Node.Property falseProp = new PropertyWithSDVReturningFalse();
72         assertFalse("Property doesn't support default value. It should be " +
73                 "disabled", PropUtils.shallBeRDVEnabled(falseProp));
74         
75         Node.Property newIDVFalseProp = new BothMethodsOverridedPropertyWithIDSReturningFalse();
76         assertTrue("Correctly implemented property with isDefaultValue() " +
77                 "returning false should be enable.",
78                 PropUtils.shallBeRDVEnabled(newIDVFalseProp));
79         
80         Node.Property newIDVTrueProp = new BothMethodsOverridedPropertyWithIDSReturningTrue();
81         assertFalse("Correctly implemented property with isDefaultValue() " +
82                 "returning true should be disabled.",
83                 PropUtils.shallBeRDVEnabled(newIDVTrueProp));
84         
85         Node.Property noneOverrided = new DefaultTestProperty();
86         assertFalse("Correctly implemented property which doesn't override any " +
87                 "of the two method should be disabled",
88                 PropUtils.shallBeRDVEnabled(noneOverrided));
89     }
90     
91     /**
92      * Simulates property for old modules which didn't know about
93      * isDefaultValue() method but could overrode restoreDefaultValue().
94      */

95     private static final class OldModulePropertyWithSDVReturningTrue extends DefaultTestProperty {
96         public boolean supportsDefaultValue() {
97             return true;
98         }
99     }
100     
101     private static final class PropertyWithSDVReturningFalse extends DefaultTestProperty {
102         public boolean supportsDefaultValue() {
103             return false;
104         }
105     }
106     
107     /**
108      * Simulates correctly implemented property which override both methods.
109      */

110     private static final class BothMethodsOverridedPropertyWithIDSReturningFalse
111             extends DefaultTestProperty {
112         public boolean supportsDefaultValue() {
113             return true;
114         }
115         public boolean isDefaultValue() {
116             return false;
117         }
118     }
119     
120     private static final class BothMethodsOverridedPropertyWithIDSReturningTrue
121             extends DefaultTestProperty {
122         public boolean supportsDefaultValue() {
123             return true;
124         }
125         public boolean isDefaultValue() {
126             return true;
127         }
128     }
129     
130     /**
131      * Simulates correctly implemented property which doesn't override any of
132      * the methods (supportsDefaultValue(), isDefaultValue()).
133      */

134     private static class DefaultTestProperty extends Node.Property {
135         /** We don't need any of these method (or constructor) for our testing. */
136         public DefaultTestProperty() { super(Object JavaDoc.class); }
137         public void setValue(Object JavaDoc val) {}
138         public Object JavaDoc getValue() { return null; }
139         public boolean canWrite() { return false; }
140         public boolean canRead() { return false; }
141     }
142 }
143
Popular Tags