KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > project > ui > ProjectChooserAccessoryTest


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.modules.project.ui;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.Arrays JavaDoc;
24 import java.util.HashMap JavaDoc;
25 import java.util.HashSet JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.Set JavaDoc;
28 import javax.swing.event.ChangeListener JavaDoc;
29 import org.netbeans.api.project.Project;
30 import org.netbeans.junit.NbTestCase;
31 import org.netbeans.modules.project.ui.actions.TestSupport.ChangeableLookup;
32 import org.netbeans.spi.project.SubprojectProvider;
33 import org.openide.filesystems.FileObject;
34 import org.openide.util.Lookup;
35
36 /**
37  *
38  * @author Jan Lahoda
39  */

40 public class ProjectChooserAccessoryTest extends NbTestCase {
41     
42     public ProjectChooserAccessoryTest(String JavaDoc testName) {
43         super(testName);
44     }
45
46     protected void setUp() throws Exception JavaDoc {
47     }
48
49     /**The cycles in project dependencies should be handled gracefully:
50      */

51     public void testAddSubprojects() {
52         ChangeableLookup l1 = new ChangeableLookup();
53         ChangeableLookup l2 = new ChangeableLookup();
54         Project p1 = new TestProject(l1);
55         Project p2 = new TestProject(l2);
56         
57         Set JavaDoc<Project> subprojects1 = new HashSet JavaDoc<Project>();
58         Set JavaDoc<Project> subprojects2 = new HashSet JavaDoc<Project>();
59         
60         subprojects1.add(p2);
61         subprojects2.add(p1);
62         
63         l1.change(new SubprojectProviderImpl(subprojects1));
64         l2.change(new SubprojectProviderImpl(subprojects2));
65         
66         List JavaDoc<Project> result = new ArrayList JavaDoc<Project>();
67         
68         ProjectChooserAccessory.addSubprojects(p1, result, new HashMap JavaDoc<Project,Set JavaDoc<? extends Project>>());
69         
70         assertTrue(new HashSet JavaDoc<Project>(Arrays.asList(p1, p2)).equals(new HashSet JavaDoc<Project>(result)));
71     }
72     
73     private final class TestProject implements Project {
74         
75         private Lookup l;
76         
77         public TestProject(Lookup l) {
78             this.l = l;
79         }
80         
81         public FileObject getProjectDirectory() {
82             throw new UnsupportedOperationException JavaDoc("Should not be called in this test.");
83         }
84         
85         public Lookup getLookup() {
86             return l;
87         }
88     }
89     
90     private static final class SubprojectProviderImpl implements SubprojectProvider {
91         
92         private Set JavaDoc<Project> subprojects;
93         
94         public SubprojectProviderImpl(Set JavaDoc<Project> subprojects) {
95             this.subprojects = subprojects;
96         }
97         
98         public Set JavaDoc<? extends Project> getSubprojects() {
99             return subprojects;
100         }
101
102         public void addChangeListener(ChangeListener JavaDoc listener) {
103         }
104
105         public void removeChangeListener(ChangeListener JavaDoc listener) {
106         }
107         
108     }
109 }
110
Popular Tags