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.Collection;
25  import java.util.LinkedList;
26  import java.util.List;
27  
28  import org.eclipse.aether.graph.DependencyFilter;
29  import org.eclipse.aether.graph.DependencyNode;
30  import org.eclipse.aether.internal.test.util.NodeBuilder;
31  import org.eclipse.aether.util.filter.AndDependencyFilter;
32  import org.eclipse.aether.util.filter.OrDependencyFilter;
33  import org.junit.Test;
34  
35  public class OrDependencyFilterTest
36      extends AbstractDependencyFilterTest
37  {
38  
39      @Test
40      public void acceptTest()
41      {
42          NodeBuilder builder = new NodeBuilder();
43          builder.artifactId( "test" );
44          List<DependencyNode> parents = new LinkedList<>();
45          // Empty OR
46          assertFalse( new OrDependencyFilter().accept( builder.build(), parents ) );
47  
48          // Basic Boolean Input
49          assertTrue( new OrDependencyFilter( getAcceptFilter() ).accept( builder.build(), parents ) );
50          assertFalse( new OrDependencyFilter( getDenyFilter() ).accept( builder.build(), parents ) );
51  
52          assertFalse( new OrDependencyFilter( getDenyFilter(), getDenyFilter() ).accept( builder.build(), parents ) );
53          assertTrue( new OrDependencyFilter( getDenyFilter(), getAcceptFilter() ).accept( builder.build(), parents ) );
54          assertTrue( new OrDependencyFilter( getAcceptFilter(), getDenyFilter() ).accept( builder.build(), parents ) );
55          assertTrue( new OrDependencyFilter( getAcceptFilter(), getAcceptFilter() ).accept( builder.build(), parents ) );
56  
57          assertFalse( new OrDependencyFilter( getDenyFilter(), getDenyFilter(), getDenyFilter() ).accept( builder.build(),
58                                                                                                           parents ) );
59          assertTrue( new OrDependencyFilter( getAcceptFilter(), getDenyFilter(), getDenyFilter() ).accept( builder.build(),
60                                                                                                            parents ) );
61          assertTrue( new OrDependencyFilter( getAcceptFilter(), getAcceptFilter(), getDenyFilter() ).accept( builder.build(),
62                                                                                                              parents ) );
63          assertTrue( new OrDependencyFilter( getAcceptFilter(), getAcceptFilter(), getAcceptFilter() ).accept( builder.build(),
64                                                                                                                parents ) );
65  
66          // User another constructor
67          Collection<DependencyFilter> filters = new LinkedList<>();
68          filters.add( getDenyFilter() );
69          filters.add( getAcceptFilter() );
70          assertTrue( new OrDependencyFilter( filters ).accept( builder.build(), parents ) );
71  
72          filters = new LinkedList<>();
73          filters.add( getDenyFilter() );
74          filters.add( getDenyFilter() );
75          assertFalse( new OrDependencyFilter( filters ).accept( builder.build(), parents ) );
76  
77          // newInstance
78          assertTrue( AndDependencyFilter.newInstance( getAcceptFilter(), getAcceptFilter() ).accept( builder.build(),
79                                                                                                      parents ) );
80          assertFalse( AndDependencyFilter.newInstance( getAcceptFilter(), getDenyFilter() ).accept( builder.build(),
81                                                                                                     parents ) );
82          assertTrue( AndDependencyFilter.newInstance( getAcceptFilter(), null ).accept( builder.build(), parents ) );
83          assertFalse( AndDependencyFilter.newInstance( getDenyFilter(), null ).accept( builder.build(), parents ) );
84          assertNull( AndDependencyFilter.newInstance( null, null ) );
85      }
86  
87  }