1 19 20 package org.netbeans.modules.apisupport.project.universe; 21 22 import org.netbeans.api.project.ProjectManager; 23 import org.netbeans.modules.apisupport.project.NbModuleProject; 24 import org.netbeans.modules.apisupport.project.TestBase; 25 import org.openide.filesystems.FileObject; 26 27 28 32 public class TestModuleDependencyTest extends TestBase { 33 34 private final static String ANT_PROJECT_SUPPORT = "org.netbeans.modules.project.ant"; 35 private final static String DIALOGS = "org.openide.dialogs"; 36 private TestModuleDependency tdJP_001; 37 private TestModuleDependency tdJP_101; 38 private TestModuleDependency tdJP_101otherInstance; 39 private TestModuleDependency tdAnt_111; 40 41 public TestModuleDependencyTest(String testName) { 42 super(testName); 43 } 44 45 protected void setUp() throws Exception { 46 clearWorkDir(); 47 super.setUp(); 48 final NbModuleProject testingProject = generateTestingProject(); 49 final String cnb = "org.netbeans.modules.java.project"; 50 final String cnb2 = "org.netbeans.modules.project.ant"; 51 ModuleEntry meJP = testingProject.getModuleList().getEntry(cnb); 52 ModuleEntry meAnt = testingProject.getModuleList().getEntry(cnb2); 53 tdJP_001 = new TestModuleDependency(meJP, false, false, true); 54 tdJP_101 = new TestModuleDependency(meJP, true, false, true); 55 tdJP_101otherInstance = new TestModuleDependency(meJP, true, false, true); 56 tdAnt_111 = new TestModuleDependency(meAnt, true, true, true); 57 } 58 59 60 public void testEquals() throws Exception { 61 assertFalse("001!=101" , tdJP_001.equals((TestModuleDependency)tdJP_101)); 62 assertTrue("these are equal", tdJP_101.equals((TestModuleDependency)tdJP_101otherInstance)); 63 assertFalse(tdAnt_111.equals(null)); 64 assertFalse(tdAnt_111.equals("")); 65 } 66 67 public void testCompareTo() { 68 assertEquals("equals", 0, tdJP_101.compareTo((TestModuleDependency) tdJP_101otherInstance)); 69 assertTrue("o.n.m.java.project < o.n.m.project.ant", tdJP_001.compareTo(tdAnt_111) < 0); 70 assertTrue("o.n.m.project.ant > o.n.m.java.project", tdAnt_111.compareTo(tdJP_101) > 0); 71 } 72 73 public void testHashCode() { 74 assertEquals("the same hashcodes", tdJP_101.hashCode(),tdJP_101otherInstance.hashCode()); 75 assertTrue("the same hashcodes", tdJP_101.hashCode() == tdJP_001.hashCode()); 76 assertTrue("different hashcodes", tdJP_101.hashCode() != tdAnt_111.hashCode()); 77 } 78 79 private NbModuleProject generateTestingProject() throws Exception { 80 FileObject fo = TestBase.generateStandaloneModuleDirectory(getWorkDir(), "testing"); 81 FileObject projectXMLFO = fo.getFileObject("nbproject/project.xml"); 82 String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + 83 "<project xmlns=\"http://www.netbeans.org/ns/project/1\">\n" + 84 "<type>org.netbeans.modules.apisupport.project</type>\n" + 85 "<configuration>\n" + 86 "<data xmlns=\"http://www.netbeans.org/ns/nb-module-project/3\">\n" + 87 "<code-name-base>org.example.testing</code-name-base>\n" + 88 "<standalone/>\n" + 89 "<module-dependencies>\n" + 90 "<dependency>\n" + 91 "<code-name-base>" + DIALOGS + "</code-name-base>\n" + 92 "<build-prerequisite/>\n" + 93 "<compile-dependency/>\n" + 94 "<run-dependency>\n" + 95 "<specification-version>6.2</specification-version>\n" + 96 "</run-dependency>\n" + 97 "</dependency>\n" + 98 "<dependency>\n" + 99 "<code-name-base>" + ANT_PROJECT_SUPPORT + "</code-name-base>\n" + 100 "<build-prerequisite/>\n" + 101 "<compile-dependency/>\n" + 102 "<run-dependency>\n" + 103 "<release-version>1</release-version>\n" + 104 "<specification-version>1.10</specification-version>\n" + 105 "</run-dependency>\n" + 106 "</dependency>\n" + 107 "</module-dependencies>\n" + 108 "<test-dependencies/>\n" + 109 "<friend-packages>\n" + 110 "<friend>org.module.examplemodule</friend>\n" + 111 "<package>org.netbeans.examples.modules.misc</package>\n" + 112 "</friend-packages>\n" + 113 "<class-path-extension>\n" + 114 "<runtime-relative-path>ext/jsr88javax.jar</runtime-relative-path>\n" + 115 "<binary-origin>../external/jsr88javax.jar</binary-origin>\n" + 116 "</class-path-extension>\n" + 117 "</data>\n" + 118 "</configuration>\n" + 119 "</project>\n"; 120 TestBase.dump(projectXMLFO, xml); 121 return (NbModuleProject) ProjectManager.getDefault().findProject(fo); 122 } 123 124 125 } 126 | Popular Tags |