|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2002 Sun * Microsystems, Inc. All Rights Reserved. */ package org.openide.nodes; import java.beans.*; import java.util.*; import junit.textui.TestRunner; import org.netbeans.junit.NbTestCase; import org.netbeans.junit.NbTestSuite; import org.openide.nodes.*; /** Test Children.Array. * @author Jesse Glick */ public class ChildrenArrayTest extends NbTestCase { public ChildrenArrayTest(String name) { super(name); } public static void main(String[] args) { TestRunner.run(new NbTestSuite(ChildrenArrayTest.class)); } /** Tests that node membership events are fired even before getNodes is called. * @see "#24851" */ public void testNodeEventsFiredAtOnce() { // Stage 1: call getNodes first, after addNodeListener. Children kids = new Children.Array(); Node root = new AbstractNode(kids); WaitNL l = new WaitNL(); root.addNodeListener(l); kids.getNodes(); Node a = node("a"); kids.add(new Node[] {a}); assertTrue(l.didAdd(a)); Node b = node("b"); kids.add(new Node[] {b}); assertTrue(l.didAdd(b)); Node c = node("c"); kids.add(new Node[] {c}); assertTrue(l.didAdd(c)); // Stage 2: call before addNodeListener. kids = new Children.Array(); root = new AbstractNode(kids); kids.getNodes(); l = new WaitNL(); root.addNodeListener(l); a = node("a"); kids.add(new Node[] {a}); assertTrue(l.didAdd(a)); b = node("b"); kids.add(new Node[] {b}); assertTrue(l.didAdd(b)); c = node("c"); kids.add(new Node[] {c}); assertTrue(l.didAdd(c)); // Stage 3: don't call getNodes explicitly. Events should not be fired kids = new Children.Array(); root = new AbstractNode(kids); l = new WaitNL(); root.addNodeListener(l); a = node("a"); kids.add(new Node[] {a}); assertTrue("First node added w/o explicit getNodes() is notified", !l.didAdd(a)); b = node("b"); kids.add(new Node[] {b}); assertFalse(l.didAdd(b)); c = node("c"); kids.add(new Node[] {c}); assertFalse(l.didAdd(c)); } public void testParentAssigned() { Children ch = new Children.Array(); Node n1 = new AbstractNode( ch ); Node n2 = new AbstractNode( Children.LEAF ); ch.add( new Node[] { n2 } ); assertEquals( "Parent is assigned", n1, n2.getParentNode() ); } private static Node node(String name) { Node n = new AbstractNode(Children.LEAF); n.setName(name); return n; } /** Node listener that will tell you if it gets a change. */ private static final class WaitNL implements NodeListener { private final Set added = new HashSet(); // Set |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.