1 19 20 package org.netbeans.spi.java.project.support.ui; 21 22 import org.netbeans.api.project.SourceGroup; 23 import org.netbeans.api.project.TestUtil; 24 import org.netbeans.junit.NbTestCase; 25 import org.netbeans.spi.project.support.GenericSources; 26 import org.openide.filesystems.FileObject; 27 import org.openide.filesystems.FileUtil; 28 import org.openide.nodes.Children; 29 import org.openide.nodes.Node; 30 31 34 public class PackageRenameHandlerTest extends NbTestCase { 35 36 private FileObject fo; 37 private Node n; 38 private PackageRenameHandlerImpl frh = new PackageRenameHandlerImpl(); 39 40 41 public PackageRenameHandlerTest(String testName) { 42 super(testName); 43 } 44 45 public void setUp() throws Exception { 46 super.setUp(); 47 FileObject root = TestUtil.makeScratchDir(this); 48 fo = FileUtil.createFolder(root, "test"); 50 SourceGroup group = GenericSources.group(null, root.createFolder("src"), "testGroup", "Test Group", null, null); 51 Children ch = PackageView.createPackageView(group).getChildren(); 52 53 FileUtil.createFolder(root, "src/foo"); 55 n = ch.findChild("foo"); 56 57 assertNotNull(n); 58 } 59 60 public void testRenameHandlerNotCalled() throws Exception { 61 TestUtil.setLookup(new Object [0]); 62 frh.called = false; 63 64 n.setName("blabla"); 65 assertFalse(frh.called); 66 } 67 68 public void testRenameHandlerCalled() throws Exception { 69 TestUtil.setLookup(new Object [] {frh}); 70 frh.called = false; 71 72 n.setName("foo"); assertTrue(frh.called); 74 } 75 76 private static final class PackageRenameHandlerImpl implements PackageRenameHandler { 77 boolean called = false; 78 public void handleRename(Node n, String newName) throws IllegalArgumentException { 79 called = true; 80 } 81 } 82 83 } 84 | Popular Tags |