1 package org.apache.maven.shared.artifact.filter.collection;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
36
37
38
39
40
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 }