Trying to mimic a failure with duplicated delegates in setLookups unified_caches_root
authorjtulach@netbeans.org
Thu, 24 Jan 2008 09:05:17 +0000
changeset 3228fb23eaf14a8
parent 321 f7f1a24b280a
child 323 8015071dc7a2
Trying to mimic a failure with duplicated delegates in setLookups
openide.util/test/unit/src/org/openide/util/lookup/ProxyLookupTest.java
     1.1 --- a/openide.util/test/unit/src/org/openide/util/lookup/ProxyLookupTest.java	Mon Jan 21 12:13:41 2008 +0000
     1.2 +++ b/openide.util/test/unit/src/org/openide/util/lookup/ProxyLookupTest.java	Thu Jan 24 09:05:17 2008 +0000
     1.3 @@ -531,4 +531,47 @@
     1.4          
     1.5          pl.setLookups(new L("X"), new L("Y"), new L("Z"));
     1.6      }
     1.7 +    
     1.8 +    public void testDuplicatedLookupArrayIndexWithSetLookupAsInIssue123679() throws Exception {
     1.9 +        final ProxyLookup pl = new ProxyLookup();
    1.10 +        final int[] cnt = { 0 };
    1.11 +        
    1.12 +        class L extends Lookup {
    1.13 +            L[] set;
    1.14 +            Lookup l;
    1.15 +            Collection<? extends Serializable> res;
    1.16 +            
    1.17 +            public L(String s) {
    1.18 +                l = Lookups.singleton(s);
    1.19 +            }
    1.20 +            
    1.21 +            @Override
    1.22 +            public <T> T lookup(Class<T> clazz) {
    1.23 +                return l.lookup(clazz);
    1.24 +            }
    1.25 +
    1.26 +            @Override
    1.27 +            public <T> Result<T> lookup(Template<T> template) {
    1.28 +                cnt[0]++;
    1.29 +                if (set != null) {
    1.30 +                    pl.setLookups(set);
    1.31 +                    res = pl.lookupAll(Serializable.class);
    1.32 +                }
    1.33 +                Result<T> r = l.lookup(template);
    1.34 +                return r;
    1.35 +            }
    1.36 +        }
    1.37 +
    1.38 +        L dupl = new L("A");
    1.39 +        L[] now = { dupl };
    1.40 +        L[] old = { new L("C") };
    1.41 +        pl.setLookups(old);
    1.42 +        old[0].set = now;
    1.43 +        
    1.44 +        Result<String> res = pl.lookupResult(String.class);
    1.45 +        assertEquals("New items visible", 1, res.allItems().size());
    1.46 +        
    1.47 +        
    1.48 +        pl.setLookups(old);
    1.49 +    }
    1.50  }