Lines 44-51
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 214-220
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 |
Node[] n = ch.getNodes(true); |
224 |
assertEquals (2, n.length); |
225 |
assertEquals ("foo", n[0].getDisplayName()); |
226 |
assertEquals ("bar", n[1].getDisplayName()); |
227 |
ch.removeNotify(); |
228 |
r.assertRemoved(); |
229 |
} |
230 |
|
231 |
public void testAddRemoveNotifyAsynch() throws Exception { |
232 |
DetachableImpl r = new DetachableImpl(); |
233 |
Children ch = Children.create(r, true); |
234 |
new AbstractNode (ch); |
235 |
ch.addNotify(); |
236 |
synchronized(r) { |
237 |
r.wait(1000); |
238 |
} |
239 |
r.assertAdded(); |
240 |
Node[] n = ch.getNodes(true); |
241 |
assertEquals (2, n.length); |
242 |
assertEquals ("foo", n[0].getDisplayName()); |
243 |
assertEquals ("bar", n[1].getDisplayName()); |
244 |
ch.removeNotify(); |
245 |
synchronized(r) { |
246 |
r.wait(1000); |
247 |
} |
248 |
r.assertRemoved(); |
249 |
} |
250 |
|
251 |
|
218 |
static final class ProviderImpl extends ChildFactory <String> { |
252 |
static final class ProviderImpl extends ChildFactory <String> { |
219 |
Object lock = new Object(); |
253 |
Object lock = new Object(); |
220 |
volatile boolean wait = false; |
254 |
volatile boolean wait = false; |
Lines 421-424
Link Here
|
421 |
refresh(true); |
455 |
refresh(true); |
422 |
} |
456 |
} |
423 |
} |
457 |
} |
|
|
458 |
|
459 |
private static final class DetachableImpl extends Detachable<String> { |
460 |
boolean removed; |
461 |
boolean added; |
462 |
|
463 |
@Override |
464 |
protected boolean createKeys(List<String> toPopulate) { |
465 |
toPopulate.add("foo"); |
466 |
toPopulate.add("bar"); |
467 |
synchronized(this) { |
468 |
notifyAll(); |
469 |
} |
470 |
return true; |
471 |
} |
472 |
|
473 |
@Override |
474 |
protected void removeNotify() { |
475 |
synchronized(this) { |
476 |
notifyAll(); |
477 |
} |
478 |
removed = true; |
479 |
} |
480 |
|
481 |
@Override |
482 |
protected Node createNodeForKey(String key) { |
483 |
AbstractNode nd = new AbstractNode(Children.LEAF); |
484 |
nd.setDisplayName(key); |
485 |
return nd; |
486 |
} |
487 |
|
488 |
@Override |
489 |
protected void addNotify() { |
490 |
added = true; |
491 |
} |
492 |
|
493 |
void assertAdded() { |
494 |
assertTrue (added); |
495 |
} |
496 |
|
497 |
void assertRemoved() { |
498 |
assertTrue (removed); |
499 |
} |
500 |
} |
424 |
} |
501 |
} |