1 19 package org.netbeans.modules.editor.highlights; 20 21 import java.beans.PropertyVetoException ; 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.lang.ref.Reference ; 25 import java.lang.ref.WeakReference ; 26 import javax.swing.JEditorPane ; 27 import javax.swing.text.Document ; 28 import javax.swing.text.JTextComponent ; 29 import javax.swing.text.PlainDocument ; 30 import org.netbeans.editor.BaseTextUI; 31 import org.netbeans.junit.NbTestCase; 32 import org.openide.filesystems.FileObject; 33 import org.openide.filesystems.FileUtil; 34 import org.openide.filesystems.LocalFileSystem; 35 import org.openide.filesystems.Repository; 36 import org.openide.loaders.DataObject; 37 38 42 public class HighlighterImplTest extends NbTestCase { 43 44 public HighlighterImplTest(String testName) { 45 super(testName); 46 } 47 48 protected void setUp() throws Exception { 49 } 50 51 public void testIsReclaimable() throws Exception { 52 FileObject dir = makeScratchDir(this); 53 FileObject file = dir.createData("test.txt"); 54 JTextComponent c = new JEditorPane (); 55 56 HighlighterImpl.getDefault().assureRegistered(c); 57 58 Document d = new PlainDocument (); 59 60 d.putProperty(Document.StreamDescriptionProperty, DataObject.find(file)); 61 c.setDocument(d); 62 63 Reference fileR = new WeakReference (file); 64 Reference cR = new WeakReference (c); 65 Reference docR = new WeakReference (d); 66 67 dir = null; 68 file = null; 69 c = null; 70 d = null; 71 72 assertGC("", cR); 73 assertGC("", docR); 74 75 HighlighterImpl.getDefault().assureRegistered(new JEditorPane ()); 77 78 assertGC("", fileR); 79 } 80 81 public boolean runInEQ() { 82 return true; 83 } 84 89 public static FileObject makeScratchDir(NbTestCase test) throws IOException { 90 test.clearWorkDir(); 91 File root = test.getWorkDir(); 92 assert root.isDirectory() && root.list().length == 0; 93 FileObject fo = FileUtil.toFileObject(root); 94 if (fo != null) { 95 return fo; 97 } else { 98 LocalFileSystem lfs = new LocalFileSystem(); 100 try { 101 lfs.setRootDirectory(root); 102 } catch (PropertyVetoException e) { 103 assert false : e; 104 } 105 Repository.getDefault().addFileSystem(lfs); 106 return lfs.getRoot(); 107 } 108 } 109 110 } 111 | Popular Tags |