1 19 20 package org.openide.nodes; 21 22 import junit.textui.TestRunner; 23 import org.netbeans.junit.NbTestCase; 24 import org.netbeans.junit.NbTestSuite; 25 26 27 28 31 public class PropertiesTest extends NbTestCase { 32 33 public PropertiesTest(String name) { 34 super(name); 35 } 36 37 public static void main(String [] args) { 38 TestRunner.run(new NbTestSuite(PropertiesTest.class)); 39 } 40 41 public void testReflection() throws Exception { 42 43 Node.Property np = null; 44 45 TestBean tb = new TestBean(); 47 np = new PropertySupport.Reflection( tb, int.class, "number" ); 48 assertEquals( "Value", np.getValue(), new Integer ( 1 ) ); 49 50 NoSuchMethodException thrownException = null; 52 try { 53 np = new PropertySupport.Reflection( tb, String .class, "setterOnlyString" ); 54 } 55 catch ( NoSuchMethodException e ){ 56 thrownException = e; 57 } 58 assertNotNull( "Exception should be thrown", thrownException ); 59 60 thrownException = null; 62 try { 63 np = new PropertySupport.Reflection( tb, boolean.class, "setterOnlyBoolean" ); 64 } 65 catch ( NoSuchMethodException e ){ 66 thrownException = e; 67 } 68 assertNotNull( "Exception should be thrown", thrownException ); 69 70 thrownException = null; 72 try { 73 np = new PropertySupport.Reflection( tb, long.class, "isSetLong" ); 74 } 75 catch ( NoSuchMethodException e ){ 76 thrownException = e; 77 } 78 assertNotNull( "Exception should be thrown", thrownException ); 79 80 81 np = new PropertySupport.Reflection( tb, boolean.class, "getSetBoolean" ); 83 assertEquals( "Value", np.getValue(), Boolean.TRUE ); 84 85 np = new PropertySupport.Reflection( tb, boolean.class, "isSetBoolean" ); 87 assertEquals( "Value", np.getValue(), Boolean.TRUE ); 88 89 } 90 91 public static class TestBean { 92 93 public int getNumber() { 94 return 1; 95 } 96 97 public void setNumber( int number ) { 98 } 99 100 public void setSetterOnlyString( String text ) { 101 } 102 103 public void setSetterOnlyBoolean( boolean value ) { 104 } 105 106 public long isIsSetLong() { 107 return 10L; 108 } 109 110 public void setIsSetLong( long value ) { 111 } 112 113 public boolean getGetSetBoolean() { 114 return true; 115 } 116 117 public void setGetSetBoolean( boolean value ) { 118 } 119 120 121 public boolean isIsSetBoolean() { 122 return true; 123 } 124 125 public void setIsSetBoolean( boolean value ) { 126 } 127 } 128 129 130 } 131 | Popular Tags |