1 19 20 package org.netbeans.core.lookup; 21 22 import java.lang.ref.WeakReference ; 23 import javax.swing.Action ; 24 import org.openide.util.Lookup; 25 26 28 public class InstanceDataObjectModule38420Test extends InstanceDataObjectModuleTestHid { 29 30 public InstanceDataObjectModule38420Test (String name) { 31 super(name); 32 } 33 34 public void testEnableDisableOfModulePreservesExistingInstances () throws Exception { 35 Lookup.Result res = Lookup.getDefault ().lookupResult(Action .class); 36 Action found = null; 37 twiddle(m1, TWIDDLE_ENABLE); 38 try { 39 twiddle(m2, TWIDDLE_ENABLE); 40 StringBuffer foundLog = new StringBuffer (); 41 try { 42 java.util.Iterator it = res.allInstances ().iterator (); 43 while (it.hasNext ()) { 44 Action a = (Action )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 again = Lookup.getDefault().lookup(found.getClass()); 60 assertSame ("The instance remains the same", found, again); 61 62 WeakReference ref = new WeakReference (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 |