1 package org.testng.internal; 2 3 import org.testng.IClass; 4 import org.testng.IRetryAnalyzer; 5 import org.testng.ITestClass; 6 import org.testng.ITestNGMethod; 7 import org.testng.collections.Lists; 8 import org.testng.xml.XmlTest; 9 10 import java.lang.reflect.Method; 11 import java.util.Collections; 12 import java.util.List; 13 import java.util.Map; 14 15 public class ClonedMethod implements ITestNGMethod { 16 private static final long serialVersionUID = 1L; 17 18 private ITestNGMethod m_method; 19 transient private Method m_javaMethod; 20 private String m_id; 21 private int m_currentInvocationCount; 22 private long m_date; 23 24 private List<Integer> m_invocationNumbers = Lists.newArrayList(); 25 private List<Integer> m_failedInvocationNumbers = Lists.newArrayList(); 26 27 public ClonedMethod(ITestNGMethod method, Method javaMethod) { 28 m_method = method; 29 m_javaMethod = javaMethod; 30 } 31 32 @Override 33 public void addMethodDependedUpon(String methodName) { 34 // nop 35 } 36 37 @Override 38 public boolean canRunFromClass(IClass testClass) { 39 return m_method.canRunFromClass(testClass); 40 } 41 42 @Override 43 public String[] getAfterGroups() { 44 return m_method.getAfterGroups(); 45 } 46 47 @Override 48 public String[] getBeforeGroups() { 49 return m_method.getBeforeGroups(); 50 } 51 52 @Override 53 public int getCurrentInvocationCount() { 54 return m_currentInvocationCount; 55 } 56 57 @Override 58 public long getDate() { 59 return m_method.getDate(); 60 } 61 62 @Override 63 public String getDescription() { 64 return ""; 65 } 66 67 @Override 68 public void setDescription(String description) { 69 m_method.setDescription(description); 70 } 71 72 @Override 73 public boolean getEnabled() { 74 return true; 75 } 76 77 @Override 78 public String[] getGroups() { 79 return m_method.getGroups(); 80 } 81 82 @Override 83 public String[] getGroupsDependedUpon() { 84 return new String[0]; 85 } 86 87 @Override 88 public String getId() { 89 return m_id; 90 } 91 92 @Override 93 public long[] getInstanceHashCodes() { 94 return m_method.getInstanceHashCodes(); 95 } 96 97 @Override 98 public Object[] getInstances() { 99 return m_method.getInstances(); 100 } 101 102 @Override 103 public Object getInstance() { 104 return m_method.getInstance(); 105 } 106 107 @Override 108 public int getInvocationCount() { 109 return 1; 110 } 111 112 @Override 113 public int getTotalInvocationCount() { 114 return 1; 115 } 116 117 @Override 118 public long getInvocationTimeOut() { 119 return m_method.getInvocationTimeOut(); 120 } 121 122 @Override 123 public Method getMethod() { 124 return m_javaMethod; 125 } 126 127 @Override 128 public String getMethodName() { 129 return m_javaMethod.getName(); 130 } 131 132 @Override 133 public String[] getMethodsDependedUpon() { 134 return new String[0]; 135 } 136 137 @Override 138 public String getMissingGroup() { 139 return null; 140 } 141 142 @Override 143 public int getParameterInvocationCount() { 144 return 1; 145 } 146 147 @Override 148 public Class getRealClass() { 149 return m_javaMethod.getClass(); 150 } 151 152 @Override 153 public IRetryAnalyzer getRetryAnalyzer() { 154 return m_method.getRetryAnalyzer(); 155 } 156 157 @Override 158 public int getSuccessPercentage() { 159 return 100; 160 } 161 162 @Override 163 public ITestClass getTestClass() { 164 return m_method.getTestClass(); 165 } 166 167 @Override 168 public int getThreadPoolSize() { 169 return m_method.getThreadPoolSize(); 170 } 171 172 @Override 173 public long getTimeOut() { 174 return m_method.getTimeOut(); 175 } 176 177 @Override 178 public void setTimeOut(long timeOut) { 179 m_method.setTimeOut(timeOut); 180 } 181 182 @Override 183 public boolean ignoreMissingDependencies() { 184 return false; 185 } 186 187 @Override 188 public void incrementCurrentInvocationCount() { 189 m_currentInvocationCount++; 190 } 191 192 @Override 193 public boolean isAfterClassConfiguration() { 194 return false; 195 } 196 197 @Override 198 public boolean isAfterGroupsConfiguration() { 199 return false; 200 } 201 202 @Override 203 public boolean isAfterMethodConfiguration() { 204 return false; 205 } 206 207 @Override 208 public boolean isAfterSuiteConfiguration() { 209 return false; 210 } 211 212 @Override 213 public boolean isAfterTestConfiguration() { 214 return false; 215 } 216 217 @Override 218 public boolean isAlwaysRun() { 219 return false; 220 } 221 222 @Override 223 public boolean isBeforeClassConfiguration() { 224 return false; 225 } 226 227 @Override 228 public boolean isBeforeGroupsConfiguration() { 229 return false; 230 } 231 232 @Override 233 public boolean isBeforeMethodConfiguration() { 234 return false; 235 } 236 237 @Override 238 public boolean isBeforeSuiteConfiguration() { 239 return false; 240 } 241 242 @Override 243 public boolean isBeforeTestConfiguration() { 244 return false; 245 } 246 247 @Override 248 public boolean isTest() { 249 return true; 250 } 251 252 @Override 253 public void setDate(long date) { 254 m_date = date; 255 } 256 257 @Override 258 public void setId(String id) { 259 m_id = id; 260 } 261 262 @Override 263 public void setIgnoreMissingDependencies(boolean ignore) { 264 } 265 266 @Override 267 public void setInvocationCount(int count) { 268 } 269 270 @Override 271 public void setMissingGroup(String group) { 272 } 273 274 @Override 275 public void setParameterInvocationCount(int n) { 276 } 277 278 @Override 279 public void setRetryAnalyzer(IRetryAnalyzer retryAnalyzer) { 280 } 281 282 @Override 283 public void setSkipFailedInvocations(boolean skip) { 284 } 285 286 @Override 287 public void setTestClass(ITestClass cls) { 288 } 289 290 @Override 291 public void setThreadPoolSize(int threadPoolSize) { 292 } 293 294 @Override 295 public boolean skipFailedInvocations() { 296 return false; 297 } 298 299 @Override 300 public int compareTo(Object o) { 301 int result = -2; 302 Class<?> thisClass = getRealClass(); 303 Class<?> otherClass = ((ITestNGMethod) o).getRealClass(); 304 if (thisClass.isAssignableFrom(otherClass)) { 305 result = -1; 306 } else if (otherClass.isAssignableFrom(thisClass)) { 307 result = 1; 308 } else if (equals(o)) { 309 result = 0; 310 } 311 312 return result; 313 } 314 315 @Override 316 public ClonedMethod clone() { 317 return new ClonedMethod(m_method, m_javaMethod); 318 } 319 320 @Override 321 public String toString() { 322 Method m = getMethod(); 323 String cls = m.getDeclaringClass().getName(); 324 StringBuffer result = new StringBuffer(cls + "." + m.getName() + "("); 325 int i = 0; 326 for (Class<?> p : m.getParameterTypes()) { 327 if (i++ > 0) { 328 result.append(", "); 329 } 330 result.append(p.getName()); 331 } 332 result.append(")"); 333 334 return result.toString(); 335 } 336 337 @Override 338 public List<Integer> getInvocationNumbers() { 339 return m_invocationNumbers; 340 } 341 342 @Override 343 public void setInvocationNumbers(List<Integer> count) { 344 m_invocationNumbers = count; 345 } 346 347 @Override 348 public List<Integer> getFailedInvocationNumbers() { 349 return m_failedInvocationNumbers; 350 } 351 352 @Override 353 public void addFailedInvocationNumber(int number) { 354 m_failedInvocationNumbers.add(number); 355 } 356 357 @Override 358 public int getPriority() { 359 return m_method.getPriority(); 360 } 361 362 @Override 363 public void setPriority(int priority) { 364 // ignored 365 } 366 367 @Override 368 public XmlTest getXmlTest() { 369 return m_method.getXmlTest(); 370 } 371 372 @Override 373 public ConstructorOrMethod getConstructorOrMethod() { 374 return null; 375 } 376 377 @Override 378 public Map<String, String> findMethodParameters(XmlTest test) { 379 return Collections.emptyMap(); 380 } 381 } 382