View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.shared.release.transform.jdom2;
20  
21  import java.io.StringReader;
22  
23  import org.jdom2.Document;
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.assertNotNull;
29  
30  public class JDomDependencyManagementTest {
31      private SAXBuilder builder = new SAXBuilder();
32  
33      @Test
34      public void testGetDependencies() throws Exception {
35          String content = "<dependencyManamgement></dependencyManamgement>";
36          Document document = builder.build(new StringReader(content));
37          assertNotNull(new JDomDependencyManagement(document.getRootElement()).getDependencies());
38          assertEquals(
39                  0,
40                  new JDomDependencyManagement(document.getRootElement())
41                          .getDependencies()
42                          .size());
43  
44          content = "<dependencyManamgement><dependencies/></dependencyManamgement>";
45          document = builder.build(new StringReader(content));
46          assertEquals(
47                  0,
48                  new JDomDependencyManagement(document.getRootElement())
49                          .getDependencies()
50                          .size());
51  
52          content = "<dependencyManamgement><dependencies><dependency/></dependencies></dependencyManamgement>";
53          document = builder.build(new StringReader(content));
54          assertEquals(
55                  1,
56                  new JDomDependencyManagement(document.getRootElement())
57                          .getDependencies()
58                          .size());
59      }
60  
61      // All other methods throw UnsupportedOperationException
62  
63      @Test(expected = UnsupportedOperationException.class)
64      public void testAddDependency() {
65          new JDomDependencyManagement(null).addDependency(null);
66      }
67  
68      @Test(expected = UnsupportedOperationException.class)
69      public void testRemoveDependency() {
70          new JDomDependencyManagement(null).addDependency(null);
71      }
72  
73      @Test(expected = UnsupportedOperationException.class)
74      public void testSetDependenciesListOfDependency() {
75          new JDomDependencyManagement(null).setDependencies(null);
76      }
77  }