1 19 package org.netbeans.modules.timers; 20 21 import java.lang.ref.WeakReference ; 22 import javax.swing.event.ChangeEvent ; 23 import javax.swing.event.ChangeListener ; 24 import org.netbeans.junit.NbTestCase; 25 26 30 public class InstanceWatcherTest extends NbTestCase { 31 32 public InstanceWatcherTest(String testName) { 33 super(testName); 34 } 35 36 public void testFiring() throws Exception { 37 System.out.println("addChangeListener"); 38 39 QueueListener listener = new QueueListener(); 40 InstanceWatcher iw = new InstanceWatcher(); 41 42 iw.addChangeListener(listener); 43 44 Integer ts1 = new Integer ( 20 ); 45 iw.add( ts1 ); 46 47 WeakReference tmp; 49 tmp = new WeakReference ( new Object () ); 50 assertGC( "", tmp ); 51 52 assertEquals( "There should be no change in the queue", 0, listener.changeCount ); 53 54 ts1 = null; 56 tmp = new WeakReference ( new Object () ); 57 assertGC( "", tmp ); 59 assertEquals( "There should be one change in the queue", 1, listener.changeCount ); 60 61 } 62 63 64 private static class QueueListener implements ChangeListener { 65 66 int changeCount; 67 68 public void stateChanged( ChangeEvent e ) { 69 changeCount ++; 70 } 71 72 } 73 74 } | Popular Tags |