KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > timers > TimesCollectorPeerTest


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 package org.netbeans.modules.timers;
20
21 import java.beans.PropertyVetoException JavaDoc;
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import javax.swing.JFrame JavaDoc;
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 /**
34  *
35  * @author Jan Lahoda
36  */

37 public class TimesCollectorPeerTest extends NbTestCase {
38
39     public TimesCollectorPeerTest(String JavaDoc name) {
40         super(name);
41     }
42     
43     public void testHandleDelete() throws Exception JavaDoc {
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 JavaDoc f = new JFrame JavaDoc();
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     /**Copied from org.netbeans.api.project.
67      * Create a scratch directory for tests.
68      * Will be in /tmp or whatever, and will be empty.
69      * If you just need a java.io.File use clearWorkDir + getWorkDir.
70      */

71     public static FileObject makeScratchDir(NbTestCase test) throws IOException JavaDoc {
72         test.clearWorkDir();
73         File JavaDoc root = test.getWorkDir();
74         assert root.isDirectory() && root.list().length == 0;
75         FileObject fo = FileUtil.toFileObject(root);
76         if (fo != null) {
77             // Presumably using masterfs.
78
return fo;
79         } else {
80             // For the benefit of those not using masterfs.
81
LocalFileSystem lfs = new LocalFileSystem();
82             try {
83                 lfs.setRootDirectory(root);
84             } catch (PropertyVetoException JavaDoc e) {
85                 assert false : e;
86             }
87             Repository.getDefault().addFileSystem(lfs);
88             return lfs.getRoot();
89         }
90     }
91     
92     @Override JavaDoc
93     protected boolean runInEQ() {
94         return true;
95     }
96 }
97
Popular Tags