001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.project.ui;
043:
044: import java.util.ArrayList;
045: import java.util.Arrays;
046: import java.util.HashMap;
047: import java.util.HashSet;
048: import java.util.List;
049: import java.util.Set;
050: import javax.swing.JFileChooser;
051: import javax.swing.event.ChangeListener;
052: import org.netbeans.api.project.Project;
053: import org.netbeans.junit.NbTestCase;
054: import org.netbeans.modules.project.ui.actions.TestSupport.ChangeableLookup;
055: import org.netbeans.spi.project.SubprojectProvider;
056: import org.openide.filesystems.FileObject;
057: import org.openide.util.Lookup;
058:
059: /**
060: *
061: * @author Jan Lahoda
062: */
063: public class ProjectChooserAccessoryTest extends NbTestCase {
064:
065: public ProjectChooserAccessoryTest(String testName) {
066: super (testName);
067: }
068:
069: protected void setUp() throws Exception {
070: }
071:
072: /**The cycles in project dependencies should be handled gracefully:
073: */
074: public void testAddSubprojects() {
075: ChangeableLookup l1 = new ChangeableLookup();
076: ChangeableLookup l2 = new ChangeableLookup();
077: Project p1 = new TestProject(l1);
078: Project p2 = new TestProject(l2);
079:
080: Set<Project> subprojects1 = new HashSet<Project>();
081: Set<Project> subprojects2 = new HashSet<Project>();
082:
083: subprojects1.add(p2);
084: subprojects2.add(p1);
085:
086: l1.change(new SubprojectProviderImpl(subprojects1));
087: l2.change(new SubprojectProviderImpl(subprojects2));
088:
089: List<Project> result = new ArrayList<Project>();
090: //#101227
091: ProjectChooserAccessory acc = new ProjectChooserAccessory(
092: new JFileChooser(), false, false);
093: acc.modelUpdater.addSubprojects(p1, result,
094: new HashMap<Project, Set<? extends Project>>());
095:
096: assertTrue(new HashSet<Project>(Arrays.asList(p1, p2))
097: .equals(new HashSet<Project>(result)));
098: }
099:
100: private final class TestProject implements Project {
101:
102: private Lookup l;
103:
104: public TestProject(Lookup l) {
105: this .l = l;
106: }
107:
108: public FileObject getProjectDirectory() {
109: throw new UnsupportedOperationException(
110: "Should not be called in this test.");
111: }
112:
113: public Lookup getLookup() {
114: return l;
115: }
116: }
117:
118: private static final class SubprojectProviderImpl implements
119: SubprojectProvider {
120:
121: private Set<Project> subprojects;
122:
123: public SubprojectProviderImpl(Set<Project> subprojects) {
124: this .subprojects = subprojects;
125: }
126:
127: public Set<? extends Project> getSubprojects() {
128: return subprojects;
129: }
130:
131: public void addChangeListener(ChangeListener listener) {
132: }
133:
134: public void removeChangeListener(ChangeListener listener) {
135: }
136:
137: }
138: }
|