1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/openide.util/test/unit/src/org/openide/util/lookup/ProxyLookupEventIssue136866Test.java Tue Jun 17 13:34:54 2008 +0200
1.3 @@ -0,0 +1,56 @@
1.4 +package org.openide.util.lookup;
1.5 +
1.6 +import junit.framework.TestCase;
1.7 +import org.openide.util.Lookup;
1.8 +import org.openide.util.LookupEvent;
1.9 +import org.openide.util.LookupListener;
1.10 +
1.11 +/**
1.12 + * Test case which demonstrates that ProxyLookup does not fire
1.13 + * an event when it should.
1.14 + */
1.15 +public class ProxyLookupEventIssue136866Test extends TestCase {
1.16 +
1.17 + public ProxyLookupEventIssue136866Test(String testName) {
1.18 + super(testName);
1.19 + }
1.20 +
1.21 + public void testAbstractLookupFiresEventWhenContentChanged() {
1.22 + InstanceContent ic = new InstanceContent();
1.23 + AbstractLookup al = new AbstractLookup(ic);
1.24 +
1.25 + final int[] counts = {0}; // Number of items observed upon a LookupEvent
1.26 + final Lookup.Result<String> result = al.lookupResult(String.class);
1.27 +
1.28 + result.addLookupListener(new LookupListener() {
1.29 + public void resultChanged(LookupEvent ev) {
1.30 + // this gets called as expected
1.31 + assertSame(result, ev.getSource());
1.32 + counts[0] = result.allInstances().size();
1.33 + }
1.34 + });
1.35 +
1.36 + ic.add("hello1");
1.37 + assertEquals(1, counts[0]);
1.38 + }
1.39 +
1.40 + public void testProxyLookupFailsToFireEventWhenProxiedLookupChanged() {
1.41 + InstanceContent ic = new InstanceContent();
1.42 +// AbstractLookup al = new AbstractLookup(ic);
1.43 + Lookup proxy = new AbstractLookup(ic);
1.44 +
1.45 + final int[] counts = {0}; // Number of items observed upon a LookupEvent
1.46 + final Lookup.Result<String> result = proxy.lookupResult(String.class);
1.47 +
1.48 + result.addLookupListener(new LookupListener() {
1.49 + public void resultChanged(LookupEvent ev) {
1.50 + // this should be called but never is
1.51 + assertSame(result, ev.getSource());
1.52 + counts[0] = result.allInstances().size();
1.53 + }
1.54 + });
1.55 +
1.56 + ic.add("hello1");
1.57 + assertEquals(1, counts[0]);
1.58 + }
1.59 +}