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  
22  /**
23   * 
24   */
25  
26  import java.lang.reflect.Constructor;
27  import java.lang.reflect.InvocationTargetException;
28  import java.util.HashSet;
29  import java.util.List;
30  import java.util.Set;
31  
32  import org.apache.maven.artifact.Artifact;
33  
34  import junit.framework.TestCase;
35  
36  /**
37   * Abstract test case for subclasses of AbstractArtifactFeatureFilter
38   * 
39   * @author clove
40   * @see junit.framework.TestCase
41   * @see org.apache.maven.plugin.dependency.utils.filters.AbstractArtifactFeatureFilter
42   * @since 2.0
43   */
44  public abstract class AbstractArtifactFeatureFilterTestCase
45      extends TestCase
46  {
47      protected Set<Artifact> artifacts = new HashSet<Artifact>();
48  
49      protected Class<?> filterClass;
50  
51      protected void setUp()
52          throws Exception
53      {
54          super.setUp();
55  
56      }
57  
58      private Object createObjectViaReflection( Class<?> clazz, Object[] conArgs )
59          throws SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException,
60          IllegalAccessException, InvocationTargetException
61      {
62          Class<?>[] argslist = new Class<?>[2];
63          argslist[0] = String.class;
64          argslist[1] = String.class;
65          Constructor<?> ct = clazz.getConstructor( argslist );
66          return ct.newInstance( conArgs );
67      }
68  
69      public abstract void testParsing()
70          throws Exception;
71  
72      public void parsing()
73          throws SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException,
74          IllegalAccessException, InvocationTargetException
75      {
76          Object[] conArgs = new Object[] { "one,two", "three,four," };
77  
78          AbstractArtifactFeatureFilter filter =
79              (AbstractArtifactFeatureFilter) createObjectViaReflection( filterClass, conArgs );
80          List<String> includes = filter.getIncludes();
81          List<String> excludes = filter.getExcludes();
82  
83          assertEquals( 2, includes.size() );
84          assertEquals( 2, excludes.size() );
85          assertEquals( "one", includes.get( 0 ).toString() );
86          assertEquals( "two", includes.get( 1 ).toString() );
87          assertEquals( "three", excludes.get( 0 ).toString() );
88          assertEquals( "four", excludes.get( 1 ).toString() );
89      }
90  
91      public abstract void testFiltering()
92          throws Exception;
93  
94      public Set<Artifact> filtering()
95          throws SecurityException, IllegalArgumentException, NoSuchMethodException, InstantiationException,
96          IllegalAccessException, InvocationTargetException
97      {
98          Object[] conArgs = new Object[] { "one,two", "one,three," };
99          AbstractArtifactFeatureFilter filter =
100             (AbstractArtifactFeatureFilter) createObjectViaReflection( filterClass, conArgs );
101         Set<Artifact> result = filter.filter( artifacts );
102         assertEquals( 1, result.size() );
103         return result;
104     }
105 
106     public abstract void testFiltering2()
107         throws Exception;
108 
109     public Set<Artifact> filtering2()
110         throws SecurityException, IllegalArgumentException, NoSuchMethodException, InstantiationException,
111         IllegalAccessException, InvocationTargetException
112     {
113         Object[] conArgs = new Object[] { null, "one,three," };
114         AbstractArtifactFeatureFilter filter =
115             (AbstractArtifactFeatureFilter) createObjectViaReflection( filterClass, conArgs );
116         Set<Artifact> result = filter.filter( artifacts );
117         assertEquals( 2, result.size() );
118         return result;
119 
120     }
121 
122     public abstract void testFiltering3()
123         throws Exception;
124 
125     public void filtering3()
126         throws SecurityException, IllegalArgumentException, NoSuchMethodException, InstantiationException,
127         IllegalAccessException, InvocationTargetException
128     {
129         Object[] conArgs = new Object[] { null, null };
130         AbstractArtifactFeatureFilter filter =
131             (AbstractArtifactFeatureFilter) createObjectViaReflection( filterClass, conArgs );
132         Set<Artifact> result = filter.filter( artifacts );
133         assertEquals( 4, result.size() );
134     }
135 }