1 19 20 package org.netbeans.modules.loaderswitcher; 21 22 import java.io.IOException ; 23 import java.util.logging.Level ; 24 import org.netbeans.junit.NbTestCase; 25 import org.openide.filesystems.FileObject; 26 import org.openide.filesystems.FileSystem; 27 import org.openide.filesystems.FileUtil; 28 import org.openide.loaders.*; 29 30 34 public class ObjectTypeTest extends NbTestCase 35 implements DataLoader.RecognizedFiles { 36 37 public ObjectTypeTest(String testName) { 38 super(testName); 39 } 40 41 protected Level logLevel() { 42 return Level.ALL; 43 } 44 45 protected void setUp() throws Exception { 46 } 47 48 protected void tearDown() throws Exception { 49 } 50 51 public void testFindAndSwitch() throws Exception { 52 FileSystem fs = FileUtil.createMemoryFileSystem(); 53 FileObject fnd = fs.getRoot().createFolder("testFindAndSwitch"); 54 55 DataObject obj = InstanceDataObject.create(DataFolder.findFolder(fnd), "ahoj", java.awt.FlowLayout .class); 56 57 DataLoader[] x = ObjectType.findPossibleLoaders(obj, this); 58 59 assertEquals("Two loaders shall be interested", 2, x.length); 60 assertEquals("First one is the actual loader", obj.getLoader(), x[0]); 61 62 assertEquals("Name", "ahoj", obj.getName()); 63 64 ObjectType.convertTo(obj, x[1]); 65 66 assertFalse("Old object is invalidated", obj.isValid()); 67 68 DataObject n = DataObject.find(obj.getPrimaryFile()); 69 70 if (n == obj) { 71 fail("They should be different: " + n); 72 } 73 74 assertEquals("The right loader", x[1], n.getLoader()); 75 76 77 assertEquals("Name with extension", "ahoj.instance", n.getName()); 78 79 n.rename("kuk.unknown"); 80 81 DataLoader[] arr = ObjectType.findPossibleLoaders(n, this); 82 assertEquals("Just one loader now", 1, arr.length); 83 assertEquals("and it is the default loader", n.getLoader(), arr[0]); 84 85 } 86 87 public void markRecognized(FileObject fo) { 88 } 89 } 90 | Popular Tags |