KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > loaders > DataObjectSizeTest


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.openide.loaders;
21
22 import java.lang.ref.WeakReference JavaDoc;
23 import java.util.HashSet JavaDoc;
24 import junit.textui.TestRunner;
25 import org.openide.filesystems.*;
26 import java.util.Enumeration JavaDoc;
27 import org.openide.nodes.Node;
28 import org.openide.cookies.InstanceCookie;
29 import org.openide.filesystems.Repository;
30 import org.netbeans.junit.*;
31
32 /** How big is default data object?
33  * @author Jaroslav Tulach
34  */

35 public class DataObjectSizeTest extends NbTestCase {
36     static FileSystem lfs;
37     static DataObject original;
38
39     public DataObjectSizeTest(String JavaDoc name) {
40         super(name);
41     }
42     
43     protected void setUp() throws java.lang.Exception JavaDoc {
44         if (original == null) {
45             String JavaDoc fsstruct [] = new String JavaDoc [] {
46                 "folder/original.txt",
47             };
48             TestUtilHid.destroyLocalFileSystem (getName());
49             lfs = TestUtilHid.createLocalFileSystem (getWorkDir (), fsstruct);
50             FileObject fo = FileUtil.createData (lfs.getRoot (), "/folder/original.txt");
51             assertNotNull(fo);
52             original = DataObject.find (fo);
53
54             assertFalse ("Not a folder", original instanceof DataFolder);
55         }
56     }
57     
58     public void testThatThereIsJustOneItemIssue42857 () throws Exception JavaDoc {
59         Object JavaDoc[] exclude = {
60             original.getLoader (),
61             original.getPrimaryFile (),
62             org.openide.util.Utilities.activeReferenceQueue (),
63         };
64         
65         assertSize ("If we exclude all the static things, like loader and " +
66             " reference queue and things we do not have control upon like file object" +
67             " we should get some reasonable size for the data object. ",
68             java.util.Collections.singleton (original), 280, exclude
69         );
70     }
71     
72     public void testNumberOfDataObjectPoolItemsIssue42857 () throws Exception JavaDoc {
73         class CountItems implements MemoryFilter {
74             HashSet JavaDoc items = new HashSet JavaDoc ();
75             
76             public boolean reject(java.lang.Object JavaDoc obj) {
77                 if (obj instanceof DataObjectPool.Item) {
78                     items.add (obj);
79                 }
80                 
81                 return false;
82             }
83         }
84         CountItems cnt = new CountItems ();
85         assertSize (
86             "Just iterate thru all the objects available and count Items",
87             java.util.Collections.singleton (DataObjectPool.getPOOL ()),
88             Integer.MAX_VALUE,
89             cnt
90         );
91         
92         if (cnt.items.size () != 1) {
93             fail ("There should be one item, but was " + cnt.items.size () + "\n" + cnt.items);
94         }
95     }
96 }
97
Popular Tags