1 19 20 package org.netbeans.core.windows.view.ui; 21 22 import java.awt.Component ; 23 import java.util.Arrays ; 24 import java.util.Collection ; 25 import javax.swing.JLabel ; 26 import javax.swing.JPanel ; 27 import junit.textui.TestRunner; 28 import java.net.*; 29 import org.openide.util.Lookup; 30 import org.openide.util.lookup.AbstractLookup; 31 import org.openide.util.lookup.InstanceContent; 32 import org.openide.util.lookup.Lookups; 33 34 import org.netbeans.junit.*; 35 import org.netbeans.core.*; 36 import org.openide.awt.StatusLineElementProvider; 37 38 39 43 public class StatusLineElementProviderTest extends NbTestCase { 44 45 static { 46 System.setProperty ("org.openide.util.Lookup", "org.netbeans.core.windows.view.ui.StatusLineElementProviderTest$Lkp"); 47 } 48 49 static private InstanceContent ic = null; 50 static private Impl impl1, impl2; 51 static private JPanel statusLine; 52 53 public StatusLineElementProviderTest(String name) { 54 super(name); 55 } 56 57 public static void main(String [] args) { 58 TestRunner.run(new NbTestSuite(StatusLineElementProviderTest.class)); 59 } 60 61 protected boolean runInEQ () { 62 return true; 63 } 64 65 protected void setUp() { 66 impl1 = new Impl ("First"); 67 impl2 = new Impl ("Second"); 68 statusLine = new JPanel (); 69 Lookup.getDefault (); 70 } 71 72 public void testGetStatusLineElements () { 73 JPanel panel = MainWindow.getStatusLineElements (statusLine); 75 assertNotNull ("getStatusLineElements() returns a panel.", panel); 76 assertEquals ("Panel contains only one component.", 1, panel.getComponentCount ()); 77 assertTrue ("Panel contains the component Comp1.", Arrays.asList (panel.getComponents ()).contains (impl1.myComponent)); 78 79 ic.remove (impl1); 81 panel = MainWindow.getStatusLineElements (statusLine); 82 assertNull ("getStatusLineElements() returns null, panel: " + panel, panel); 83 84 ic.add (impl1); 86 panel = MainWindow.getStatusLineElements (statusLine); 87 assertNotNull ("getStatusLineElements() returns a panel.", panel); 88 assertEquals ("Panel contains only one component.", 1, panel.getComponentCount ()); 89 assertTrue ("Panel contains the component Comp1.", Arrays.asList (panel.getComponents ()).contains (impl1.myComponent)); 90 91 ic.add (impl2); 93 panel = MainWindow.getStatusLineElements (statusLine); 94 assertNotNull ("getStatusLineElements() returns a panel.", panel); 95 assertEquals ("Panel contains two components.", 2, panel.getComponentCount ()); 96 assertTrue ("Panel contains the component from impl1.", Arrays.asList (panel.getComponents ()).contains (impl1.myComponent)); 97 assertTrue ("Panel contains the component from impl2.", Arrays.asList (panel.getComponents ()).contains (impl2.myComponent)); 98 } 99 100 101 public static final class Lkp extends AbstractLookup { 102 public Lkp () { 103 this (new InstanceContent ()); 104 } 105 106 private Lkp (InstanceContent instanceContent) { 107 super (instanceContent); 108 ic = instanceContent; 109 ic.add (impl1); 110 } 111 } 112 113 private static class Impl implements StatusLineElementProvider { 114 public Component myComponent; 115 private String myId; 116 public Impl (String id) { 117 myId = id; 118 } 119 public Component getStatusLineElement() { 120 myComponent = new JLabel (myId); 121 return myComponent; 122 } 123 } 124 125 } | Popular Tags |