1 package testng.utils;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import junit.framework.TestCase;
23 import org.apache.maven.surefire.testng.utils.MethodSelector;
24 import org.apache.maven.surefire.api.testset.TestListResolver;
25 import org.testng.IClass;
26 import org.testng.IRetryAnalyzer;
27 import org.testng.ITestClass;
28 import org.testng.ITestNGMethod;
29 import org.testng.internal.DefaultMethodSelectorContext;
30
31 import java.lang.reflect.Method;
32
33
34
35
36 public class MethodSelectorTest
37 extends TestCase
38 {
39 public void testInclusionOfMethodFromBaseClass()
40 {
41 MethodSelector selector = new MethodSelector();
42 DefaultMethodSelectorContext context = new DefaultMethodSelectorContext();
43 ITestNGMethod testngMethod = new FakeTestNGMethod( ChildClassSample.class, "baseClassMethodToBeIncluded" );
44 TestListResolver resolver =
45 new TestListResolver( BaseClassSample.class.getName() + "#baseClassMethodToBeIncluded" );
46 MethodSelector.setTestListResolver( resolver );
47 boolean include = selector.includeMethod( context, testngMethod, true );
48 assertTrue( include );
49 }
50
51 public void testNoInclusionOfMethodFromBaseClass()
52 {
53 MethodSelector selector = new MethodSelector();
54 DefaultMethodSelectorContext context = new DefaultMethodSelectorContext();
55 ITestNGMethod testngMethod = new FakeTestNGMethod( ChildClassSample.class, "baseClassMethodToBeIncluded" );
56 TestListResolver resolver = new TestListResolver( BaseClassSample.class.getName() + "#nonExistedMethod" );
57 MethodSelector.setTestListResolver( resolver );
58 boolean include = selector.includeMethod( context, testngMethod, true );
59 assertFalse( include );
60 }
61
62 public void testInclusionOfMethodFromSubClass()
63 {
64 MethodSelector selector = new MethodSelector();
65 DefaultMethodSelectorContext context = new DefaultMethodSelectorContext();
66 ITestNGMethod testngMethod = new FakeTestNGMethod( ChildClassSample.class, "subClassMethod" );
67 TestListResolver resolver = new TestListResolver( ChildClassSample.class.getName() + "#sub*" );
68 MethodSelector.setTestListResolver( resolver );
69 boolean include = selector.includeMethod( context, testngMethod, true );
70 assertTrue( include );
71 }
72
73 private static class FakeTestNGMethod
74 implements ITestNGMethod
75 {
76 private final Class<?> clazz;
77 private final String methodName;
78
79 FakeTestNGMethod( Class<?> clazz, String methodName )
80 {
81 this.clazz = clazz;
82 this.methodName = methodName;
83 }
84
85 @Override
86 public Class getRealClass()
87 {
88 return clazz;
89 }
90
91 @Override
92 public ITestClass getTestClass()
93 {
94 return null;
95 }
96
97 @Override
98 public void setTestClass( ITestClass iTestClass )
99 {
100
101 }
102
103 @Override
104 public Method getMethod()
105 {
106 return null;
107 }
108
109 @Override
110 public String getMethodName()
111 {
112 return methodName;
113 }
114
115 @Override
116 public Object[] getInstances()
117 {
118 return new Object[0];
119 }
120
121 @Override
122 public long[] getInstanceHashCodes()
123 {
124 return new long[0];
125 }
126
127 @Override
128 public String[] getGroups()
129 {
130 return new String[0];
131 }
132
133 @Override
134 public String[] getGroupsDependedUpon()
135 {
136 return new String[0];
137 }
138
139 @Override
140 public String getMissingGroup()
141 {
142 return null;
143 }
144
145 @Override
146 public void setMissingGroup( String s )
147 {
148
149 }
150
151 @Override
152 public String[] getBeforeGroups()
153 {
154 return new String[0];
155 }
156
157 @Override
158 public String[] getAfterGroups()
159 {
160 return new String[0];
161 }
162
163 @Override
164 public String[] getMethodsDependedUpon()
165 {
166 return new String[0];
167 }
168
169 @Override
170 public void addMethodDependedUpon( String s )
171 {
172
173 }
174
175 @Override
176 public boolean isTest()
177 {
178 return false;
179 }
180
181 @Override
182 public boolean isBeforeMethodConfiguration()
183 {
184 return false;
185 }
186
187 @Override
188 public boolean isAfterMethodConfiguration()
189 {
190 return false;
191 }
192
193 @Override
194 public boolean isBeforeClassConfiguration()
195 {
196 return false;
197 }
198
199 @Override
200 public boolean isAfterClassConfiguration()
201 {
202 return false;
203 }
204
205 @Override
206 public boolean isBeforeSuiteConfiguration()
207 {
208 return false;
209 }
210
211 @Override
212 public boolean isAfterSuiteConfiguration()
213 {
214 return false;
215 }
216
217 @Override
218 public boolean isBeforeTestConfiguration()
219 {
220 return false;
221 }
222
223 @Override
224 public boolean isAfterTestConfiguration()
225 {
226 return false;
227 }
228
229 @Override
230 public boolean isBeforeGroupsConfiguration()
231 {
232 return false;
233 }
234
235 @Override
236 public boolean isAfterGroupsConfiguration()
237 {
238 return false;
239 }
240
241 @Override
242 public long getTimeOut()
243 {
244 return 0;
245 }
246
247 @Override
248 public int getInvocationCount()
249 {
250 return 0;
251 }
252
253 @Override
254 public void setInvocationCount( int i )
255 {
256
257 }
258
259 @Override
260 public int getSuccessPercentage()
261 {
262 return 0;
263 }
264
265 @Override
266 public String getId()
267 {
268 return null;
269 }
270
271 @Override
272 public void setId( String s )
273 {
274
275 }
276
277 @Override
278 public long getDate()
279 {
280 return 0;
281 }
282
283 @Override
284 public void setDate( long l )
285 {
286
287 }
288
289 @Override
290 public boolean canRunFromClass( IClass iClass )
291 {
292 return false;
293 }
294
295 @Override
296 public boolean isAlwaysRun()
297 {
298 return false;
299 }
300
301 @Override
302 public int getThreadPoolSize()
303 {
304 return 0;
305 }
306
307 @Override
308 public void setThreadPoolSize( int i )
309 {
310
311 }
312
313 @Override
314 public String getDescription()
315 {
316 return null;
317 }
318
319 @Override
320 public void incrementCurrentInvocationCount()
321 {
322
323 }
324
325 @Override
326 public int getCurrentInvocationCount()
327 {
328 return 0;
329 }
330
331 @Override
332 public void setParameterInvocationCount( int i )
333 {
334
335 }
336
337 @Override
338 public int getParameterInvocationCount()
339 {
340 return 0;
341 }
342
343 @Override
344 public ITestNGMethod clone()
345 {
346 try
347 {
348 return ( ITestNGMethod ) super.clone();
349 }
350 catch ( CloneNotSupportedException e )
351 {
352 throw new RuntimeException( e );
353 }
354 }
355
356 @Override
357 public IRetryAnalyzer getRetryAnalyzer()
358 {
359 return null;
360 }
361
362 @Override
363 public void setRetryAnalyzer( IRetryAnalyzer iRetryAnalyzer )
364 {
365
366 }
367
368 @Override
369 public boolean skipFailedInvocations()
370 {
371 return false;
372 }
373
374 @Override
375 public void setSkipFailedInvocations( boolean b )
376 {
377
378 }
379
380 @Override
381 public long getInvocationTimeOut()
382 {
383 return 0;
384 }
385
386 @Override
387 public boolean ignoreMissingDependencies()
388 {
389 return false;
390 }
391
392 @Override
393 public void setIgnoreMissingDependencies( boolean b )
394 {
395
396 }
397
398 @Override
399 public int compareTo( Object o )
400 {
401 return 0;
402 }
403 }
404 }