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  public abstract class AbstractArtifactFeatureFilterTestCase
40      extends TestCase
41  {
42      protected Set<Artifact> artifacts = new HashSet<Artifact>();
43  
44      protected Class<?> filterClass;
45  
46      protected void setUp()
47          throws Exception
48      {
49          super.setUp();
50  
51      }
52  
53      private Object createObjectViaReflection( Class<?> clazz, Object[] conArgs )
54          throws SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException,
55          IllegalAccessException, InvocationTargetException
56      {
57          Class<?>[] argslist = new Class<?>[2];
58          argslist[0] = String.class;
59          argslist[1] = String.class;
60          Constructor<?> ct = clazz.getConstructor( argslist );
61          return ct.newInstance( conArgs );
62      }
63  
64      public abstract void testParsing()
65          throws Exception;
66  
67      public void parsing()
68          throws SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException,
69          IllegalAccessException, InvocationTargetException
70      {
71          Object[] conArgs = new Object[] { "one,two", "three,four," };
72  
73          AbstractArtifactFeatureFilter filter =
74              (AbstractArtifactFeatureFilter) createObjectViaReflection( filterClass, conArgs );
75          List<String> includes = filter.getIncludes();
76          List<String> excludes = filter.getExcludes();
77  
78          assertEquals( 2, includes.size() );
79          assertEquals( 2, excludes.size() );
80          assertEquals( "one", includes.get( 0 ).toString() );
81          assertEquals( "two", includes.get( 1 ).toString() );
82          assertEquals( "three", excludes.get( 0 ).toString() );
83          assertEquals( "four", excludes.get( 1 ).toString() );
84      }
85  
86      public abstract void testFiltering()
87          throws Exception;
88  
89      public Set<Artifact> filtering()
90          throws SecurityException, IllegalArgumentException, NoSuchMethodException, InstantiationException,
91          IllegalAccessException, InvocationTargetException
92      {
93          Object[] conArgs = new Object[] { "one,two", "one,three," };
94          AbstractArtifactFeatureFilter filter =
95              (AbstractArtifactFeatureFilter) createObjectViaReflection( filterClass, conArgs );
96          Set<Artifact> result = filter.filter( artifacts );
97          assertEquals( 1, result.size() );
98          return result;
99      }
100 
101     public abstract void testFiltering2()
102         throws Exception;
103 
104     public Set<Artifact> filtering2()
105         throws SecurityException, IllegalArgumentException, NoSuchMethodException, InstantiationException,
106         IllegalAccessException, InvocationTargetException
107     {
108         Object[] conArgs = new Object[] { null, "one,three," };
109         AbstractArtifactFeatureFilter filter =
110             (AbstractArtifactFeatureFilter) createObjectViaReflection( filterClass, conArgs );
111         Set<Artifact> result = filter.filter( artifacts );
112         assertEquals( 2, result.size() );
113         return result;
114 
115     }
116 
117     public abstract void testFiltering3()
118         throws Exception;
119 
120     public void filtering3()
121         throws SecurityException, IllegalArgumentException, NoSuchMethodException, InstantiationException,
122         IllegalAccessException, InvocationTargetException
123     {
124         Object[] conArgs = new Object[] { null, null };
125         AbstractArtifactFeatureFilter filter =
126             (AbstractArtifactFeatureFilter) createObjectViaReflection( filterClass, conArgs );
127         Set<Artifact> result = filter.filter( artifacts );
128         assertEquals( 4, result.size() );
129     }
130 }