1 19 package org.netbeans.modules.timers; 20 21 import java.beans.PropertyVetoException ; 22 import java.io.File ; 23 import java.io.IOException ; 24 import javax.swing.JFrame ; 25 import org.netbeans.junit.MockServices; 26 import org.netbeans.junit.NbTestCase; 27 import org.netbeans.modules.timers.TimeComponent; 28 import org.openide.filesystems.FileObject; 29 import org.openide.filesystems.FileUtil; 30 import org.openide.filesystems.LocalFileSystem; 31 import org.openide.filesystems.Repository; 32 33 37 public class TimesCollectorPeerTest extends NbTestCase { 38 39 public TimesCollectorPeerTest(String name) { 40 super(name); 41 } 42 43 public void testHandleDelete() throws Exception { 44 FileObject dir = makeScratchDir(this); 45 FileObject file = dir.createData("test.txt"); 46 47 TimesCollectorPeer.getDefault().reportTime(file, "test", "test", 0); 48 49 file.delete(); 50 51 assertTrue(TimesCollectorPeer.getDefault().getFiles().isEmpty()); 52 53 JFrame f = new JFrame (); 54 55 f.add(new TimeComponentPanel()); 56 57 f.setVisible(true); 58 59 file = dir.createData("test.txt"); 60 61 TimesCollectorPeer.getDefault().reportTime(file, "test", "test", 0); 62 63 file.delete(); 64 } 65 66 71 public static FileObject makeScratchDir(NbTestCase test) throws IOException { 72 test.clearWorkDir(); 73 File root = test.getWorkDir(); 74 assert root.isDirectory() && root.list().length == 0; 75 FileObject fo = FileUtil.toFileObject(root); 76 if (fo != null) { 77 return fo; 79 } else { 80 LocalFileSystem lfs = new LocalFileSystem(); 82 try { 83 lfs.setRootDirectory(root); 84 } catch (PropertyVetoException e) { 85 assert false : e; 86 } 87 Repository.getDefault().addFileSystem(lfs); 88 return lfs.getRoot(); 89 } 90 } 91 92 @Override 93 protected boolean runInEQ() { 94 return true; 95 } 96 } 97 | Popular Tags |