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 JDomDependencyTest {
31 private SAXBuilder builder = new SAXBuilder();
32
33 @Test(expected = UnsupportedOperationException.class)
34 public void testIsOptional() {
35 new JDomDependency(null).isOptional();
36 }
37
38 @Test(expected = UnsupportedOperationException.class)
39 public void testSetOptional() {
40 new JDomDependency(null).setOptional(true);
41 }
42
43 @Test(expected = UnsupportedOperationException.class)
44 public void testAddExclusion() {
45 new JDomDependency(null).addExclusion(null);
46 }
47
48 @Test
49 public void testGetArtifactId() throws Exception {
50 String content = "<dependency></dependency>";
51 Element dependencyElm = builder.build(new StringReader(content)).getRootElement();
52 assertNull(new JDomDependency(dependencyElm).getArtifactId());
53
54 content = "<dependency><artifactId>ARTIFACTID</artifactId></dependency>";
55 dependencyElm = builder.build(new StringReader(content)).getRootElement();
56 assertEquals("ARTIFACTID", new JDomDependency(dependencyElm).getArtifactId());
57 }
58
59 @Test(expected = UnsupportedOperationException.class)
60 public void testGetClassifier() {
61 new JDomDependency(null).getClassifier();
62 }
63
64 @Test(expected = UnsupportedOperationException.class)
65 public void testGetExclusions() {
66 new JDomDependency(null).getExclusions();
67 }
68
69 @Test
70 public void testGetGroupId() throws Exception {
71 String content = "<dependency></dependency>";
72 Element dependencyElm = builder.build(new StringReader(content)).getRootElement();
73 assertNull(new JDomDependency(dependencyElm).getGroupId());
74
75 content = "<dependency><groupId>GROUPID</groupId></dependency>";
76 dependencyElm = builder.build(new StringReader(content)).getRootElement();
77 assertEquals("GROUPID", new JDomDependency(dependencyElm).getGroupId());
78 }
79
80 @Test(expected = UnsupportedOperationException.class)
81 public void testGetScope() {
82 new JDomDependency(null).getScope();
83 }
84
85 @Test(expected = UnsupportedOperationException.class)
86 public void testGetSystemPath() {
87 new JDomDependency(null).getSystemPath();
88 }
89
90 @Test(expected = UnsupportedOperationException.class)
91 public void testGetType() {
92 new JDomDependency(null).getType();
93 }
94
95 @Test
96 public void testGetVersion() throws Exception {
97 String content = "<dependency></dependency>";
98 Element dependencyElm = builder.build(new StringReader(content)).getRootElement();
99 assertNull(new JDomDependency(dependencyElm).getVersion());
100
101 content = "<dependency><version>VERSION</version></dependency>";
102 dependencyElm = builder.build(new StringReader(content)).getRootElement();
103 assertEquals("VERSION", new JDomDependency(dependencyElm).getVersion());
104 }
105
106 @Test(expected = UnsupportedOperationException.class)
107 public void testRemoveExclusion() {
108 new JDomDependency(null).removeExclusion(null);
109 ;
110 }
111
112 @Test(expected = UnsupportedOperationException.class)
113 public void testSetArtifactIdString() {
114 new JDomDependency(null).setArtifactId(null);
115 ;
116 }
117
118 @Test(expected = UnsupportedOperationException.class)
119 public void testSetClassifierString() {
120 new JDomDependency(null).setClassifier(null);
121 ;
122 }
123
124 @Test(expected = UnsupportedOperationException.class)
125 public void testSetExclusions() {
126 new JDomDependency(null).setExclusions(null);
127 ;
128 }
129
130 @Test(expected = UnsupportedOperationException.class)
131 public void testSetGroupIdString() {
132 new JDomDependency(null).setGroupId(null);
133 }
134
135 @Test(expected = UnsupportedOperationException.class)
136 public void testSetScopeString() {
137 new JDomDependency(null).setScope(null);
138 }
139
140 @Test(expected = UnsupportedOperationException.class)
141 public void testSetSystemPathString() {
142 new JDomDependency(null).setSystemPath(null);
143 }
144
145 @Test(expected = UnsupportedOperationException.class)
146 public void testSetTypeString() {
147 new JDomDependency(null).setType(null);
148 }
149
150 @Test
151 public void testSetVersionString() throws Exception {
152 String content = "<dependency><version>OLD_VERSION</version></dependency>";
153 Element dependencyElm = builder.build(new StringReader(content)).getRootElement();
154 new JDomDependency(dependencyElm).setVersion("NEW_VERSION");
155 assertEquals("NEW_VERSION", getVersion(dependencyElm));
156 }
157
158 @Test
159 public void testGetName() {
160 assertEquals("dependency", new JDomDependency(null).getName());
161 }
162
163 private String getVersion(Element dependencyElm) {
164 return dependencyElm.getChildTextTrim("version", dependencyElm.getNamespace());
165 }
166 }