View Javadoc
1   package org.eclipse.aether.internal.test.util;
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 java.util.List;
23  
24  import org.eclipse.aether.DefaultRepositorySystemSession;
25  import org.eclipse.aether.RepositorySystemSession;
26  import org.eclipse.aether.artifact.Artifact;
27  import org.eclipse.aether.collection.DependencyCollectionContext;
28  import org.eclipse.aether.collection.DependencyGraphTransformationContext;
29  import org.eclipse.aether.collection.VersionFilter;
30  import org.eclipse.aether.graph.Dependency;
31  import org.eclipse.aether.resolution.VersionRangeResult;
32  
33  /**
34   * Utility methods to help unit testing.
35   */
36  public class TestUtils
37  {
38  
39      private TestUtils()
40      {
41          // hide constructor
42      }
43  
44      /**
45       * Creates a new repository session whose local repository manager is initialized with an instance of
46       * {@link TestLocalRepositoryManager}.
47       */
48      public static DefaultRepositorySystemSession newSession()
49      {
50          DefaultRepositorySystemSession session = new DefaultRepositorySystemSession();
51          session.setLocalRepositoryManager( new TestLocalRepositoryManager() );
52          return session;
53      }
54  
55      /**
56       * Creates a new dependency collection context.
57       */
58      public static DependencyCollectionContext newCollectionContext( RepositorySystemSession session,
59                                                                      Dependency dependency,
60                                                                      List<Dependency> managedDependencies )
61      {
62          return new TestDependencyCollectionContext( session, null, dependency, managedDependencies );
63      }
64  
65      /**
66       * Creates a new dependency collection context.
67       */
68      public static DependencyCollectionContext newCollectionContext( RepositorySystemSession session, Artifact artifact,
69                                                                      Dependency dependency,
70                                                                      List<Dependency> managedDependencies )
71      {
72          return new TestDependencyCollectionContext( session, artifact, dependency, managedDependencies );
73      }
74  
75      /**
76       * Creates a new dependency graph transformation context.
77       */
78      public static DependencyGraphTransformationContext newTransformationContext( RepositorySystemSession session )
79      {
80          return new TestDependencyGraphTransformationContext( session );
81      }
82  
83      /**
84       * Creates a new version filter context from the specified session and version range result.
85       */
86      public static VersionFilter.VersionFilterContext newVersionFilterContext( RepositorySystemSession session,
87                                                                                VersionRangeResult rangeResult )
88      {
89          return new TestVersionFilterContext( session, rangeResult );
90      }
91  
92  }