KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > masterfs > CacheTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.masterfs;
21
22 import java.io.File JavaDoc;
23 import java.lang.ref.Reference JavaDoc;
24 import java.lang.ref.WeakReference JavaDoc;
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 /**
31  *
32  * @author rmatous
33  */

34 public class CacheTest extends NbTestCase {
35     private File JavaDoc testFile;
36     private FileObject testFo;
37
38
39     public CacheTest(String JavaDoc testName) {
40         super(testName);
41     }
42
43     protected void setUp() throws Exception JavaDoc {
44         super.setUp();
45         testFile = new File JavaDoc(getWorkDir(),"testfile");//NOI18N
46
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 JavaDoc {
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 JavaDoc {
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 JavaDoc ref = new WeakReference JavaDoc(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 JavaDoc {
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 JavaDoc ref = new WeakReference JavaDoc(testFo);
87         testFo = null;
88         assertGC("",ref);
89         assertNotNull(Cache.getDefault().get(testFo2.getResource()));
90     }
91     
92     
93 }
94
Popular Tags