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