KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > lookup > InstanceDataObjectModule38420Test


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.core.lookup;
21
22 import java.lang.ref.WeakReference JavaDoc;
23 import javax.swing.Action JavaDoc;
24 import org.openide.util.Lookup;
25
26 /** A test.
27  */

28 public class InstanceDataObjectModule38420Test extends InstanceDataObjectModuleTestHid {
29
30     public InstanceDataObjectModule38420Test (String JavaDoc name) {
31         super(name);
32     }
33
34     public void testEnableDisableOfModulePreservesExistingInstances () throws Exception JavaDoc {
35         Lookup.Result res = Lookup.getDefault ().lookupResult(Action JavaDoc.class);
36         Action JavaDoc found = null;
37         twiddle(m1, TWIDDLE_ENABLE);
38         try {
39             twiddle(m2, TWIDDLE_ENABLE);
40             StringBuffer JavaDoc foundLog = new StringBuffer JavaDoc ();
41             try {
42                 java.util.Iterator JavaDoc it = res.allInstances ().iterator ();
43                 while (it.hasNext ()) {
44                     Action JavaDoc a = (Action JavaDoc)it.next ();
45                     if ("test1.SomeAction".equals (a.getClass ().getName ())) {
46                         found = a;
47                     } else {
48                         foundLog.append ("Found: ");
49                         foundLog.append (a.getClass ().getName ());
50                         foundLog.append ("\n");
51                     }
52                 }
53                 assertNotNull ("Action from module m1 has been found. Only found:\n" + foundLog, found);
54
55             } finally {
56                 twiddle (m2, TWIDDLE_DISABLE);
57             }
58
59             Action JavaDoc again = Lookup.getDefault().lookup(found.getClass());
60             assertSame ("The instance remains the same", found, again);
61             
62             WeakReference JavaDoc ref = new WeakReference JavaDoc(found);
63             found = null;
64             again = null;
65             res = null;
66             assertGC ("Content of lookup is hold by a weak reference", ref);
67
68         } finally {
69             twiddle(m1, TWIDDLE_DISABLE);
70         }
71     }
72     
73 }
74
Popular Tags