View Javadoc
1   package org.apache.maven.shared.artifact.filter.collection;
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  import java.util.Set;
22  
23  import org.apache.maven.artifact.Artifact;
24  import org.apache.maven.plugin.testing.ArtifactStubFactory;
25  import org.junit.Before;
26  import org.junit.Test;
27  
28  import static org.junit.Assert.*;
29  
30  /**
31   * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
32   */
33  public class TestProjectTransitivityFilter
34  {
35      Set<Artifact> artifacts;
36  
37      Set<Artifact> directArtifacts;
38      
39      Set<Artifact> classifiedArtifacts;
40  
41      @Before
42      public void setUp() throws Exception
43      {
44          ArtifactStubFactory fact = new ArtifactStubFactory( null, false );
45          artifacts = fact.getScopedArtifacts();
46          directArtifacts = fact.getReleaseAndSnapshotArtifacts();
47          classifiedArtifacts = fact.getClassifiedArtifacts();
48          artifacts.addAll( directArtifacts );
49          artifacts.addAll( classifiedArtifacts );
50      }
51  
52      @Test
53      public void testAll()
54      {
55          ProjectTransitivityFilter filter = new ProjectTransitivityFilter( directArtifacts, false );
56          Set<Artifact> result = filter.filter( artifacts );
57          assertEquals( 11, result.size() );
58      }
59  
60      @Test
61      public void testExclude()
62      {
63          ProjectTransitivityFilter filter = new ProjectTransitivityFilter( directArtifacts, false );
64          assertFalse( filter.isExcludeTransitive() );
65          filter.setExcludeTransitive( true );
66          assertTrue( filter.isExcludeTransitive() );
67          Set<Artifact> result = filter.filter( artifacts );
68  
69          assertEquals( 2, result.size() );
70  
71          for ( Artifact artifact : result )
72          {
73              assertTrue(
74                      artifact.getArtifactId().equals( "release" ) || artifact.getArtifactId().equals( "snapshot" ) );
75          }
76      }
77  
78      @Test
79      public void testClassified()
80      {
81          ProjectTransitivityFilter filter = new ProjectTransitivityFilter( classifiedArtifacts, true );
82          Set<Artifact> result = filter.filter( artifacts );
83          assertEquals( 4, result.size() );
84      }
85  
86  }