001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.eclipse.aether.internal.test.util; 020 021import java.util.List; 022 023import org.eclipse.aether.DefaultRepositorySystemSession; 024import org.eclipse.aether.RepositorySystemSession; 025import org.eclipse.aether.artifact.Artifact; 026import org.eclipse.aether.collection.DependencyCollectionContext; 027import org.eclipse.aether.collection.DependencyGraphTransformationContext; 028import org.eclipse.aether.collection.VersionFilter; 029import org.eclipse.aether.graph.Dependency; 030import org.eclipse.aether.resolution.VersionRangeResult; 031 032/** 033 * Utility methods to help unit testing. 034 */ 035public class TestUtils { 036 037 private TestUtils() { 038 // hide constructor 039 } 040 041 /** 042 * Creates a new repository session whose local repository manager is initialized with an instance of 043 * {@link TestLocalRepositoryManager}. 044 */ 045 public static DefaultRepositorySystemSession newSession() { 046 DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(); 047 session.setLocalRepositoryManager(new TestLocalRepositoryManager()); 048 return session; 049 } 050 051 /** 052 * Creates a new dependency collection context. 053 */ 054 public static DependencyCollectionContext newCollectionContext( 055 RepositorySystemSession session, Dependency dependency, List<Dependency> managedDependencies) { 056 return new TestDependencyCollectionContext(session, null, dependency, managedDependencies); 057 } 058 059 /** 060 * Creates a new dependency collection context. 061 */ 062 public static DependencyCollectionContext newCollectionContext( 063 RepositorySystemSession session, 064 Artifact artifact, 065 Dependency dependency, 066 List<Dependency> managedDependencies) { 067 return new TestDependencyCollectionContext(session, artifact, dependency, managedDependencies); 068 } 069 070 /** 071 * Creates a new dependency graph transformation context. 072 */ 073 public static DependencyGraphTransformationContext newTransformationContext(RepositorySystemSession session) { 074 return new TestDependencyGraphTransformationContext(session); 075 } 076 077 /** 078 * Creates a new version filter context from the specified session and version range result. 079 */ 080 public static VersionFilter.VersionFilterContext newVersionFilterContext( 081 RepositorySystemSession session, VersionRangeResult rangeResult) { 082 return new TestVersionFilterContext(session, rangeResult); 083 } 084}