001package org.eclipse.aether.util.graph.manager; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import static org.junit.Assert.*; 023 024import java.util.Arrays; 025 026import org.eclipse.aether.RepositorySystemSession; 027import org.eclipse.aether.artifact.Artifact; 028import org.eclipse.aether.artifact.DefaultArtifact; 029import org.eclipse.aether.collection.DependencyCollectionContext; 030import org.eclipse.aether.collection.DependencyManagement; 031import org.eclipse.aether.collection.DependencyManager; 032import org.eclipse.aether.graph.Dependency; 033import org.eclipse.aether.internal.test.util.TestUtils; 034import org.junit.Before; 035import org.junit.Test; 036 037public class ClassicDependencyManagerTest 038{ 039 040 private final Artifact A = new DefaultArtifact( "test", "a", "", "" ); 041 042 private final Artifact A1 = new DefaultArtifact( "test", "a", "", "1" ); 043 044 private final Artifact B = new DefaultArtifact( "test", "b", "", "" ); 045 046 private final Artifact B1 = new DefaultArtifact( "test", "b", "", "1" ); 047 048 private RepositorySystemSession session; 049 050 private DependencyCollectionContext newContext( Dependency... managedDependencies ) 051 { 052 return TestUtils.newCollectionContext( session, null, Arrays.asList( managedDependencies ) ); 053 } 054 055 @Before 056 public void setUp() 057 { 058 session = TestUtils.newSession(); 059 } 060 061 @Test 062 public void testManageOptional() 063 { 064 DependencyManager manager = new ClassicDependencyManager(); 065 066 manager = 067 manager.deriveChildManager( newContext( new Dependency( A, null, null ), new Dependency( B, null, true ) ) ); 068 DependencyManagement mngt; 069 mngt = manager.manageDependency( new Dependency( A1, null ) ); 070 assertNull( mngt ); 071 mngt = manager.manageDependency( new Dependency( B1, null ) ); 072 assertNull( mngt ); 073 074 manager = manager.deriveChildManager( newContext() ); 075 mngt = manager.manageDependency( new Dependency( A1, null ) ); 076 assertNull( mngt ); 077 mngt = manager.manageDependency( new Dependency( B1, null ) ); 078 assertNotNull( mngt ); 079 assertEquals( Boolean.TRUE, mngt.getOptional() ); 080 } 081 082}