1 19 20 package org.openide.explorer.view; 21 22 import java.lang.ref.WeakReference ; 23 import java.util.LinkedList ; 24 import java.util.List ; 25 import org.netbeans.junit.NbTestCase; 26 import org.openide.nodes.AbstractNode; 27 import org.openide.nodes.Children; 28 import org.openide.nodes.Node; 29 30 33 public class NodeListModelTest extends NbTestCase { 34 35 private static final int NO_OF_NODES = 20; 36 37 public NodeListModelTest(String name) { 38 super(name); 39 } 40 41 protected boolean runInEQ() { 42 return true; 43 } 44 45 50 public void testNodesAreReferenced() { 51 52 WeakReference [] tn; 53 54 Node c = new AbstractNode(new CNodeChildren()); 55 NodeListModel model = new NodeListModel(c); 56 57 58 59 tn = new WeakReference [model.getSize()]; 60 for (int i = 0; i < model.getSize(); i++) { 61 tn[i] = new WeakReference (model.getElementAt(i)); 62 } 63 64 assertTrue("Need to have more than one child", tn.length > 0); 65 66 boolean fail; 67 try { 68 assertGC("First node should not be gone", tn[0]); 69 fail = true; 70 } catch (Error err) { 71 fail = false; 72 } 73 if (fail) { 74 fail("First node garbage collected!!! " + tn[0].get()); 75 } 76 77 for (int i = 0; i < tn.length; i++) { 78 assertNotNull("One of the nodes was gone. Index: " + i, tn[i].get()); 80 } 81 } 82 83 86 public void testConstructors() { 87 Node c = new AbstractNode(new CNodeChildren()); 88 NodeListModel model = new NodeListModel(c); 89 90 model.getSize(); 94 } 95 96 99 private static class CNodeChildren extends Children.Keys { 100 public CNodeChildren() { 101 List myKeys = new LinkedList (); 102 for (int i = 0; i < NO_OF_NODES; i++) { 103 myKeys.add(new Integer (i)); 104 } 105 106 setKeys(myKeys); 107 } 108 109 protected Node[] createNodes(Object key) { 110 AbstractNode an = new AbstractNode(Children.LEAF); 111 an.setName(key.toString()); 112 return new Node[] { an }; 113 } 114 } 115 } 116 | Popular Tags |