Lines 7-18
Link Here
|
7 |
* http://www.sun.com/ |
7 |
* http://www.sun.com/ |
8 |
* |
8 |
* |
9 |
* The Original Code is NetBeans. The Initial Developer of the Original |
9 |
* The Original Code is NetBeans. The Initial Developer of the Original |
10 |
* Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun |
10 |
* Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun |
11 |
* Microsystems, Inc. All Rights Reserved. |
11 |
* Microsystems, Inc. All Rights Reserved. |
12 |
*/ |
12 |
*/ |
13 |
package org.openide; |
13 |
package org.openide; |
14 |
|
14 |
|
15 |
|
15 |
|
|
|
16 |
import java.lang.reflect.InvocationTargetException; |
16 |
import org.netbeans.junit.*; |
17 |
import org.netbeans.junit.*; |
17 |
import junit.framework.Test; |
18 |
import junit.framework.Test; |
18 |
import junit.framework.TestSuite; |
19 |
import junit.framework.TestSuite; |
Lines 30-35
Link Here
|
30 |
import org.netbeans.junit.NbTestCase; |
31 |
import org.netbeans.junit.NbTestCase; |
31 |
import org.openide.util.*; |
32 |
import org.openide.util.*; |
32 |
import org.openide.util.HelpCtx; |
33 |
import org.openide.util.HelpCtx; |
|
|
34 |
import org.openide.util.RequestProcessor.Task; |
33 |
|
35 |
|
34 |
/** Testing functional implementation calling the methods to interface <code>WizardDescriptor.InstantiatingIterator</code> |
36 |
/** Testing functional implementation calling the methods to interface <code>WizardDescriptor.InstantiatingIterator</code> |
35 |
* from WizardDescriptor. |
37 |
* from WizardDescriptor. |
Lines 46-70
Link Here
|
46 |
System.exit (0); |
48 |
System.exit (0); |
47 |
} |
49 |
} |
48 |
|
50 |
|
49 |
private WizardDescriptor wd; |
51 |
protected WizardDescriptor wd; |
50 |
private String exceptedValue; |
52 |
protected String exceptedValue; |
51 |
private Iterator iterator; |
53 |
private Iterator iterator; |
52 |
private int attachedInIterator = 0; |
54 |
protected int attachedInIterator = 0; |
53 |
private int attachedInPanel = 0; |
55 |
protected int attachedInPanel = 0; |
54 |
private boolean checkOrder = false; |
56 |
protected boolean checkOrder = false; |
55 |
private boolean shouldThrowException = false; |
57 |
protected boolean shouldThrowException = false; |
56 |
private boolean checkAWTQueue = false; |
58 |
protected Set/*<ChangeListener>*/ changeListenersInIterator = new HashSet (); |
57 |
private Set/*<ChangeListener>*/ changeListenersInIterator = new HashSet (); |
59 |
protected Set/*<ChangeListener>*/ changeListenersInPanel = new HashSet (); |
58 |
private Set/*<ChangeListener>*/ changeListenersInPanel = new HashSet (); |
60 |
protected boolean checkIfInAWT; |
59 |
|
61 |
|
60 |
protected final void setUp () { |
62 |
protected void setUp () { |
61 |
iterator = new Iterator (); |
63 |
iterator = new Iterator (); |
62 |
wd = new WizardDescriptor (iterator); |
64 |
wd = new WizardDescriptor (iterator); |
63 |
wd.addPropertyChangeListener(new Listener ()); |
65 |
wd.addPropertyChangeListener(new Listener ()); |
64 |
java.awt.Dialog d = DialogDisplayer.getDefault ().createDialog (wd); |
66 |
java.awt.Dialog d = DialogDisplayer.getDefault ().createDialog (wd); |
65 |
checkOrder = false; |
67 |
checkOrder = false; |
66 |
shouldThrowException = false; |
68 |
shouldThrowException = false; |
67 |
checkAWTQueue = false; |
|
|
68 |
//d.show(); |
69 |
//d.show(); |
69 |
} |
70 |
} |
70 |
|
71 |
|
Lines 79-85
Link Here
|
79 |
assertEquals ("Still only one listener is attached after Next.", 1, changeListenersInIterator.size ()); |
80 |
assertEquals ("Still only one listener is attached after Next.", 1, changeListenersInIterator.size ()); |
80 |
wd.doPreviousClick (); |
81 |
wd.doPreviousClick (); |
81 |
assertEquals ("Still only one listener is attached after Previous.", 1, changeListenersInIterator.size ()); |
82 |
assertEquals ("Still only one listener is attached after Previous.", 1, changeListenersInIterator.size ()); |
82 |
wd.doFinishClick (); |
83 |
finishWizard (wd); |
83 |
assertEquals ("No one listener is attached after Finish.", 0, changeListenersInIterator.size ()); |
84 |
assertEquals ("No one listener is attached after Finish.", 0, changeListenersInIterator.size ()); |
84 |
assertEquals ("No one listener is attached in WD.Panel after Finish.", 0, changeListenersInPanel.size ()); |
85 |
assertEquals ("No one listener is attached in WD.Panel after Finish.", 0, changeListenersInPanel.size ()); |
85 |
} |
86 |
} |
Lines 92-147
Link Here
|
92 |
} |
93 |
} |
93 |
|
94 |
|
94 |
public void testInitializeIterator () throws Exception { |
95 |
public void testInitializeIterator () throws Exception { |
95 |
assertTrue ("InstantiatingIterator was initialized.", iterator.initialized.booleanValue ()); |
96 |
assertTrue ("InstantiatingIterator was initialized.", getInitialized ().booleanValue ()); |
96 |
assertNull ("InstantiatingIterator wasn't instantiated.", iterator.result); |
97 |
assertNull ("InstantiatingIterator wasn't instantiated.", getResult ()); |
97 |
} |
98 |
} |
98 |
|
99 |
|
99 |
public void testUninitializeIterator () throws Exception { |
100 |
public void testUninitializeIterator () throws Exception { |
100 |
assertTrue ("InstantiatingIterator was initialized at start.", iterator.initialized.booleanValue ()); |
101 |
assertTrue ("InstantiatingIterator was initialized at start.", getInitialized ().booleanValue ()); |
101 |
wd.doCancelClick (); |
102 |
wd.doCancelClick (); |
102 |
assertFalse ("InstantiatingIterator was uninitialized after cancel.", iterator.initialized.booleanValue ()); |
103 |
assertFalse ("InstantiatingIterator was uninitialized after cancel.", getInitialized ().booleanValue ()); |
103 |
assertNull ("InstantiatingIterator wasn't instantiated.", iterator.result); |
104 |
assertNull ("InstantiatingIterator wasn't instantiated.", getResult ()); |
104 |
} |
105 |
} |
105 |
|
106 |
|
106 |
public void testFinishAndUninitializeIterator () throws Exception { |
107 |
public void testFinishAndUninitializeIterator () throws Exception { |
107 |
assertTrue ("InstantiatingIterator was initialized at start.", iterator.initialized.booleanValue ()); |
108 |
assertTrue ("InstantiatingIterator was initialized at start.", getInitialized ().booleanValue ()); |
108 |
wd.doNextClick (); |
109 |
wd.doNextClick (); |
109 |
assertTrue ("InstantiatingIterator wasn't uninitialized after next.", iterator.initialized.booleanValue ()); |
110 |
assertTrue ("InstantiatingIterator wasn't uninitialized after next.", getInitialized ().booleanValue ()); |
110 |
wd.doFinishClick (); |
111 |
finishWizard (wd); |
111 |
assertFalse ("InstantiatingIterator wasn uninitialized after finish.", iterator.initialized.booleanValue ()); |
112 |
assertFalse ("InstantiatingIterator wasn uninitialized after finish.", getInitialized ().booleanValue ()); |
112 |
assertNotNull ("InstantiatingIterator was instantiated.", iterator.result); |
113 |
assertNotNull ("InstantiatingIterator was instantiated.", getResult ()); |
113 |
} |
114 |
} |
114 |
|
115 |
|
115 |
public void testUninitializeIteratorAndCalledCurrent () throws Exception { |
116 |
public void testUninitializeIteratorAndCalledCurrent () throws Exception { |
116 |
assertTrue ("InstantiatingIterator was initialized at start.", iterator.initialized.booleanValue ()); |
117 |
assertTrue ("InstantiatingIterator was initialized at start.", getInitialized ().booleanValue ()); |
117 |
wd.doNextClick (); |
118 |
wd.doNextClick (); |
118 |
assertTrue ("InstantiatingIterator wasn't uninitialized after next.", iterator.initialized.booleanValue ()); |
119 |
assertTrue ("InstantiatingIterator wasn't uninitialized after next.", getInitialized ().booleanValue ()); |
119 |
wd.doFinishClick (); |
120 |
finishWizard (wd); |
120 |
assertFalse ("InstantiatingIterator wasn uninitialized after finish.", iterator.initialized.booleanValue ()); |
121 |
assertFalse ("InstantiatingIterator was uninitialized after finish.", getInitialized ().booleanValue ()); |
121 |
assertNotNull ("InstantiatingIterator was instantiated.", iterator.result); |
122 |
assertNotNull ("InstantiatingIterator was instantiated.", getResult ()); |
122 |
} |
123 |
} |
123 |
|
124 |
|
124 |
public void testOrderStoreSettingAndInstantiate () throws Exception { |
125 |
public void testOrderStoreSettingAndInstantiate () throws Exception { |
125 |
checkOrder = true; |
126 |
checkOrder = true; |
126 |
wd.doNextClick (); |
127 |
wd.doNextClick (); |
127 |
wd.doFinishClick (); |
128 |
finishWizard (wd); |
128 |
assertNotNull ("InstantiatingIterator was instantiated.", iterator.result); |
129 |
assertNotNull ("InstantiatingIterator was instantiated.", getResult ()); |
129 |
} |
130 |
} |
130 |
|
131 |
|
131 |
public void testGetInstantiatedObjects () throws Exception { |
132 |
public void testGetInstantiatedObjects () throws Exception { |
132 |
wd.doNextClick (); |
133 |
wd.doNextClick (); |
133 |
wd.doFinishClick (); |
134 |
finishWizard (wd); |
134 |
assertNotNull ("InstantiatingIterator was instantiated.", iterator.result); |
135 |
assertNotNull ("InstantiatingIterator was instantiated.", getResult ()); |
135 |
Set newObjects = wd.getInstantiatedObjects (); |
136 |
Set newObjects = wd.getInstantiatedObjects (); |
136 |
assertEquals ("WD returns same objects as InstantiatingIterator instantiated.", iterator.result, newObjects); |
137 |
assertEquals ("WD returns same objects as InstantiatingIterator instantiated.", getResult (), newObjects); |
137 |
|
138 |
|
138 |
} |
139 |
} |
139 |
|
140 |
|
140 |
public void testInstantiateOutsideAWTQueue () { |
141 |
public void testInstantiateInAWTQueueOrNot () { |
141 |
checkAWTQueue = true; |
142 |
checkIfInAWT = true; |
142 |
|
143 |
|
143 |
wd.doNextClick (); |
144 |
wd.doNextClick (); |
144 |
wd.doFinishClick (); |
145 |
finishWizard (wd); |
|
|
146 |
try { |
147 |
Set newObjects = wd.getInstantiatedObjects (); |
148 |
} catch (IllegalStateException ise) { |
149 |
fail ("IllegalStateException was caught because WD.instantiate() called outside AWT queue."); |
150 |
} |
151 |
assertNotNull ("InstantiatingIterator was correctly instantiated.", getResult ()); |
145 |
} |
152 |
} |
146 |
|
153 |
|
147 |
public void testFinishOptionWhenInstantiateFails () throws Exception { |
154 |
public void testFinishOptionWhenInstantiateFails () throws Exception { |
Lines 149-160
Link Here
|
149 |
|
156 |
|
150 |
wd.doNextClick (); |
157 |
wd.doNextClick (); |
151 |
Object state = wd.getValue(); |
158 |
Object state = wd.getValue(); |
152 |
wd.doFinishClick (); |
159 |
finishWizard (wd); |
153 |
|
160 |
|
154 |
assertNull ("InstantiatingIterator was not correctly instantiated.", iterator.result); |
161 |
assertNull ("InstantiatingIterator was not correctly instantiated.", getResult ()); |
155 |
// Set newObjects = wd.getInstantiatedObjects (); |
162 |
try { |
156 |
// assertEquals ("WD returns no object.", Collections.EMPTY_SET, newObjects); |
163 |
Set newObjects = wd.getInstantiatedObjects (); |
157 |
assertSame ("The state is same as before instantiate()", state, wd.getValue ()); |
164 |
fail ("No IllegalStateException was caught. Should be thrown when invoked getInstantiatedObjects() on unfinished wizard."); |
|
|
165 |
} catch (IllegalStateException ise) { |
166 |
// correct behavior |
167 |
} |
168 |
assertEquals ("The state is same as before instantiate()", state, wd.getValue ()); |
158 |
} |
169 |
} |
159 |
|
170 |
|
160 |
public class Panel implements WizardDescriptor.FinishablePanel { |
171 |
public class Panel implements WizardDescriptor.FinishablePanel { |
Lines 194-200
Link Here
|
194 |
|
205 |
|
195 |
public void storeSettings(Object settings) { |
206 |
public void storeSettings(Object settings) { |
196 |
if (checkOrder) { |
207 |
if (checkOrder) { |
197 |
assertNull ("WD.P.storeSettings() called before WD.I.instantiate()", iterator.result); |
208 |
assertNull ("WD.P.storeSettings() called before WD.I.instantiate()", getResult ()); |
198 |
// bugfix #45093, remember storeSettings could be called multiple times |
209 |
// bugfix #45093, remember storeSettings could be called multiple times |
199 |
// do check order only when the first time |
210 |
// do check order only when the first time |
200 |
checkOrder = false; |
211 |
checkOrder = false; |
Lines 212-224
Link Here
|
212 |
|
223 |
|
213 |
} |
224 |
} |
214 |
|
225 |
|
|
|
226 |
protected Boolean getInitialized () { |
227 |
return iterator.initialized; |
228 |
} |
229 |
|
230 |
protected Set getResult () { |
231 |
return iterator.result; |
232 |
} |
233 |
|
215 |
public class Iterator implements WizardDescriptor.InstantiatingIterator { |
234 |
public class Iterator implements WizardDescriptor.InstantiatingIterator { |
216 |
int index = 0; |
235 |
int index = 0; |
217 |
WizardDescriptor.Panel panels[] = new WizardDescriptor.Panel[2]; |
236 |
WizardDescriptor.Panel panels[] = new WizardDescriptor.Panel[2]; |
218 |
java.util.Set helpSet; |
237 |
java.util.Set helpSet; |
219 |
|
238 |
|
220 |
public Boolean initialized = null; |
239 |
private Boolean initialized = null; |
221 |
Set result = null; |
240 |
private Set result = null; |
222 |
|
241 |
|
223 |
public WizardDescriptor.Panel current () { |
242 |
public WizardDescriptor.Panel current () { |
224 |
assertTrue ("WD.current() called on initialized iterator.", initialized != null && initialized.booleanValue ()); |
243 |
assertTrue ("WD.current() called on initialized iterator.", initialized != null && initialized.booleanValue ()); |
Lines 248-255
Link Here
|
248 |
changeListenersInIterator.remove (l); |
267 |
changeListenersInIterator.remove (l); |
249 |
} |
268 |
} |
250 |
public java.util.Set instantiate () throws IOException { |
269 |
public java.util.Set instantiate () throws IOException { |
251 |
if (checkAWTQueue && SwingUtilities.isEventDispatchThread ()) { |
270 |
if (checkIfInAWT) { |
252 |
throw new IOException ("Don't call from AWT queue."); |
271 |
if (! SwingUtilities.isEventDispatchThread ()) { |
|
|
272 |
throw new IOException ("Must run in AWT queue."); |
273 |
} |
253 |
} |
274 |
} |
254 |
if (shouldThrowException) { |
275 |
if (shouldThrowException) { |
255 |
throw new IOException ("Test throw IOException during instantiate()."); |
276 |
throw new IOException ("Test throw IOException during instantiate()."); |
Lines 303-306
Link Here
|
303 |
} |
324 |
} |
304 |
return "UNKNOWN OPTION: " + val; |
325 |
return "UNKNOWN OPTION: " + val; |
305 |
} |
326 |
} |
306 |
} |
327 |
|
|
|
328 |
public static void finishWizard (WizardDescriptor wd) { |
329 |
wd.doFinishClick (); |
330 |
RequestProcessor.getDefault ().post (new Runnable () { |
331 |
public void run () {} |
332 |
}).waitFinished (); |
333 |
} |
334 |
} |