1 19 20 package org.openide.nodes; 21 22 import java.util.Date ; 23 import java.util.logging.Level ; 24 import org.netbeans.junit.Log; 25 import org.netbeans.junit.NbTestCase; 26 import org.openide.ErrorManager; 27 import org.openide.util.Lookup; 28 import org.openide.util.lookup.AbstractLookup; 29 import org.openide.util.lookup.InstanceContent; 30 31 38 public class NodeProperty51907Test extends NbTestCase { 39 40 public NodeProperty51907Test(String name) { 41 super(name); 42 } 43 44 48 public void testThatWarningIsLoggedForOldModulesProperty() { 49 CharSequence log = Log.enable("", Level.WARNING); 50 Node.Property property = new OldModulePropertyWithSDVReturningTrue(); 51 property.isDefaultValue(); 53 String className = property.getClass().getName(); 54 assertTrue("The WARNING message should contain name of the property" + 55 "class - " + className + " was log:\n" + log, log.toString().indexOf(className) >= 0); 56 57 58 int len = log.length(); 59 60 property.isDefaultValue(); 62 assertEquals("No other message logged", len, log.length()); 63 64 Node.Property otherInstance = new OldModulePropertyWithSDVReturningTrue(); 65 otherInstance.isDefaultValue(); 66 assertEquals("No other message logged2", len, log.length()); 67 } 68 69 public void testThatWarningIsNotLoggedForPropertyWithBothMethodsOverrided() { 70 CharSequence log = Log.enable("", Level.WARNING); 71 72 Node.Property property = new BothMethodsOverridedProperty(); 73 property.isDefaultValue(); 75 assertEquals("There shouldn't be any WARNING message logged by the ErrorManager", 0, log.length()); 76 } 77 78 public void testThatWarningIsNotLoggedForPropertyWithNoneMethodOverrided() { 79 CharSequence log = Log.enable("", Level.WARNING); 80 81 Node.Property property = new DefaultTestProperty(); 82 property.isDefaultValue(); 84 assertEquals("There shouldn't be any WARNING message logged by the ErrorManager", 0, log.length()); 85 } 86 87 88 93 private static final class OldModulePropertyWithSDVReturningTrue 94 extends DefaultTestProperty { 95 public boolean supportsDefaultValue() { 96 return true; 97 } 98 } 99 100 103 private static final class BothMethodsOverridedProperty 104 extends DefaultTestProperty { 105 public boolean supportsDefaultValue() { 106 return true; 107 } 108 public boolean isDefaultValue() { 109 return false; 110 } 111 } 112 113 117 private static class DefaultTestProperty extends Node.Property { 118 119 public DefaultTestProperty() { super(Object .class); } 120 public void setValue(Object val) {} 121 public Object getValue() { return null; } 122 public boolean canWrite() { return false; } 123 public boolean canRead() { return false; } 124 } 125 126 } 127 | Popular Tags |