1 19 20 package org.openide.explorer.propertysheet; 21 22 import java.awt.IllegalComponentStateException ; 23 import java.beans.PropertyDescriptor ; 24 import java.lang.reflect.InvocationTargetException ; 25 import java.net.ServerSocket ; 26 import org.netbeans.junit.NbTestCase; 27 28 30 public class DefaultPropertyModelTest extends NbTestCase { 31 32 public DefaultPropertyModelTest(String name) { 33 super(name); 34 } 35 36 public void testLookupOfAPropertyReadOnlyProperty() throws Exception { 37 Object obj = new Object (); 38 DefaultPropertyModel model = new DefaultPropertyModel(obj, "class"); 39 40 41 assertEquals("Calls the get method", model.getValue(), obj.getClass()); 42 } 43 44 public void testLookupOfAPropertyReadWriteProperty() throws Exception { 45 ServerSocket obj = new ServerSocket (0); 46 47 DefaultPropertyModel model = new DefaultPropertyModel(obj, "soTimeout"); 48 49 50 assertEquals("Calls the get method", model.getValue(), new Integer (obj.getSoTimeout())); 51 52 model.setValue(new Integer (100)); 53 54 assertEquals("Value change", 100, obj.getSoTimeout()); 55 assertEquals("Model updated", model.getValue(), new Integer (obj.getSoTimeout())); 56 } 57 58 62 public void testUsageOfExplicitPropertyDescriptor() throws Exception { 63 PropertyDescriptor pd = new PropertyDescriptor ( 64 "myProp", this.getClass(), 65 "getterUsageOfExplicitPropertyDescriptor", 66 "setterUsageOfExplicitPropertyDescriptor" 67 ); 68 69 DefaultPropertyModel model = new DefaultPropertyModel(this, pd); 70 71 assertEquals("Getter returns this", model.getValue(), this); 72 73 String msgToThrow = "msgToThrow"; 74 try { 75 model.setValue(msgToThrow); 76 fail("Setter should throw an exception"); 77 } catch (InvocationTargetException ex) { 78 assertEquals("The right message", msgToThrow, ex.getTargetException().getMessage()); 80 } 81 } 82 83 public Object getterUsageOfExplicitPropertyDescriptor() { 84 return this; 85 } 86 87 public void setterUsageOfExplicitPropertyDescriptor(Object any) { 88 throw new IllegalComponentStateException (any.toString()); 89 } 90 91 } 95 96 | Popular Tags |