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.eclipse.aether.graph;
20  
21  import java.util.Arrays;
22  import java.util.Collections;
23  
24  import org.eclipse.aether.artifact.DefaultArtifact;
25  import org.junit.Test;
26  
27  import static org.junit.Assert.*;
28  
29  /**
30   */
31  public class DependencyTest {
32  
33      @Test
34      public void testSetScope() {
35          Dependency d1 = new Dependency(new DefaultArtifact("gid:aid:ver"), "compile");
36  
37          Dependency d2 = d1.setScope(null);
38          assertNotSame(d2, d1);
39          assertEquals("", d2.getScope());
40  
41          Dependency d3 = d1.setScope("test");
42          assertNotSame(d3, d1);
43          assertEquals("test", d3.getScope());
44      }
45  
46      @Test
47      public void testSetExclusions() {
48          Dependency d1 = new Dependency(
49                  new DefaultArtifact("gid:aid:ver"),
50                  "compile",
51                  false,
52                  Collections.singleton(new Exclusion("g", "a", "c", "e")));
53  
54          Dependency d2 = d1.setExclusions(null);
55          assertNotSame(d2, d1);
56          assertEquals(0, d2.getExclusions().size());
57  
58          assertSame(d2, d2.setExclusions(null));
59          assertSame(d2, d2.setExclusions(Collections.<Exclusion>emptyList()));
60          assertSame(d2, d2.setExclusions(Collections.<Exclusion>emptySet()));
61          assertSame(d1, d1.setExclusions(Arrays.asList(new Exclusion("g", "a", "c", "e"))));
62  
63          Dependency d3 =
64                  d1.setExclusions(Arrays.asList(new Exclusion("g", "a", "c", "e"), new Exclusion("g", "a", "c", "f")));
65          assertNotSame(d3, d1);
66          assertEquals(2, d3.getExclusions().size());
67      }
68  }