KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > beans > test > SynchronizedIndexedBeanPropertyTest


1 /*
2  * Copyright (c) 2003-2004, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.beans.test;
8
9
10 import java.util.Iterator JavaDoc;
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 /**
20  * <p>
21  * This class tests the synchronized indexed bean property class
22  * class with the same tests as the un-synchronized version,
23  * and a few additional tests.
24  * </p>
25  *
26  * @author Brian Pontarelli
27  */

28 public class SynchronizedIndexedBeanPropertyTest extends IndexedBeanPropertyTest {
29
30     /**
31      * Constructs a new <code>SynchronizedBeanPropertyTest</code>.
32      */

33     public SynchronizedIndexedBeanPropertyTest(String JavaDoc name) {
34         super(name);
35     }
36
37
38     /**
39      * Tests that the listener methods still work.
40      */

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 JavaDoc 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     /**
96      * Tests using the default constructor works.
97      */

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     /**
113      * Creates the IndexedBeanProperty to test. This can be overridden in sub-classes
114      * to test other types of NestedBeanProperties.
115      */

116     protected IndexedBeanProperty create(String JavaDoc property, Class JavaDoc bean)
117     throws BeanException {
118         return new SynchronizedIndexedBeanProperty(property, bean);
119     }
120
121     /**
122      * Creates the BeanProperty to test. This can be overridden in sub-classes
123      * to test other types of NestedBeanProperties.
124      */

125     protected IndexedBeanProperty create(String JavaDoc property, String JavaDoc bean)
126     throws BeanException {
127         return new SynchronizedIndexedBeanProperty(property, bean);
128     }
129 }
Popular Tags