1 19 20 package org.netbeans.modules.masterfs; 21 22 import java.io.File ; 23 import java.lang.ref.Reference ; 24 import java.lang.ref.WeakReference ; 25 import org.netbeans.junit.NbTestCase; 26 import org.netbeans.modules.masterfs.providers.ProvidedExtensionsTest; 27 import org.openide.filesystems.FileObject; 28 import org.openide.filesystems.FileUtil; 29 30 34 public class CacheTest extends NbTestCase { 35 private File testFile; 36 private FileObject testFo; 37 38 39 public CacheTest(String testName) { 40 super(testName); 41 } 42 43 protected void setUp() throws Exception { 44 super.setUp(); 45 testFile = new File (getWorkDir(),"testfile"); if (!testFile.exists()) { 47 assert testFile.createNewFile(); 48 } 49 testFo = FileUtil.toFileObject(testFile); 50 assert testFo != null; 51 52 } 53 54 public void testIssue64363() throws Exception { 55 assertTrue(testFo.isValid()); 56 assertTrue(testFile.delete()); 57 testFo.getFileSystem().findResource(testFo.getPath()); 58 59 FileObject testFo2 = Cache.getDefault().getValidOrInvalid(((MasterFileObject)testFo).getResource()); 60 if (!ProvidedExtensionsTest.ProvidedExtensionsImpl.isImplsDeleteRetVal()) { 61 assertFalse(testFo2.isValid()); 62 } 63 assertEquals(testFo, testFo2); 64 } 65 66 public void testIssue61221() throws Exception { 67 assertTrue(testFo.isValid()); 68 FileObject par = testFo.getParent(); 69 testFo.delete(); 70 MasterFileObject testFo2 = (MasterFileObject)par.createData(testFo.getNameExt()); 71 assertNotSame(testFo2, testFo); 72 Reference ref = new WeakReference (testFo); 73 testFo = null; 74 assertGC("",ref); 75 MasterFileObject testFo3 = (MasterFileObject)par.getFileObject(testFo2.getNameExt()); 76 assertEquals(testFo3.isValid(), testFo2.isValid()); 77 assertSame(testFo3, testFo2); 78 } 79 80 public void testIssue61221_2() throws Exception { 81 assertTrue(testFo.isValid()); 82 FileObject par = testFo.getParent(); 83 testFo.delete(); 84 MasterFileObject testFo2 = (MasterFileObject)par.createData(testFo.getNameExt()); 85 assertNotSame(testFo2, testFo); 86 Reference ref = new WeakReference (testFo); 87 testFo = null; 88 assertGC("",ref); 89 assertNotNull(Cache.getDefault().get(testFo2.getResource())); 90 } 91 92 93 } 94 | Popular Tags |