Lines 44-51
import java.beans.*;
Link Here
|
44 |
import java.beans.*; |
44 |
import java.beans.*; |
45 |
import java.util.*; |
45 |
import java.util.*; |
46 |
import junit.framework.TestCase; |
46 |
import junit.framework.TestCase; |
47 |
import org.openide.nodes.*; |
47 |
import org.openide.nodes.ChildFactory.Detachable; |
48 |
import org.openide.nodes.NodeAdapter; |
|
|
49 |
import org.openide.util.NbBundle; |
48 |
import org.openide.util.NbBundle; |
50 |
|
49 |
|
51 |
/** Test for AsynchChildren, ChildFactory and SynchChildren. |
50 |
/** Test for AsynchChildren, ChildFactory and SynchChildren. |
Lines 202-208
public class ChildFactoryTest extends Te
Link Here
|
202 |
Thread.interrupted(); |
201 |
Thread.interrupted(); |
203 |
factory.wait = true; |
202 |
factory.wait = true; |
204 |
kids.addNotify(); |
203 |
kids.addNotify(); |
205 |
Thread.currentThread().yield(); |
204 |
Thread.yield(); |
206 |
synchronized (factory.lock) { |
205 |
synchronized (factory.lock) { |
207 |
factory.lock.wait(500); |
206 |
factory.lock.wait(500); |
208 |
} |
207 |
} |
Lines 214-220
public class ChildFactoryTest extends Te
Link Here
|
214 |
assertTrue(kids.cancelled); |
213 |
assertTrue(kids.cancelled); |
215 |
assertTrue(factory.cancelled); |
214 |
assertTrue(factory.cancelled); |
216 |
} |
215 |
} |
217 |
|
216 |
|
|
|
217 |
public void testAddRemoveNotifySynch() throws Exception { |
218 |
DetachableImpl r = new DetachableImpl(); |
219 |
Children ch = Children.create(r, false); |
220 |
new AbstractNode (ch); |
221 |
ch.addNotify(); |
222 |
r.assertAdded(); |
223 |
ch.removeNotify(); |
224 |
r.assertRemoved(); |
225 |
r = new DetachableImpl(); |
226 |
ch = Children.create(r, false); |
227 |
Node[] n = ch.getNodes(true); |
228 |
assertEquals (2, n.length); |
229 |
assertEquals ("foo", n[0].getDisplayName()); |
230 |
assertEquals ("bar", n[1].getDisplayName()); |
231 |
ch.removeNotify(); |
232 |
r.assertRemoved(); |
233 |
} |
234 |
|
235 |
public void testAddRemoveNotifyAsynch() throws Exception { |
236 |
DetachableImpl r = new DetachableImpl(); |
237 |
Children ch = Children.create(r, true); |
238 |
new AbstractNode (ch); |
239 |
ch.addNotify(); |
240 |
synchronized(r) { |
241 |
r.wait(1000); |
242 |
} |
243 |
r.assertAdded(); |
244 |
Node[] n = ch.getNodes(true); |
245 |
assertEquals (2, n.length); |
246 |
assertEquals ("foo", n[0].getDisplayName()); |
247 |
assertEquals ("bar", n[1].getDisplayName()); |
248 |
ch.removeNotify(); |
249 |
synchronized(r) { |
250 |
r.wait(1000); |
251 |
} |
252 |
r.assertRemoved(); |
253 |
} |
254 |
|
255 |
|
218 |
static final class ProviderImpl extends ChildFactory <String> { |
256 |
static final class ProviderImpl extends ChildFactory <String> { |
219 |
Object lock = new Object(); |
257 |
Object lock = new Object(); |
220 |
volatile boolean wait = false; |
258 |
volatile boolean wait = false; |
Lines 421-424
public class ChildFactoryTest extends Te
Link Here
|
421 |
refresh(true); |
459 |
refresh(true); |
422 |
} |
460 |
} |
423 |
} |
461 |
} |
|
|
462 |
|
463 |
private static final class DetachableImpl extends Detachable<String> { |
464 |
boolean removed; |
465 |
boolean added; |
466 |
|
467 |
@Override |
468 |
protected boolean createKeys(List<String> toPopulate) { |
469 |
toPopulate.add("foo"); |
470 |
toPopulate.add("bar"); |
471 |
synchronized(this) { |
472 |
notifyAll(); |
473 |
} |
474 |
return true; |
475 |
} |
476 |
|
477 |
@Override |
478 |
protected void removeNotify() { |
479 |
assertFalse (removed); |
480 |
synchronized(this) { |
481 |
notifyAll(); |
482 |
} |
483 |
removed = true; |
484 |
added = false; |
485 |
} |
486 |
|
487 |
@Override |
488 |
protected Node createNodeForKey(String key) { |
489 |
AbstractNode nd = new AbstractNode(Children.LEAF); |
490 |
nd.setDisplayName(key); |
491 |
return nd; |
492 |
} |
493 |
|
494 |
@Override |
495 |
protected void addNotify() { |
496 |
assertFalse (added); |
497 |
added = true; |
498 |
} |
499 |
|
500 |
void assertAdded() { |
501 |
assertTrue (added); |
502 |
} |
503 |
|
504 |
void assertRemoved() { |
505 |
assertTrue (removed); |
506 |
} |
507 |
} |
424 |
} |
508 |
} |