1 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 33 public class NodeHtmlTest extends NbTestCase { 34 35 public NodeHtmlTest(String name) { 36 super(name); 37 } 38 39 public static void main(String [] 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 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 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 getDisplayName() { 104 return "Not the same name!"; 105 } 106 } 107 } 108 109 | Popular Tags |