View Javadoc
1   package org.eclipse.aether.util.graph.visitor;
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 java.util.Objects.requireNonNull;
23  import static org.junit.Assert.*;
24  
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.DependencyGraphParser;
30  import org.junit.Test;
31  
32  public class FilteringDependencyVisitorTest
33  {
34  
35      private DependencyNode parse( String resource )
36          throws Exception
37      {
38          return new DependencyGraphParser( "visitor/filtering/" ).parseResource( resource );
39      }
40  
41      @Test
42      public void testFilterCalledWithProperParentStack()
43          throws Exception
44      {
45          DependencyNode root = parse( "parents.txt" );
46  
47          final StringBuilder buffer = new StringBuilder( 256 );
48          DependencyFilter filter = new DependencyFilter()
49          {
50              public boolean accept( DependencyNode node, List<DependencyNode> parents )
51              {
52                  requireNonNull( node, "node cannot be null" );
53                  requireNonNull( parents, "parents cannot be null" );
54                  for ( DependencyNode parent : parents )
55                  {
56                      buffer.append( parent.getDependency().getArtifact().getArtifactId() );
57                  }
58                  buffer.append( "," );
59                  return false;
60              }
61          };
62  
63          FilteringDependencyVisitor visitor = new FilteringDependencyVisitor( new PreorderNodeListGenerator(), filter );
64          root.accept( visitor );
65  
66          assertEquals( ",a,ba,cba,a,ea,", buffer.toString() );
67      }
68  
69  }