View Javadoc

1   package org.apache.maven.shared.dependency.tree.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 org.apache.maven.shared.dependency.tree.AbstractDependencyNodeTest;
23  import org.apache.maven.shared.dependency.tree.DependencyNode;
24  
25  /**
26   * Tests <code>AncestorOrSelfDependencyNodeFilter</code>.
27   * 
28   * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
29   * @version $Id: AncestorOrSelfDependencyNodeFilterTest.java 1100703 2011-05-08 08:27:33Z hboutemy $
30   * @see AncestorOrSelfDependencyNodeFilter
31   */
32  public class AncestorOrSelfDependencyNodeFilterTest
33      extends AbstractDependencyNodeTest
34  {
35      // constants --------------------------------------------------------------
36  
37      private DependencyNode rootNode;
38  
39      private DependencyNode childNode1;
40  
41      private DependencyNode childNode2;
42  
43      private DependencyNode grandChildNode;
44  
45      private AncestorOrSelfDependencyNodeFilter filter;
46  
47      // TestCase methods -------------------------------------------------------
48  
49      /**
50       * {@inheritDoc}
51       */
52      protected void setUp()
53          throws Exception
54      {
55          /*
56           * p -> a -> c
57           *   -> b
58           */
59  
60          rootNode = createNode( "g:p:t:1" );
61  
62          childNode1 = createNode( "g:a:t:1" );
63          rootNode.addChild( childNode1 );
64  
65          childNode2 = createNode( "g:b:t:1" );
66          rootNode.addChild( childNode2 );
67  
68          grandChildNode = createNode( "g:c:t:1" );
69          childNode1.addChild( grandChildNode );
70      }
71  
72      // tests ------------------------------------------------------------------
73  
74      public void testSelf()
75      {
76          filter = new AncestorOrSelfDependencyNodeFilter( rootNode );
77  
78          assertTrue( filter.accept( rootNode ) );
79      }
80  
81      public void testParent()
82      {
83          filter = new AncestorOrSelfDependencyNodeFilter( childNode1 );
84  
85          assertTrue( filter.accept( rootNode ) );
86      }
87  
88      public void testGrandParent()
89      {
90          filter = new AncestorOrSelfDependencyNodeFilter( grandChildNode );
91  
92          assertTrue( filter.accept( rootNode ) );
93      }
94  
95      public void testCousin()
96      {
97          filter = new AncestorOrSelfDependencyNodeFilter( childNode2 );
98  
99          assertFalse( filter.accept( childNode1 ) );
100     }
101 
102     public void testChild()
103     {
104         filter = new AncestorOrSelfDependencyNodeFilter( rootNode );
105 
106         assertFalse( filter.accept( childNode1 ) );
107     }
108 
109     public void testGrandChild()
110     {
111         filter = new AncestorOrSelfDependencyNodeFilter( rootNode );
112 
113         assertFalse( filter.accept( grandChildNode ) );
114     }
115 }