More tests for everybody docs-nb50l10n98handoff release50_coco_root version-2-3-57
authorjtulach@netbeans.org
Thu, 24 Nov 2005 14:57:37 +0000
changeset 91a1184606e6ea
parent 90 bafe0eae2b19
child 92 42dc82cfc022
More tests for everybody
openide.util/test/unit/src/org/openide/util/lookup/AbstractLookupBaseHid.java
     1.1 --- a/openide.util/test/unit/src/org/openide/util/lookup/AbstractLookupBaseHid.java	Thu Nov 24 13:49:29 2005 +0000
     1.2 +++ b/openide.util/test/unit/src/org/openide/util/lookup/AbstractLookupBaseHid.java	Thu Nov 24 14:57:37 2005 +0000
     1.3 @@ -23,6 +23,7 @@
     1.4  import org.netbeans.junit.*;
     1.5  import java.io.Serializable;
     1.6  import org.openide.util.Lookup.Item;
     1.7 +import org.openide.util.Lookup.Provider;
     1.8  import org.openide.util.Lookup.Result;
     1.9  import org.openide.util.Lookup.Template;
    1.10  
    1.11 @@ -1274,10 +1275,22 @@
    1.12      public void testChangeOfNodeDoesNotFireChangeInActionMap() {
    1.13          ActionMap am = new ActionMap();
    1.14          Lookup s = Lookups.singleton(am);
    1.15 -        doChangeOfNodeDoesNotFireChangeInActionMap(am, s);
    1.16 +        doChangeOfNodeDoesNotFireChangeInActionMap(am, s, false);
    1.17 +    }
    1.18 +    public void testChangeOfNodeDoesNotFireChangeInActionMapSimple() {
    1.19 +        ActionMap am = new ActionMap();
    1.20 +        Lookup s = Lookups.singleton(am);
    1.21 +        doChangeOfNodeDoesNotFireChangeInActionMap(am, s, true);
    1.22      }
    1.23  
    1.24 +    public void testChangeOfNodeDoesNotFireChangeInActionMapWithBeforeLookupSimple() {
    1.25 +        doChangeOfNodeDoesNotFireChangeInActionMapWithBeforeLookup(true);
    1.26 +    }
    1.27 +    
    1.28      public void testChangeOfNodeDoesNotFireChangeInActionMapWithBeforeLookup() {
    1.29 +        doChangeOfNodeDoesNotFireChangeInActionMapWithBeforeLookup(false);
    1.30 +    }
    1.31 +    private void doChangeOfNodeDoesNotFireChangeInActionMapWithBeforeLookup(boolean wrapBySimple) {
    1.32          final ActionMap am = new ActionMap();
    1.33          
    1.34          class Before extends AbstractLookup {
    1.35 @@ -1300,15 +1313,43 @@
    1.36          }
    1.37          
    1.38          Before s = new Before();
    1.39 -        doChangeOfNodeDoesNotFireChangeInActionMap(am, s);
    1.40 +        doChangeOfNodeDoesNotFireChangeInActionMap(am, s, wrapBySimple);
    1.41          
    1.42          assertNull("beforeLookup called once", s.ic);
    1.43      }
    1.44      
    1.45 -    private void doChangeOfNodeDoesNotFireChangeInActionMap(final ActionMap am, Lookup actionMapLookup) {
    1.46 +    private void doChangeOfNodeDoesNotFireChangeInActionMap(final ActionMap am, Lookup actionMapLookup, final boolean wrapBySimple) {
    1.47          Lookup[] lookups = { lookup, actionMapLookup };
    1.48 -        ProxyLookup proxy = new ProxyLookup(lookups);
    1.49 -        Lookup.Result res = proxy.lookup(new Lookup.Template(ActionMap.class));
    1.50 +        
    1.51 +        class Provider implements Lookup.Provider {
    1.52 +            ProxyLookup delegate;
    1.53 +            Lookup query;
    1.54 +            
    1.55 +            public Provider(Lookup[] arr) {
    1.56 +                if (wrapBySimple) {
    1.57 +                    delegate = new ProxyLookup(arr);
    1.58 +                    query = Lookups.proxy(this);
    1.59 +                } else {
    1.60 +                    query = delegate = new ProxyLookup(arr);
    1.61 +                }
    1.62 +            }
    1.63 +            
    1.64 +            public Lookup getLookup() {
    1.65 +                return delegate;
    1.66 +            }
    1.67 +            
    1.68 +            public void setLookups(Lookup[] arr) {
    1.69 +                if (wrapBySimple) {
    1.70 +                    delegate = new ProxyLookup(arr);                    
    1.71 +                } else {
    1.72 +                    delegate.setLookups(arr);
    1.73 +                }
    1.74 +            }
    1.75 +        }
    1.76 +        
    1.77 +        Provider p = new Provider(lookups);
    1.78 +        
    1.79 +        Lookup.Result res = p.query.lookup(new Lookup.Template(ActionMap.class));
    1.80          LL ll = new LL();
    1.81          res.addLookupListener(ll);
    1.82  
    1.83 @@ -1329,10 +1370,10 @@
    1.84          assertEquals("No change in ActionMap 2", 0, ll.getCount());
    1.85          ic.add(m2);
    1.86          assertEquals("No change in ActionMap 3", 0, ll.getCount());
    1.87 -        proxy.setLookups(new Lookup[]{ lookup, actionMapLookup, Lookup.EMPTY });
    1.88 +        p.setLookups(new Lookup[]{ lookup, actionMapLookup, Lookup.EMPTY });
    1.89          assertEquals("No change in ActionMap 4", 0, ll.getCount());
    1.90          
    1.91 -        ActionMap am2 = (ActionMap)proxy.lookup(ActionMap.class);
    1.92 +        ActionMap am2 = (ActionMap)p.query.lookup(ActionMap.class);
    1.93          assertEquals("Still the same action map", am, am2);
    1.94          
    1.95          
    1.96 @@ -1360,7 +1401,7 @@
    1.97          // adding different Before, but returning the same instance
    1.98          // this happens with metaInfServices lookup often, moreover
    1.99          // it adds the instance in beforeLookup, which confuses a lot
   1.100 -        proxy.setLookups(new Lookup[]{ lookup, new Before() });
   1.101 +        p.setLookups(new Lookup[]{ lookup, new Before() });
   1.102          assertEquals("No change in ActionMap 5", 0, ll.getCount());
   1.103          
   1.104