1 19 20 package org.openide.windows; 21 22 import javax.swing.SwingUtilities ; 23 import org.netbeans.junit.NbTestCase; 24 25 29 public class WindowManagerHid extends NbTestCase { 30 31 public WindowManagerHid(String testName) { 32 super(testName); 33 } 34 35 public void testGetDefault() { 36 WindowManager result = WindowManager.getDefault(); 37 assertNotNull(result); 38 } 39 40 public void testInvokeWhenUIReady() throws Exception { 41 class R implements Runnable { 42 public boolean started; 43 public boolean finished; 44 public boolean block; 45 46 public synchronized void run() { 47 assertTrue("Runs only in AWT thread", SwingUtilities.isEventDispatchThread()); 48 try { 49 started = true; 50 notifyAll(); 51 if (block) { 52 wait(); 53 } 54 } catch (InterruptedException ex) { 55 ex.printStackTrace(); 56 } 57 finished = true; 58 notifyAll(); 59 } 60 } 61 62 R run = new R(); 63 R snd = new R(); 64 65 WindowManager wm = WindowManager.getDefault(); 66 synchronized (run) { 67 wm.invokeWhenUIReady(run); 68 run.block = true; 69 run.wait(); 70 } 71 assertTrue("started", run.started); 72 assertFalse("but not finished", run.finished); 73 74 wm.invokeWhenUIReady(snd); 75 76 Thread.sleep(100); 77 78 assertFalse("Not started", snd.started); 79 synchronized (snd) { 80 synchronized (run) { 81 run.notifyAll(); 82 run.wait(); 83 } 84 assertTrue("run is finished", run.finished); 85 snd.wait(); 86 assertTrue("snd also finished", snd.finished); 87 } 88 } 89 } 90 | Popular Tags |