View Javadoc
1   package org.eclipse.aether.util.filter;
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 java.util.Collections;
25  import java.util.List;
26  
27  import org.eclipse.aether.graph.DependencyFilter;
28  import org.eclipse.aether.graph.DependencyNode;
29  import org.eclipse.aether.internal.test.util.NodeBuilder;
30  import org.eclipse.aether.util.filter.DependencyFilterUtils;
31  import org.junit.Test;
32  
33  /**
34   */
35  public class DependencyFilterUtilsTest
36  {
37  
38      private static List<DependencyNode> PARENTS = Collections.emptyList();
39  
40      @Test
41      public void testClasspathFilterCompile()
42      {
43          NodeBuilder builder = new NodeBuilder().artifactId( "aid" );
44          DependencyFilter filter = DependencyFilterUtils.classpathFilter( "compile" );
45  
46          assertTrue( filter.accept( builder.scope( "compile" ).build(), PARENTS ) );
47          assertTrue( filter.accept( builder.scope( "system" ).build(), PARENTS ) );
48          assertTrue( filter.accept( builder.scope( "provided" ).build(), PARENTS ) );
49          assertFalse( filter.accept( builder.scope( "runtime" ).build(), PARENTS ) );
50          assertFalse( filter.accept( builder.scope( "test" ).build(), PARENTS ) );
51      }
52  
53      @Test
54      public void testClasspathFilterRuntime()
55      {
56          NodeBuilder builder = new NodeBuilder().artifactId( "aid" );
57          DependencyFilter filter = DependencyFilterUtils.classpathFilter( "runtime" );
58  
59          assertTrue( filter.accept( builder.scope( "compile" ).build(), PARENTS ) );
60          assertFalse( filter.accept( builder.scope( "system" ).build(), PARENTS ) );
61          assertFalse( filter.accept( builder.scope( "provided" ).build(), PARENTS ) );
62          assertTrue( filter.accept( builder.scope( "runtime" ).build(), PARENTS ) );
63          assertFalse( filter.accept( builder.scope( "test" ).build(), PARENTS ) );
64      }
65  
66      @Test
67      public void testClasspathFilterTest()
68      {
69          NodeBuilder builder = new NodeBuilder().artifactId( "aid" );
70          DependencyFilter filter = DependencyFilterUtils.classpathFilter( "test" );
71  
72          assertTrue( filter.accept( builder.scope( "compile" ).build(), PARENTS ) );
73          assertTrue( filter.accept( builder.scope( "system" ).build(), PARENTS ) );
74          assertTrue( filter.accept( builder.scope( "provided" ).build(), PARENTS ) );
75          assertTrue( filter.accept( builder.scope( "runtime" ).build(), PARENTS ) );
76          assertTrue( filter.accept( builder.scope( "test" ).build(), PARENTS ) );
77      }
78  
79      @Test
80      public void testClasspathFilterCompileRuntime()
81      {
82          NodeBuilder builder = new NodeBuilder().artifactId( "aid" );
83          DependencyFilter filter = DependencyFilterUtils.classpathFilter( "compile", "runtime" );
84  
85          assertTrue( filter.accept( builder.scope( "compile" ).build(), PARENTS ) );
86          assertTrue( filter.accept( builder.scope( "system" ).build(), PARENTS ) );
87          assertTrue( filter.accept( builder.scope( "provided" ).build(), PARENTS ) );
88          assertTrue( filter.accept( builder.scope( "runtime" ).build(), PARENTS ) );
89          assertFalse( filter.accept( builder.scope( "test" ).build(), PARENTS ) );
90      }
91  
92      @Test
93      public void testClasspathFilterCompilePlusRuntime()
94      {
95          NodeBuilder builder = new NodeBuilder().artifactId( "aid" );
96          DependencyFilter filter = DependencyFilterUtils.classpathFilter( "compile+runtime" );
97  
98          assertTrue( filter.accept( builder.scope( "compile" ).build(), PARENTS ) );
99          assertTrue( filter.accept( builder.scope( "system" ).build(), PARENTS ) );
100         assertTrue( filter.accept( builder.scope( "provided" ).build(), PARENTS ) );
101         assertTrue( filter.accept( builder.scope( "runtime" ).build(), PARENTS ) );
102         assertFalse( filter.accept( builder.scope( "test" ).build(), PARENTS ) );
103     }
104 
105     @Test
106     public void testClasspathFilterRuntimeCommaSystem()
107     {
108         NodeBuilder builder = new NodeBuilder().artifactId( "aid" );
109         DependencyFilter filter = DependencyFilterUtils.classpathFilter( "runtime,system" );
110 
111         assertTrue( filter.accept( builder.scope( "compile" ).build(), PARENTS ) );
112         assertTrue( filter.accept( builder.scope( "system" ).build(), PARENTS ) );
113         assertFalse( filter.accept( builder.scope( "provided" ).build(), PARENTS ) );
114         assertTrue( filter.accept( builder.scope( "runtime" ).build(), PARENTS ) );
115         assertFalse( filter.accept( builder.scope( "test" ).build(), PARENTS ) );
116     }
117 
118     @Test
119     public void testClasspathFilterNull()
120     {
121         NodeBuilder builder = new NodeBuilder().artifactId( "aid" );
122         DependencyFilter filter = DependencyFilterUtils.classpathFilter( (String[]) null );
123 
124         assertFalse( filter.accept( builder.scope( "compile" ).build(), PARENTS ) );
125         assertFalse( filter.accept( builder.scope( "system" ).build(), PARENTS ) );
126         assertFalse( filter.accept( builder.scope( "provided" ).build(), PARENTS ) );
127         assertFalse( filter.accept( builder.scope( "runtime" ).build(), PARENTS ) );
128         assertFalse( filter.accept( builder.scope( "test" ).build(), PARENTS ) );
129     }
130 
131     @Test
132     public void testClasspathFilterUnknownScope()
133     {
134         NodeBuilder builder = new NodeBuilder().artifactId( "aid" );
135         DependencyFilter filter = DependencyFilterUtils.classpathFilter( "compile" );
136 
137         assertTrue( filter.accept( builder.scope( "" ).build(), PARENTS ) );
138         assertTrue( filter.accept( builder.scope( "unknown" ).build(), PARENTS ) );
139     }
140 
141 }