Revision 24845
branches/v2_0_0_prep/libraries/libTools/src-test/org/gvsig/tools/observable/BaseObservableTest.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Gobernment (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2008 {DiSiD Technologies} {{Task}} |
|
26 |
*/ |
|
27 |
package org.gvsig.tools.observable; |
|
28 |
|
|
29 |
import java.lang.ref.WeakReference; |
|
30 |
|
|
31 |
import junit.framework.TestCase; |
|
32 |
|
|
33 |
import org.easymock.MockControl; |
|
34 |
import org.gvsig.tools.observer.Observer; |
|
35 |
import org.gvsig.tools.observer.impl.BaseWeakReferencingObservable; |
|
36 |
|
|
37 |
/** |
|
38 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a> |
|
39 |
*/ |
|
40 |
public class BaseObservableTest extends TestCase { |
|
41 |
|
|
42 |
private BaseWeakReferencingObservable observable; |
|
43 |
private MockControl obsControl; |
|
44 |
private Observer observer; |
|
45 |
|
|
46 |
protected void setUp() throws Exception { |
|
47 |
super.setUp(); |
|
48 |
observable = new BaseWeakReferencingObservable(); |
|
49 |
obsControl = MockControl.createStrictControl(Observer.class); |
|
50 |
observer = (Observer) obsControl.getMock(); |
|
51 |
} |
|
52 |
|
|
53 |
protected void tearDown() throws Exception { |
|
54 |
super.tearDown(); |
|
55 |
} |
|
56 |
|
|
57 |
/** |
|
58 |
* Test method for |
|
59 |
* {@link org.gvsig.tools.observer.impl.BaseWeakReferencingObservable#enableNotifications()} |
|
60 |
* . |
|
61 |
*/ |
|
62 |
public void testEnableNotifications() { |
|
63 |
observer.update(observable, null); |
|
64 |
obsControl.replay(); |
|
65 |
|
|
66 |
observable.addObserver(observer); |
|
67 |
observable.enableNotifications(); |
|
68 |
observable.notifyObservers(); |
|
69 |
|
|
70 |
obsControl.verify(); |
|
71 |
} |
|
72 |
|
|
73 |
/** |
|
74 |
* Test method for {@link org.gvsig.tools.observer.impl.BaseWeakReferencingObservable#dis}. |
|
75 |
*/ |
|
76 |
public void testDisableNotifications() { |
|
77 |
// The observer must not be notified |
|
78 |
obsControl.replay(); |
|
79 |
|
|
80 |
observable.addObserver(observer); |
|
81 |
observable.disableNotifications(); |
|
82 |
observable.notifyObservers(); |
|
83 |
|
|
84 |
obsControl.verify(); |
|
85 |
} |
|
86 |
|
|
87 |
/** |
|
88 |
* Test method for |
|
89 |
* {@link org.gvsig.tools.observer.impl.BaseWeakReferencingObservable#isEnabledNotifications()} |
|
90 |
* . |
|
91 |
*/ |
|
92 |
public void testIsEnabledNotifications() { |
|
93 |
assertTrue(observable.isEnabledNotifications()); |
|
94 |
|
|
95 |
observable.disableNotifications(); |
|
96 |
assertFalse(observable.isEnabledNotifications()); |
|
97 |
|
|
98 |
observable.enableNotifications(); |
|
99 |
assertTrue(observable.isEnabledNotifications()); |
|
100 |
} |
|
101 |
|
|
102 |
/** |
|
103 |
* Test method for |
|
104 |
* {@link org.gvsig.tools.observer.impl.BaseWeakReferencingObservable#addObserver(org.gvsig.tools.observer.Observer)} |
|
105 |
* . |
|
106 |
*/ |
|
107 |
public void testAddObserverObserver() { |
|
108 |
assertEquals(0, observable.countObservers()); |
|
109 |
observable.addObserver(observer); |
|
110 |
assertEquals(1, observable.countObservers()); |
|
111 |
observable.addObserver(observer); |
|
112 |
assertEquals(1, observable.countObservers()); |
|
113 |
} |
|
114 |
|
|
115 |
/** |
|
116 |
* Test method for |
|
117 |
* {@link org.gvsig.tools.observer.impl.BaseWeakReferencingObservable#addObserver(java.lang.ref.Reference)} |
|
118 |
* . |
|
119 |
*/ |
|
120 |
public void testAddObserverReference() { |
|
121 |
assertEquals(0, observable.countObservers()); |
|
122 |
observable.addObserver(new WeakReference(observer)); |
|
123 |
assertEquals(1, observable.countObservers()); |
|
124 |
observable.addObserver(new WeakReference(observer)); |
|
125 |
assertEquals(1, observable.countObservers()); |
|
126 |
} |
|
127 |
|
|
128 |
/** |
|
129 |
* Test method for |
|
130 |
* {@link org.gvsig.tools.observer.impl.BaseObservable#addObservers(org.gvsig.tools.observer.impl.BaseObservable)} |
|
131 |
* . |
|
132 |
*/ |
|
133 |
// public void testAddObservers() { |
|
134 |
// fail("Not yet implemented"); |
|
135 |
// } |
|
136 |
/** |
|
137 |
* Test method for |
|
138 |
* {@link org.gvsig.tools.observer.impl.BaseWeakReferencingObservable#deleteObserver(org.gvsig.tools.observer.Observer)} |
|
139 |
* . |
|
140 |
*/ |
|
141 |
public void testDeleteObserverObserver() { |
|
142 |
observable.addObserver(observer); |
|
143 |
assertEquals(1, observable.countObservers()); |
|
144 |
observable.deleteObserver(observer); |
|
145 |
assertEquals(0, observable.countObservers()); |
|
146 |
} |
|
147 |
|
|
148 |
/** |
|
149 |
* Test method for |
|
150 |
* {@link org.gvsig.tools.observer.impl.BaseWeakReferencingObservable#deleteObserver(java.lang.ref.Reference)} |
|
151 |
* . |
|
152 |
*/ |
|
153 |
public void testDeleteObserverReference() { |
|
154 |
observable.addObserver(new WeakReference(observer)); |
|
155 |
assertEquals(1, observable.countObservers()); |
|
156 |
observable.deleteObserver(new WeakReference(observer)); |
|
157 |
assertEquals(0, observable.countObservers()); |
|
158 |
} |
|
159 |
|
|
160 |
/** |
|
161 |
* Test method for |
|
162 |
* {@link org.gvsig.tools.observer.impl.BaseObservable#notifyObservers()}. |
|
163 |
*/ |
|
164 |
// public void testNotifyObservers() { |
|
165 |
// fail("Not yet implemented"); |
|
166 |
// } |
|
167 |
/** |
|
168 |
* Test method for |
|
169 |
* {@link org.gvsig.tools.observer.impl.BaseObservable#notifyObservers(org.gvsig.tools.observer.Observable, java.lang.Object)} |
|
170 |
* . |
|
171 |
*/ |
|
172 |
// public void testNotifyObserversObservableObject() { |
|
173 |
// fail("Not yet implemented"); |
|
174 |
// } |
|
175 |
/** |
|
176 |
* Test method for |
|
177 |
* {@link org.gvsig.tools.observer.impl.BaseObservable#deleteObservers()}. |
|
178 |
*/ |
|
179 |
// public void testDeleteObservers() { |
|
180 |
// fail("Not yet implemented"); |
|
181 |
// } |
|
182 |
/** |
|
183 |
* Test method for |
|
184 |
* {@link org.gvsig.tools.observer.impl.BaseObservable#hasChanged()}. |
|
185 |
*/ |
|
186 |
// public void testHasChanged() { |
|
187 |
// fail("Not yet implemented"); |
|
188 |
// } |
|
189 |
/** |
|
190 |
* Test method for |
|
191 |
* {@link org.gvsig.tools.observer.impl.BaseObservable#countObservers()}. |
|
192 |
*/ |
|
193 |
// public void testCountObservers() { |
|
194 |
// fail("Not yet implemented"); |
|
195 |
// } |
|
196 |
/** |
|
197 |
* Test method for |
|
198 |
* {@link org.gvsig.tools.observer.impl.BaseObservable#inComplex()}. |
|
199 |
*/ |
|
200 |
// public void testInComplex() { |
|
201 |
// fail("Not yet implemented"); |
|
202 |
// } |
|
203 |
/** |
|
204 |
* Test method for |
|
205 |
* {@link org.gvsig.tools.observer.impl.BaseObservable#beginComplexNotification(org.gvsig.tools.observer.ComplexNotification)} |
|
206 |
* . |
|
207 |
*/ |
|
208 |
// public void testBeginComplexNotification() { |
|
209 |
// fail("Not yet implemented"); |
|
210 |
// } |
|
211 |
/** |
|
212 |
* Test method for |
|
213 |
* {@link org.gvsig.tools.observer.impl.BaseObservable#endComplexNotification(org.gvsig.tools.observer.Observable)} |
|
214 |
* . |
|
215 |
*/ |
|
216 |
// public void testEndComplexNotification() { |
|
217 |
// fail("Not yet implemented"); |
|
218 |
// } |
|
219 |
} |
Also available in: Unified diff