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.NestedBeanProperty; 15 import com.inversoft.beans.PropertyListenerAdapter; 16 import com.inversoft.beans.SynchronizedNestedBeanProperty; 17 18 19 28 public class SynchronizedNestedBeanPropertyTest extends NestedBeanPropertyTest { 29 30 33 public SynchronizedNestedBeanPropertyTest(String name) { 34 super(name); 35 } 36 37 38 41 public void testListeners() { 42 try { 43 SynchronizedNestedBeanProperty nbp = 44 new SynchronizedNestedBeanProperty("property1.property2", Bean1.class); 45 ConversionListenerAdapter cl1 = new ConversionListenerAdapter(){}; 46 ConversionListenerAdapter cl2 = new ConversionListenerAdapter(){}; 47 PropertyListenerAdapter pl1 = new PropertyListenerAdapter(){}; 48 PropertyListenerAdapter pl2 = new PropertyListenerAdapter(){}; 49 nbp.addConversionListener(cl1); 50 nbp.addConversionListener(cl2); 51 nbp.addPropertyListener(pl1); 52 nbp.addPropertyListener(pl2); 53 54 assertTrue(nbp.hasConversionListeners()); 55 assertTrue(nbp.hasPropertyListeners()); 56 57 Iterator iter = nbp.getConversionListeners(); 58 assertTrue(iter.hasNext()); 59 assertEquals(cl1, iter.next()); 60 assertTrue(iter.hasNext()); 61 assertEquals(cl2, iter.next()); 62 63 nbp.removeConversionListener(cl1); 64 iter = nbp.getConversionListeners(); 65 assertTrue(nbp.hasConversionListeners()); 66 assertTrue(iter.hasNext()); 67 assertEquals(cl2, iter.next()); 68 assertFalse(iter.hasNext()); 69 nbp.removeConversionListener(cl2); 70 iter = nbp.getConversionListeners(); 71 assertFalse(iter.hasNext()); 72 assertFalse(nbp.hasConversionListeners()); 73 74 iter = nbp.getPropertyListeners(); 75 assertTrue(iter.hasNext()); 76 assertEquals(pl1, iter.next()); 77 assertTrue(iter.hasNext()); 78 assertEquals(pl2, iter.next()); 79 80 nbp.removePropertyListener(pl1); 81 iter = nbp.getPropertyListeners(); 82 assertTrue(nbp.hasPropertyListeners()); 83 assertTrue(iter.hasNext()); 84 assertEquals(pl2, iter.next()); 85 assertFalse(iter.hasNext()); 86 nbp.removePropertyListener(pl2); 87 iter = nbp.getPropertyListeners(); 88 assertFalse(iter.hasNext()); 89 assertFalse(nbp.hasPropertyListeners()); 90 } catch (BeanException be) { 91 fail(be.toString()); 92 } 93 } 94 95 98 public void testSubClass() { 99 try { 100 SynchronizedNestedBeanProperty bp = new SynchronizedNestedBeanProperty() {}; 101 assertNull(bp.getBeanClass()); 102 assertNull(bp.getFullName()); 103 assertNull(bp.getPropertyName()); 104 } catch (BeanException e) { 105 fail(e.toString()); 106 } 107 } 108 109 113 protected NestedBeanProperty create(String property, Class bean) 114 throws BeanException { 115 return new SynchronizedNestedBeanProperty(property, bean); 116 } 117 118 122 protected NestedBeanProperty create(String property, Class bean, boolean strict) 123 throws BeanException { 124 return new SynchronizedNestedBeanProperty(property, bean, strict); 125 } 126 127 131 protected NestedBeanProperty create(String property, String bean) 132 throws BeanException { 133 return new SynchronizedNestedBeanProperty(property, bean); 134 } 135 } | Popular Tags |