View Javadoc
1   package org.eclipse.aether.graph;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   * 
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   * 
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import static org.junit.Assert.*;
23  
24  import java.util.Arrays;
25  import java.util.Collections;
26  
27  import org.eclipse.aether.artifact.DefaultArtifact;
28  import org.eclipse.aether.graph.Dependency;
29  import org.eclipse.aether.graph.Exclusion;
30  import org.junit.Test;
31  
32  /**
33   */
34  public class DependencyTest
35  {
36  
37      @Test
38      public void testSetScope()
39      {
40          Dependency d1 = new Dependency( new DefaultArtifact( "gid:aid:ver" ), "compile" );
41  
42          Dependency d2 = d1.setScope( null );
43          assertNotSame( d2, d1 );
44          assertEquals( "", d2.getScope() );
45  
46          Dependency d3 = d1.setScope( "test" );
47          assertNotSame( d3, d1 );
48          assertEquals( "test", d3.getScope() );
49      }
50  
51      @Test
52      public void testSetExclusions()
53      {
54          Dependency d1 =
55              new Dependency( new DefaultArtifact( "gid:aid:ver" ), "compile", false,
56                              Collections.singleton( new Exclusion( "g", "a", "c", "e" ) ) );
57  
58          Dependency d2 = d1.setExclusions( null );
59          assertNotSame( d2, d1 );
60          assertEquals( 0, d2.getExclusions().size() );
61  
62          assertSame( d2, d2.setExclusions( null ) );
63          assertSame( d2, d2.setExclusions( Collections.<Exclusion> emptyList() ) );
64          assertSame( d2, d2.setExclusions( Collections.<Exclusion> emptySet() ) );
65          assertSame( d1, d1.setExclusions( Arrays.asList( new Exclusion( "g", "a", "c", "e" ) ) ) );
66  
67          Dependency d3 =
68              d1.setExclusions( Arrays.asList( new Exclusion( "g", "a", "c", "e" ), new Exclusion( "g", "a", "c", "f" ) ) );
69          assertNotSame( d3, d1 );
70          assertEquals( 2, d3.getExclusions().size() );
71      }
72  
73  }