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 org.apache.maven.artifact.Artifact;
33
34 import junit.framework.TestCase;
35
36
37
38
39
40
41
42
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 }