KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > spi > project > support > ant > FilterPropertyProviderTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.spi.project.support.ant;
21
22 import java.lang.ref.Reference JavaDoc;
23 import java.lang.ref.WeakReference JavaDoc;
24 import java.util.Collections JavaDoc;
25 import java.util.HashMap JavaDoc;
26 import org.netbeans.junit.NbTestCase;
27
28 /**
29  * @author Jesse Glick
30  */

31 public class FilterPropertyProviderTest extends NbTestCase {
32
33     public FilterPropertyProviderTest(String JavaDoc name) {
34         super(name);
35     }
36
37     public void testDelegatingPropertyProvider() throws Exception JavaDoc {
38         AntBasedTestUtil.TestMutablePropertyProvider mpp = new AntBasedTestUtil.TestMutablePropertyProvider(new HashMap JavaDoc<String JavaDoc,String JavaDoc>());
39         DPP dpp = new DPP(mpp);
40         AntBasedTestUtil.TestCL l = new AntBasedTestUtil.TestCL();
41         dpp.addChangeListener(l);
42         assertEquals("initially empty", Collections.emptyMap(), dpp.getProperties());
43         mpp.defs.put("foo", "bar");
44         mpp.mutated();
45         assertTrue("got a change", l.expect());
46         assertEquals("now right contents", Collections.singletonMap("foo", "bar"), dpp.getProperties());
47         AntBasedTestUtil.TestMutablePropertyProvider mpp2 = new AntBasedTestUtil.TestMutablePropertyProvider(new HashMap JavaDoc<String JavaDoc,String JavaDoc>());
48         mpp2.defs.put("foo", "bar2");
49         dpp.setDelegate_(mpp2);
50         assertTrue("got a change from new delegate", l.expect());
51         assertEquals("right contents from new delegate", Collections.singletonMap("foo", "bar2"), dpp.getProperties());
52         mpp2.defs.put("foo", "bar3");
53         mpp2.mutated();
54         assertTrue("got a change in new delegate", l.expect());
55         assertEquals("right contents", Collections.singletonMap("foo", "bar3"), dpp.getProperties());
56         Reference JavaDoc<?> r = new WeakReference JavaDoc<Object JavaDoc>(mpp);
57         mpp = null;
58         assertGC("old delegates can be collected", r);
59         r = new WeakReference JavaDoc<Object JavaDoc>(dpp);
60         dpp = null; // but not mpp2
61
assertGC("delegating PP can be collected when delegate is not", r); // #50572
62
}
63
64     private static final class DPP extends FilterPropertyProvider {
65         public DPP(PropertyProvider pp) {
66             super(pp);
67         }
68         public void setDelegate_(PropertyProvider pp) {
69             setDelegate(pp);
70         }
71     }
72
73 }
74
Popular Tags