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