View Javadoc
1   package org.eclipse.aether.util.graph.transformer;
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 static org.junit.Assert.*;
23  
24  import org.eclipse.aether.collection.DependencyGraphTransformer;
25  import org.eclipse.aether.graph.DependencyNode;
26  import org.eclipse.aether.internal.test.util.DependencyGraphParser;
27  import org.junit.Test;
28  
29  public class SimpleOptionalitySelectorTest
30      extends AbstractDependencyGraphTransformerTest
31  {
32  
33      @Override
34      protected DependencyGraphTransformer newTransformer()
35      {
36          return new ConflictResolver( new NearestVersionSelector(), new JavaScopeSelector(),
37                                       new SimpleOptionalitySelector(), new JavaScopeDeriver() );
38      }
39  
40      @Override
41      protected DependencyGraphParser newParser()
42      {
43          return new DependencyGraphParser( "transformer/optionality-selector/" );
44      }
45  
46      @Test
47      public void testDeriveOptionality()
48          throws Exception
49      {
50          DependencyNode root = parseResource( "derive.txt" );
51          assertSame( root, transform( root ) );
52  
53          assertEquals( 2, root.getChildren().size() );
54          assertTrue( root.getChildren().get( 0 ).getDependency().isOptional() );
55          assertTrue( root.getChildren().get( 0 ).getChildren().get( 0 ).getDependency().isOptional() );
56          assertFalse( root.getChildren().get( 1 ).getDependency().isOptional() );
57          assertFalse( root.getChildren().get( 1 ).getChildren().get( 0 ).getDependency().isOptional() );
58      }
59  
60      @Test
61      public void testResolveOptionalityConflict_NonOptionalWins()
62          throws Exception
63      {
64          DependencyNode root = parseResource( "conflict.txt" );
65          assertSame( root, transform( root ) );
66  
67          assertEquals( 2, root.getChildren().size() );
68          assertTrue( root.getChildren().get( 0 ).getDependency().isOptional() );
69          assertFalse( root.getChildren().get( 0 ).getChildren().get( 0 ).getDependency().isOptional() );
70      }
71  
72      @Test
73      public void testResolveOptionalityConflict_DirectDeclarationWins()
74          throws Exception
75      {
76          DependencyNode root = parseResource( "conflict-direct-dep.txt" );
77          assertSame( root, transform( root ) );
78  
79          assertEquals( 2, root.getChildren().size() );
80          assertTrue( root.getChildren().get( 1 ).getDependency().isOptional() );
81      }
82  
83  }