View Javadoc

1   package org.apache.maven.shared.dependency.tree.traversal;
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 java.util.Arrays;
23  import java.util.Collections;
24  import java.util.List;
25  
26  import org.apache.maven.shared.dependency.tree.AbstractDependencyNodeTest;
27  import org.apache.maven.shared.dependency.tree.DependencyNode;
28  
29  /**
30   * Tests <code>CollectingDependencyNodeVisitor</code>.
31   *
32   * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
33   * @version $Id: CollectingDependencyNodeVisitorTest.java 1100703 2011-05-08 08:27:33Z hboutemy $
34   * @see CollectingDependencyNodeVisitor
35   */
36  public class CollectingDependencyNodeVisitorTest
37      extends AbstractDependencyNodeTest
38  {
39      // fields -----------------------------------------------------------------
40      
41      private CollectingDependencyNodeVisitor visitor;
42      
43      private DependencyNode node1;
44  
45      private DependencyNode node2;
46  
47      private DependencyNode node3;
48  
49      // TestCase methods -------------------------------------------------------
50      
51      /**
52       * {@inheritDoc}
53       */
54      protected void setUp()
55          throws Exception
56      {
57          visitor = new CollectingDependencyNodeVisitor();
58          node1 = createNode( "g:a:t:1" );
59          node2 = createNode( "g:b:t:1" );
60          node3 = createNode( "g:c:t:1" );
61      }
62      
63      // tests ------------------------------------------------------------------
64      
65      public void testVisitSingleNode()
66      {
67          assertEmptyNodes();
68          assertTrue( visitor.visit( node1 ) );
69          assertNodes( node1 );
70      }
71  
72      public void testVisitMultipleNodes()
73      {
74          assertEmptyNodes();
75          assertTrue( visitor.visit( node1 ) );
76          assertTrue( visitor.visit( node2 ) );
77          assertTrue( visitor.visit( node3 ) );
78          assertNodes( Arrays.asList( new DependencyNode[] { node1, node2, node3 } ) );
79      }
80  
81      public void testEndVisit()
82      {
83          assertEmptyNodes();
84          assertTrue( visitor.endVisit( node1 ) );
85          assertEmptyNodes();
86      }
87  
88      // private methods --------------------------------------------------------
89      
90      private void assertEmptyNodes()
91      {
92          assertNodes( Collections.<DependencyNode>emptyList() );
93      }
94      
95      private void assertNodes( DependencyNode node )
96      {
97          assertNodes( Collections.singletonList( node ) );
98      }
99      
100     private void assertNodes( List<DependencyNode> expectedNodes )
101     {
102         assertEquals( "Collected nodes", expectedNodes, visitor.getNodes() );
103     }
104 }