KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.*;
23 import junit.framework.*;
24 import junit.textui.TestRunner;
25 import org.openide.nodes.*;
26
27 import org.netbeans.junit.*;
28
29 /** Tests HTML display name contracts for filter nodes and regular nodes
30  *
31  * @author Tim Boudreau
32  */

33 public class NodeHtmlTest extends NbTestCase {
34
35     public NodeHtmlTest(String JavaDoc name) {
36         super(name);
37     }
38
39     public static void main(String JavaDoc[] args) {
40         TestRunner.run(new NbTestSuite(FilterNodeTest.class));
41     }
42
43     public void testDefaultHtmlDisplayNameIsNull() {
44         AbstractNode a = new AbstractNode (Children.LEAF);
45         a.setDisplayName("Finch");
46         assertEquals("AbstractNode.getDisplayName is broken", "Finch",
47             a.getDisplayName());
48         
49         assertNull("Unless overridden, getHtmlDisplayName should return null, " +
50             "not " + a.getHtmlDisplayName(), a.getHtmlDisplayName());
51         
52         FilterNode fn = new FilterNode (a);
53         assertNull ("Filternode should have no default html display name unless" +
54             " its original overrides getHtmlDisplayName", fn.getHtmlDisplayName());
55     }
56     
57     public void testFilteredHtmlNameIsPropagated() {
58         Node n = new HtmlNode();
59         n.setDisplayName ("Whipporwill");
60         FilterNode fn = new FilterNode (n);
61         
62         assertNotNull("This test is broken", n.getHtmlDisplayName());
63         
64         assertNotNull("If a filter node's original supplies an html display " +
65             "name, the filter node's html display name should be non-null",
66             fn.getHtmlDisplayName());
67         
68         assertEquals("FilterNode should propagate the html name of the original",
69             fn.getHtmlDisplayName(), n.getHtmlDisplayName());
70     }
71     
72     public void testFilteredHtmlNameNotPropagatedIfGetDisplayNameOverridden() {
73         Node n = new HtmlNode();
74         n.setDisplayName ("Lark");
75         FilterNode fn = new HtmlDisplayNameNode (n);
76
77         assertNotNull("This test is broken", n.getHtmlDisplayName());
78         
79         assertNotNull("This test is broken", n.getHtmlDisplayName());
80         
81         assertNull ("A filternode whose getDisplayName() method is overridden" +
82             " should return null from getHtmlDisplayName() even though its " +
83             " original returns non-null - got " + fn.getHtmlDisplayName(),
84             fn.getHtmlDisplayName());
85     }
86     
87     
88     private static final String JavaDoc HTML_STRING = "<b>this is <i>html</i></b>";
89     private static class HtmlNode extends AbstractNode {
90         public HtmlNode() {
91             super (Children.LEAF);
92         }
93         
94         public String JavaDoc getHtmlDisplayName() {
95             return HTML_STRING;
96         }
97     }
98     
99     private static class HtmlDisplayNameNode extends FilterNode {
100         public HtmlDisplayNameNode (Node orig) {
101             super (orig);
102         }
103         public String JavaDoc getDisplayName() {
104             return "Not the same name!";
105         }
106     }
107 }
108
109
Popular Tags