Skip to content

Commit 25e9524

Browse files
committed
POMTest: beef up the tests
Now we check all the currently existing accessors, as well as the cdata, xpath and elements methods inherited from XML.
1 parent 7a22aca commit 25e9524

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

src/test/java/org/scijava/util/POMTest.java

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,20 @@
3131

3232
package org.scijava.util;
3333

34+
import static org.junit.Assert.assertEquals;
35+
import static org.junit.Assert.assertNotNull;
36+
import static org.junit.Assert.assertNull;
3437
import static org.junit.Assert.assertTrue;
3538

39+
import java.io.File;
40+
import java.io.IOException;
41+
import java.util.ArrayList;
42+
43+
import javax.xml.parsers.ParserConfigurationException;
44+
3645
import org.junit.Test;
46+
import org.w3c.dom.Element;
47+
import org.xml.sax.SAXException;
3748

3849
/**
3950
* Tests methods of {@link POM}.
@@ -73,4 +84,63 @@ public void testCompareVersions() {
7384
assertTrue(POM.compareVersions("2.0.0", "2.0.0-beta-1") > 0);
7485
}
7586

87+
@Test
88+
public void testAccessors() throws ParserConfigurationException,
89+
SAXException, IOException
90+
{
91+
final POM pom = new POM(new File("pom.xml"));
92+
assertEquals("org.scijava", pom.getParentGroupId());
93+
assertEquals("pom-scijava", pom.getParentArtifactId());
94+
assertNotNull(pom.getParentVersion());
95+
assertEquals("org.scijava", pom.getGroupId());
96+
assertEquals("scijava-common", pom.getArtifactId());
97+
assertNotNull(pom.getVersion());
98+
assertEquals("Jenkins", pom.getCIManagementSystem());
99+
final String ciManagementURL = pom.getCIManagementURL();
100+
assertEquals("http://jenkins.imagej.net/job/SciJava-common/",
101+
ciManagementURL);
102+
assertEquals("GitHub Issues", pom.getIssueManagementSystem());
103+
final String issueManagementURL = pom.getIssueManagementURL();
104+
assertEquals("https://github.com/scijava/scijava-common/issues",
105+
issueManagementURL);
106+
assertNull(pom.getOrganizationName());
107+
assertNull(pom.getOrganizationURL());
108+
assertTrue(pom.getPath().endsWith("pom.xml"));
109+
assertTrue(pom.getProjectDescription().startsWith(
110+
"SciJava Common is a shared library for SciJava software."));
111+
assertEquals("2009", pom.getProjectInceptionYear());
112+
assertEquals("SciJava Common", pom.getProjectName());
113+
assertEquals("http://scijava.org/", pom.getProjectURL());
114+
final String scmConnection = pom.getSCMConnection();
115+
assertEquals("scm:git:git://github.com/scijava/scijava-common",
116+
scmConnection);
117+
final String scmDeveloperConnection = pom.getSCMDeveloperConnection();
118+
assertEquals("scm:git:git@github.com:scijava/scijava-common",
119+
scmDeveloperConnection);
120+
assertNotNull(pom.getSCMTag()); // won't be HEAD for release tags
121+
assertEquals("https://github.com/scijava/scijava-common", pom.getSCMURL());
122+
}
123+
124+
@Test
125+
public void testCdata() throws ParserConfigurationException,
126+
SAXException, IOException
127+
{
128+
final POM pom = new POM(new File("pom.xml"));
129+
assertEquals("repo", pom.cdata("//project/licenses/license/distribution"));
130+
assertEquals("http://scijava.org/", pom.cdata("//project/url"));
131+
}
132+
133+
@Test
134+
public void testElements() throws ParserConfigurationException,
135+
SAXException, IOException
136+
{
137+
final POM pom = new POM(new File("pom.xml"));
138+
final ArrayList<Element> developers =
139+
pom.elements("//project/developers/developer");
140+
assertEquals(3, developers.size());
141+
assertEquals("ctrueden", XML.cdata(developers.get(0), "id"));
142+
assertEquals("dscho", XML.cdata(developers.get(1), "id"));
143+
assertEquals("hinerm", XML.cdata(developers.get(2), "id"));
144+
}
145+
76146
}

0 commit comments

Comments
 (0)