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.ConversionListenerAdapter; 14 import com.inversoft.beans.IndexedBeanProperty; 15 import com.inversoft.beans.PropertyListenerAdapter; 16 import com.inversoft.beans.SynchronizedIndexedBeanProperty; 17 18 19 28 public class SynchronizedIndexedBeanPropertyTest extends IndexedBeanPropertyTest { 29 30 33 public SynchronizedIndexedBeanPropertyTest(String name) { 34 super(name); 35 } 36 37 38 41 public void testListeners() { 42 try { 43 SynchronizedIndexedBeanProperty ibp = 44 new SynchronizedIndexedBeanProperty("stringIndexed", Bean1.class); 45 ConversionListenerAdapter cl1 = new ConversionListenerAdapter(){}; 46 ConversionListenerAdapter cl2 = new ConversionListenerAdapter(){}; 47 PropertyListenerAdapter pl1 = new PropertyListenerAdapter(){}; 48 PropertyListenerAdapter pl2 = new PropertyListenerAdapter(){}; 49 ibp.addConversionListener(cl1); 50 ibp.addConversionListener(cl2); 51 ibp.addPropertyListener(pl1); 52 ibp.addPropertyListener(pl2); 53 54 assertTrue(ibp.hasConversionListeners()); 55 assertTrue(ibp.hasPropertyListeners()); 56 57 Iterator iter = ibp.getConversionListeners(); 58 assertTrue(iter.hasNext()); 59 assertEquals(cl1, iter.next()); 60 assertTrue(iter.hasNext()); 61 assertEquals(cl2, iter.next()); 62 63 ibp.removeConversionListener(cl1); 64 iter = ibp.getConversionListeners(); 65 assertTrue(ibp.hasConversionListeners()); 66 assertTrue(iter.hasNext()); 67 assertEquals(cl2, iter.next()); 68 assertFalse(iter.hasNext()); 69 ibp.removeConversionListener(cl2); 70 iter = ibp.getConversionListeners(); 71 assertFalse(iter.hasNext()); 72 assertFalse(ibp.hasConversionListeners()); 73 74 iter = ibp.getPropertyListeners(); 75 assertTrue(iter.hasNext()); 76 assertEquals(pl1, iter.next()); 77 assertTrue(iter.hasNext()); 78 assertEquals(pl2, iter.next()); 79 80 ibp.removePropertyListener(pl1); 81 iter = ibp.getPropertyListeners(); 82 assertTrue(ibp.hasPropertyListeners()); 83 assertTrue(iter.hasNext()); 84 assertEquals(pl2, iter.next()); 85 assertFalse(iter.hasNext()); 86 ibp.removePropertyListener(pl2); 87 iter = ibp.getPropertyListeners(); 88 assertFalse(iter.hasNext()); 89 assertFalse(ibp.hasPropertyListeners()); 90 } catch (BeanException be) { 91 fail(be.toString()); 92 } 93 } 94 95 98 public void testSubClass() { 99 try { 100 SynchronizedIndexedBeanProperty bp = new SynchronizedIndexedBeanProperty() {}; 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 IndexedBeanProperty create(String property, Class bean) 117 throws BeanException { 118 return new SynchronizedIndexedBeanProperty(property, bean); 119 } 120 121 125 protected IndexedBeanProperty create(String property, String bean) 126 throws BeanException { 127 return new SynchronizedIndexedBeanProperty(property, bean); 128 } 129 } | Popular Tags |