1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.shared.release.transform.jdom2;
20
21 import java.io.StringReader;
22
23 import org.jdom2.Element;
24 import org.jdom2.input.SAXBuilder;
25 import org.junit.Test;
26
27 import static org.junit.Assert.assertEquals;
28 import static org.junit.Assert.assertNull;
29
30 public class JDomScmTest {
31 private SAXBuilder builder = new SAXBuilder();
32
33 @Test(expected = UnsupportedOperationException.class)
34 public void testGetConnection() {
35 new JDomScm(null).getConnection();
36 }
37
38 @Test(expected = UnsupportedOperationException.class)
39 public void testGetDeveloperConnection() {
40 new JDomScm(null).getDeveloperConnection();
41 }
42
43 @Test(expected = UnsupportedOperationException.class)
44 public void testGetTag() {
45 new JDomScm(null).getTag();
46 }
47
48 @Test(expected = UnsupportedOperationException.class)
49 public void testGetUrl() {
50 new JDomScm(null).getUrl();
51 }
52
53 @Test
54 public void testSetConnectionString() throws Exception {
55 String content = "<scm></scm>";
56 Element scmElm = builder.build(new StringReader(content)).getRootElement();
57
58 assertNull(getConnection(scmElm));
59
60 new JDomScm(scmElm).setConnection("CONNECTION");
61 assertEquals("CONNECTION", getConnection(scmElm));
62
63 new JDomScm(scmElm).setConnection(null);
64 assertNull(getConnection(scmElm));
65 }
66
67 @Test
68 public void testSetDeveloperConnectionString() throws Exception {
69 String content = "<scm></scm>";
70 Element scmElm = builder.build(new StringReader(content)).getRootElement();
71
72 assertNull(getDeveloperConnection(scmElm));
73
74 new JDomScm(scmElm).setDeveloperConnection("DEVELOPERCONNECTION");
75 assertEquals("DEVELOPERCONNECTION", getDeveloperConnection(scmElm));
76
77 new JDomScm(scmElm).setDeveloperConnection(null);
78 assertNull(getDeveloperConnection(scmElm));
79 }
80
81 @Test
82 public void testSetTagString() throws Exception {
83 String content = "<scm></scm>";
84 Element scmElm = builder.build(new StringReader(content)).getRootElement();
85
86 assertNull(getUrl(scmElm));
87
88 new JDomScm(scmElm).setUrl("URL");
89 assertEquals("URL", getUrl(scmElm));
90
91 new JDomScm(scmElm).setUrl(null);
92 assertNull(getUrl(scmElm));
93 }
94
95 @Test
96 public void testSetUrlString() throws Exception {
97 String content = "<scm></scm>";
98 Element scmElm = builder.build(new StringReader(content)).getRootElement();
99
100 assertNull(getTag(scmElm));
101
102 new JDomScm(scmElm).setTag("TAG");
103 assertEquals("TAG", getTag(scmElm));
104
105 new JDomScm(scmElm).setTag(null);
106 assertNull(getTag(scmElm));
107 }
108
109 private String getConnection(Element scmElm) {
110 return scmElm.getChildText("connection", scmElm.getNamespace());
111 }
112
113 private String getDeveloperConnection(Element scmElm) {
114 return scmElm.getChildText("developerConnection", scmElm.getNamespace());
115 }
116
117 private String getTag(Element scmElm) {
118 return scmElm.getChildText("tag", scmElm.getNamespace());
119 }
120
121 private String getUrl(Element scmElm) {
122 return scmElm.getChildText("url", scmElm.getNamespace());
123 }
124 }