1 19 20 package org.openide.explorer.propertysheet; 21 22 import junit.framework.TestCase; 23 import org.openide.nodes.Node; 24 25 28 public class PropUtilsTest extends TestCase { 29 30 public PropUtilsTest(String testName) { 31 super(testName); 32 } 33 34 public void testCreateHtmlTooltip() { 35 System.out.println("testCreateHtmlTooltip"); 36 String 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 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 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 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 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 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 134 private static class DefaultTestProperty extends Node.Property { 135 136 public DefaultTestProperty() { super(Object .class); } 137 public void setValue(Object val) {} 138 public Object getValue() { return null; } 139 public boolean canWrite() { return false; } 140 public boolean canRead() { return false; } 141 } 142 } 143 | Popular Tags |