1 19 20 package org.netbeans.spi.project.ui.support; 21 22 import com.sun.org.apache.bcel.internal.generic.LOOKUPSWITCH; 23 import junit.framework.TestCase; 24 import junit.framework.*; 25 import java.io.IOException ; 26 import java.util.ArrayList ; 27 import java.util.Arrays ; 28 import java.util.Collections ; 29 import java.util.Enumeration ; 30 import java.util.HashMap ; 31 import java.util.Iterator ; 32 import java.util.List ; 33 import java.util.Map ; 34 import javax.swing.event.ChangeEvent ; 35 import javax.swing.event.ChangeListener ; 36 import org.netbeans.api.project.Project; 37 import org.netbeans.junit.MockServices; 38 import org.openide.ErrorManager; 39 import org.openide.cookies.InstanceCookie; 40 import org.openide.filesystems.FileAttributeEvent; 41 import org.openide.filesystems.FileChangeListener; 42 import org.openide.filesystems.FileEvent; 43 import org.openide.filesystems.FileObject; 44 import org.openide.filesystems.FileRenameEvent; 45 import org.openide.filesystems.Repository; 46 import org.openide.loaders.DataFolder; 47 import org.openide.loaders.DataObject; 48 import org.openide.loaders.DataObjectNotFoundException; 49 import org.openide.loaders.FolderLookup; 50 import org.openide.loaders.InstanceDataObject; 51 import org.openide.nodes.AbstractNode; 52 import org.openide.nodes.Children; 53 import org.openide.nodes.Node; 54 import org.openide.util.Lookup; 55 import org.openide.util.LookupEvent; 56 import org.openide.util.LookupListener; 57 import org.openide.util.lookup.AbstractLookup; 58 import org.openide.util.lookup.InstanceContent; 59 60 64 public class NodeFactorySupportTest extends TestCase { 65 66 public NodeFactorySupportTest(String testName) { 67 super(testName); 68 } 69 70 protected void setUp() throws Exception { 71 } 72 73 protected void tearDown() throws Exception { 74 } 75 76 79 public void testCreateCompositeChildren() { 80 System.out.println("createCompositeChildren"); 81 InstanceContent ic = new InstanceContent(); 82 TestDelegates dels = new TestDelegates(ic); 83 Node node1 = new AbstractNode(Children.LEAF); 84 Node node2 = new AbstractNode(Children.LEAF); 85 Node node3 = new AbstractNode(Children.LEAF); 86 Node node4 = new AbstractNode(Children.LEAF); 87 node1.setName("node1"); 88 node2.setName("node2"); 89 node3.setName("node3"); 90 node4.setName("node4"); 91 NodeFactory fact1 = new TestNodeFactory(node1); 92 NodeFactory fact2 = new TestNodeFactory(node2); 93 NodeFactory fact3 = new TestNodeFactory(node3); 94 NodeFactory fact4 = new TestNodeFactory(node4); 95 List col = new ArrayList (); 96 col.add(fact1); 97 col.add(fact2); 98 ic.set(col, null); 99 100 Node[] nds = dels.getNodes(); 101 assertEquals(nds[0], node1); 102 assertEquals(nds[1], node2); 103 104 col.add(0, fact4); 105 col.add(fact3); 106 col.remove(fact2); 107 ic.set(col, null); 108 nds = dels.getNodes(); 109 assertEquals(nds[0], node4); 110 assertEquals(nds[1], node1); 111 assertEquals(nds[2], node3); 112 113 } 114 115 private class TestNodeFactory implements NodeFactory { 116 117 Node node; 118 public TestNodeFactory(Node node) { 119 this.node = node; 120 } 121 public NodeList createNodes(Project p) { 122 return NodeFactorySupport.fixedNodeList(new Node[] {node}); 123 } 124 } 125 126 private class TestDelegates extends NodeFactorySupport.DelegateChildren { 127 public AbstractLookup.Content content; 128 TestDelegates(AbstractLookup.Content cont) { 129 super(null, null); 130 content = cont; 131 } 132 133 protected Lookup createLookup() { 134 return new AbstractLookup(content); 135 } 136 137 public void addNotify() { 138 super.addNotify(); 139 } 140 141 public void removeNotify() { 142 super.removeNotify(); 143 } 144 } 145 146 } 147 | Popular Tags |