001package org.eclipse.aether.util.graph.transformer; 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 org.eclipse.aether.collection.DependencyGraphTransformer; 025import org.eclipse.aether.graph.DependencyNode; 026import org.eclipse.aether.internal.test.util.DependencyGraphParser; 027import org.junit.Test; 028 029public class SimpleOptionalitySelectorTest 030 extends AbstractDependencyGraphTransformerTest 031{ 032 033 @Override 034 protected DependencyGraphTransformer newTransformer() 035 { 036 return new ConflictResolver( new NearestVersionSelector(), new JavaScopeSelector(), 037 new SimpleOptionalitySelector(), new JavaScopeDeriver() ); 038 } 039 040 @Override 041 protected DependencyGraphParser newParser() 042 { 043 return new DependencyGraphParser( "transformer/optionality-selector/" ); 044 } 045 046 @Test 047 public void testDeriveOptionality() 048 throws Exception 049 { 050 DependencyNode root = parseResource( "derive.txt" ); 051 assertSame( root, transform( root ) ); 052 053 assertEquals( 2, root.getChildren().size() ); 054 assertEquals( true, root.getChildren().get( 0 ).getDependency().isOptional() ); 055 assertEquals( true, root.getChildren().get( 0 ).getChildren().get( 0 ).getDependency().isOptional() ); 056 assertEquals( false, root.getChildren().get( 1 ).getDependency().isOptional() ); 057 assertEquals( false, root.getChildren().get( 1 ).getChildren().get( 0 ).getDependency().isOptional() ); 058 } 059 060 @Test 061 public void testResolveOptionalityConflict_NonOptionalWins() 062 throws Exception 063 { 064 DependencyNode root = parseResource( "conflict.txt" ); 065 assertSame( root, transform( root ) ); 066 067 assertEquals( 2, root.getChildren().size() ); 068 assertEquals( true, root.getChildren().get( 0 ).getDependency().isOptional() ); 069 assertEquals( false, root.getChildren().get( 0 ).getChildren().get( 0 ).getDependency().isOptional() ); 070 } 071 072 @Test 073 public void testResolveOptionalityConflict_DirectDeclarationWins() 074 throws Exception 075 { 076 DependencyNode root = parseResource( "conflict-direct-dep.txt" ); 077 assertSame( root, transform( root ) ); 078 079 assertEquals( 2, root.getChildren().size() ); 080 assertEquals( true, root.getChildren().get( 1 ).getDependency().isOptional() ); 081 } 082 083}