KickJava   Java API By Example, From Geeks To Geeks.

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


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.NestedBeanProperty;
15 import com.inversoft.beans.PropertyListenerAdapter;
16 import com.inversoft.beans.SynchronizedNestedBeanProperty;
17
18
19 /**
20  * <p>
21  * This class tests the synchronized nested bean property
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 SynchronizedNestedBeanPropertyTest extends NestedBeanPropertyTest {
29
30     /**
31      * Constructs a new <code>SynchronizedNestedBeanPropertyTest</code>.
32      */

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

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     /**
110      * Creates the NestedBeanProperty to test. This can be overridden in sub-classes
111      * to test other types of NestedBeanProperties.
112      */

113     protected NestedBeanProperty create(String JavaDoc property, Class JavaDoc bean)
114     throws BeanException {
115         return new SynchronizedNestedBeanProperty(property, bean);
116     }
117
118     /**
119      * Creates the NestedBeanProperty to test. This can be overridden in sub-classes
120      * to test other types of NestedBeanProperties.
121      */

122     protected NestedBeanProperty create(String JavaDoc property, Class JavaDoc bean, boolean strict)
123     throws BeanException {
124         return new SynchronizedNestedBeanProperty(property, bean, strict);
125     }
126
127     /**
128      * Creates the NestedBeanProperty to test. This can be overridden in sub-classes
129      * to test other types of NestedBeanProperties.
130      */

131     protected NestedBeanProperty create(String JavaDoc property, String JavaDoc bean)
132     throws BeanException {
133         return new SynchronizedNestedBeanProperty(property, bean);
134     }
135 }
Popular Tags