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