1 19 20 package org.netbeans.modules.project.ui; 21 22 import java.util.ArrayList ; 23 import java.util.Arrays ; 24 import java.util.HashMap ; 25 import java.util.HashSet ; 26 import java.util.List ; 27 import java.util.Set ; 28 import javax.swing.event.ChangeListener ; 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 40 public class ProjectChooserAccessoryTest extends NbTestCase { 41 42 public ProjectChooserAccessoryTest(String testName) { 43 super(testName); 44 } 45 46 protected void setUp() throws Exception { 47 } 48 49 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 <Project> subprojects1 = new HashSet <Project>(); 58 Set <Project> subprojects2 = new HashSet <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 <Project> result = new ArrayList <Project>(); 67 68 ProjectChooserAccessory.addSubprojects(p1, result, new HashMap <Project,Set <? extends Project>>()); 69 70 assertTrue(new HashSet <Project>(Arrays.asList(p1, p2)).equals(new HashSet <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 ("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 <Project> subprojects; 93 94 public SubprojectProviderImpl(Set <Project> subprojects) { 95 this.subprojects = subprojects; 96 } 97 98 public Set <? extends Project> getSubprojects() { 99 return subprojects; 100 } 101 102 public void addChangeListener(ChangeListener listener) { 103 } 104 105 public void removeChangeListener(ChangeListener listener) { 106 } 107 108 } 109 } 110 | Popular Tags |