This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 211847
Collapse All | Expand All

(-)a/openide.nodes/test/unit/src/org/openide/nodes/ChildFactoryTest.java (+31 lines)
Lines 47-52 Link Here
47
import java.beans.*;
47
import java.beans.*;
48
import java.util.*;
48
import java.util.*;
49
import java.util.concurrent.Semaphore;
49
import java.util.concurrent.Semaphore;
50
import java.util.concurrent.atomic.AtomicInteger;
50
import org.netbeans.junit.NbTestCase;
51
import org.netbeans.junit.NbTestCase;
51
import org.netbeans.junit.RandomlyFails;
52
import org.netbeans.junit.RandomlyFails;
52
import org.openide.nodes.ChildFactory.Detachable;
53
import org.openide.nodes.ChildFactory.Detachable;
Lines 311-316 Link Here
311
        assertEquals(5, c.getNodesCount(true));
312
        assertEquals(5, c.getNodesCount(true));
312
    }
313
    }
313
314
315
    public void testNodeRecreation() throws Exception { // #211847
316
        final List<Integer> nodesCreated = new ArrayList<Integer>();
317
        final AtomicInteger size = new AtomicInteger(3);
318
        class F extends ChildFactory<Integer> {
319
            @Override protected boolean createKeys(List<Integer> keys) {
320
                for (int i = 1; i <= size.get(); i++) {
321
                    keys.add(i);
322
                }
323
                return true;
324
            }
325
            @Override protected Node createNodeForKey(Integer key) {
326
                nodesCreated.add(key);
327
                Node n = new AbstractNode(Children.LEAF);
328
                n.setName(key.toString());
329
                return n;
330
            }
331
            void refresh() {
332
                refresh(false);
333
            }
334
        }
335
        F f = new F();
336
        Children c = Children.create(f, true);
337
        assertEquals(3, c.getNodes(true).length);
338
        assertEquals("[1, 2, 3]", nodesCreated.toString());
339
        size.set(4);
340
        f.refresh();
341
        assertEquals(4, c.getNodes(true).length);
342
        assertEquals("[1, 2, 3, 4]", nodesCreated.toString());
343
    }
344
314
    static final class ProviderImpl extends ChildFactory <String> {
345
    static final class ProviderImpl extends ChildFactory <String> {
315
        final Object lock = new Object();
346
        final Object lock = new Object();
316
        volatile boolean wait = false;
347
        volatile boolean wait = false;

Return to bug 211847