View Javadoc
1   package org.eclipse.aether.util.graph.manager;
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  
26  import org.eclipse.aether.RepositorySystemSession;
27  import org.eclipse.aether.artifact.Artifact;
28  import org.eclipse.aether.artifact.DefaultArtifact;
29  import org.eclipse.aether.collection.DependencyCollectionContext;
30  import org.eclipse.aether.collection.DependencyManagement;
31  import org.eclipse.aether.collection.DependencyManager;
32  import org.eclipse.aether.graph.Dependency;
33  import org.eclipse.aether.internal.test.util.TestUtils;
34  import org.junit.Before;
35  import org.junit.Test;
36  
37  public class ClassicDependencyManagerTest
38  {
39  
40      private final Artifact A = new DefaultArtifact( "test", "a", "", "" );
41  
42      private final Artifact A1 = new DefaultArtifact( "test", "a", "", "1" );
43  
44      private final Artifact B = new DefaultArtifact( "test", "b", "", "" );
45  
46      private final Artifact B1 = new DefaultArtifact( "test", "b", "", "1" );
47  
48      private RepositorySystemSession session;
49  
50      private DependencyCollectionContext newContext( Dependency... managedDependencies )
51      {
52          return TestUtils.newCollectionContext( session, null, Arrays.asList( managedDependencies ) );
53      }
54  
55      @Before
56      public void setUp()
57      {
58          session = TestUtils.newSession();
59      }
60  
61      @Test
62      public void testManageOptional()
63      {
64          DependencyManager manager = new ClassicDependencyManager();
65  
66          manager =
67              manager.deriveChildManager( newContext( new Dependency( A, null, null ), new Dependency( B, null, true ) ) );
68          DependencyManagement mngt;
69          mngt = manager.manageDependency( new Dependency( A1, null ) );
70          assertNull( mngt );
71          mngt = manager.manageDependency( new Dependency( B1, null ) );
72          assertNull( mngt );
73  
74          manager = manager.deriveChildManager( newContext() );
75          mngt = manager.manageDependency( new Dependency( A1, null ) );
76          assertNull( mngt );
77          mngt = manager.manageDependency( new Dependency( B1, null ) );
78          assertNotNull( mngt );
79          assertEquals( Boolean.TRUE, mngt.getOptional() );
80      }
81  
82  }