1 19 20 package org.openide.loaders; 21 22 import junit.framework.*; 23 import org.openide.filesystems.*; 24 import org.openide.nodes.Node; 25 import org.openide.util.Lookup; 26 import org.openide.util.lookup.Lookups; 27 import org.openide.util.lookup.ProxyLookup; 28 29 32 public class FolderRenameHandlerTest extends TestCase { 33 static { 34 System.setProperty ("org.openide.util.Lookup", Lkp.class.getName()); } 36 37 private FileObject fo; 38 private Node n; 39 private FolderRenameHandlerImpl frh = new FolderRenameHandlerImpl(); 40 41 public FolderRenameHandlerTest (String testName) { 42 super (testName); 43 } 44 45 public void setUp() throws Exception { 46 super.setUp(); 47 FileObject root = Repository.getDefault ().getDefaultFileSystem ().getRoot (); 48 fo = FileUtil.createFolder (root, "test"); 50 DataObject obj = DataObject.find (fo); 51 if (! (obj instanceof DataFolder)) { 52 fail ("It should be DataFolder: " + obj); } 54 55 assertNotNull(obj); 56 n = obj.getNodeDelegate(); 57 assertNotNull(n); 58 } 59 60 public void tearDown() throws Exception { 61 super.tearDown(); 62 fo.delete(); 63 } 64 65 public void testRenameHandlerNotCalled () throws Exception { 66 ((Lkp) Lkp.getDefault()).register(new Object []{}); 67 frh.called = false; 68 69 n.setName("blabla"); 70 assertFalse(frh.called); 71 } 72 73 public void testRenameHandlerCalled () throws Exception { 74 ((Lkp) Lkp.getDefault()).register(new Object []{frh}); 75 frh.called = false; 76 77 n.setName("foo"); assertTrue(frh.called); 79 } 80 81 public static class Lkp extends ProxyLookup { 82 public Lkp() { 83 super(new Lookup[0]); 84 } 85 public void register(Object [] instances) { 86 setLookups(new Lookup[] {Lookups.fixed(instances)}); 87 } 88 } 89 private static final class FolderRenameHandlerImpl implements FolderRenameHandler { 90 boolean called = false; 91 public void handleRename(DataFolder folder, String newName) throws IllegalArgumentException { 92 called = true; 93 } 94 } 95 96 } 97 | Popular Tags |