1 7 package com.inversoft.beans.test; 8 9 10 import java.util.Iterator ; 11 12 import com.inversoft.beans.BeanException; 13 import com.inversoft.beans.BeanProperty; 14 import com.inversoft.beans.ConversionListenerAdapter; 15 import com.inversoft.beans.PropertyListenerAdapter; 16 import com.inversoft.beans.SynchronizedBeanProperty; 17 18 19 28 public class SynchronizedBeanPropertyTest extends BeanPropertyTest { 29 30 33 public SynchronizedBeanPropertyTest(String name) { 34 super(name); 35 } 36 37 38 41 public void testListeners() { 42 try { 43 SynchronizedBeanProperty bp = 44 new SynchronizedBeanProperty("string1", Bean1.class); 45 ConversionListenerAdapter cl1 = new ConversionListenerAdapter(){}; 46 ConversionListenerAdapter cl2 = new ConversionListenerAdapter(){}; 47 PropertyListenerAdapter pl1 = new PropertyListenerAdapter(){}; 48 PropertyListenerAdapter pl2 = new PropertyListenerAdapter(){}; 49 bp.addConversionListener(cl1); 50 bp.addConversionListener(cl2); 51 bp.addPropertyListener(pl1); 52 bp.addPropertyListener(pl2); 53 54 assertTrue(bp.hasConversionListeners()); 55 assertTrue(bp.hasPropertyListeners()); 56 57 Iterator iter = bp.getConversionListeners(); 58 assertTrue(iter.hasNext()); 59 assertEquals(cl1, iter.next()); 60 assertTrue(iter.hasNext()); 61 assertEquals(cl2, iter.next()); 62 63 bp.removeConversionListener(cl1); 64 iter = bp.getConversionListeners(); 65 assertTrue(bp.hasConversionListeners()); 66 assertTrue(iter.hasNext()); 67 assertEquals(cl2, iter.next()); 68 assertFalse(iter.hasNext()); 69 bp.removeConversionListener(cl2); 70 iter = bp.getConversionListeners(); 71 assertFalse(iter.hasNext()); 72 assertFalse(bp.hasConversionListeners()); 73 74 iter = bp.getPropertyListeners(); 75 assertTrue(iter.hasNext()); 76 assertEquals(pl1, iter.next()); 77 assertTrue(iter.hasNext()); 78 assertEquals(pl2, iter.next()); 79 80 bp.removePropertyListener(pl1); 81 iter = bp.getPropertyListeners(); 82 assertTrue(bp.hasPropertyListeners()); 83 assertTrue(iter.hasNext()); 84 assertEquals(pl2, iter.next()); 85 assertFalse(iter.hasNext()); 86 bp.removePropertyListener(pl2); 87 iter = bp.getPropertyListeners(); 88 assertFalse(iter.hasNext()); 89 assertFalse(bp.hasPropertyListeners()); 90 } catch (BeanException be) { 91 fail(be.toString()); 92 } 93 } 94 95 98 public void testSubClass() { 99 try { 100 SynchronizedBeanProperty bp = new SynchronizedBeanProperty() {}; 101 assertNull(bp.getBeanClass()); 102 assertNull(bp.getFullName()); 103 assertNull(bp.getPropertyName()); 104 assertNull(bp.getPropertyType()); 105 assertNull(bp.getReadMethod()); 106 assertNull(bp.getWriteMethod()); 107 } catch (BeanException e) { 108 fail(e.toString()); 109 } 110 } 111 112 116 protected BeanProperty create(String property, Class bean) 117 throws BeanException { 118 return new SynchronizedBeanProperty(property, bean); 119 } 120 121 125 protected BeanProperty create(String property, String bean) 126 throws BeanException { 127 return new SynchronizedBeanProperty(property, bean); 128 } 129 } | Popular Tags |