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