|
8 | 8 | import java.util.Collections; |
9 | 9 | import java.util.HashSet; |
10 | 10 | import java.util.List; |
| 11 | +import java.util.ListIterator; |
11 | 12 | import java.util.Objects; |
| 13 | +import java.util.Optional; |
12 | 14 | import java.util.ServiceLoader; |
13 | 15 | import java.util.Set; |
14 | 16 |
|
|
29 | 31 | import org.testng.ITestResult; |
30 | 32 | import org.testng.annotations.ITestAnnotation; |
31 | 33 |
|
32 | | -import com.google.common.base.Optional; |
33 | | -import com.google.common.collect.Lists; |
34 | | - |
35 | 34 | /** |
36 | 35 | * This TestNG listener enables the addition of other listeners at runtime and guarantees the order in which they're |
37 | 36 | * invoked. This is similar in behavior to a JUnit rule chain. |
@@ -124,9 +123,10 @@ public void onStart(ISuite suite) { |
124 | 123 | suite.setAttribute(LISTENER_CHAIN, this); |
125 | 124 |
|
126 | 125 | synchronized(suiteListeners) { |
127 | | - for (ISuiteListener suiteListener : Lists.reverse(suiteListeners)) { |
128 | | - suiteListener.onStart(suite); |
129 | | - } |
| 126 | + ListIterator<ISuiteListener> iterator = suiteListeners.listIterator(suiteListeners.size()); |
| 127 | + while (iterator.hasPrevious()) { |
| 128 | + iterator.previous().onStart(suite); |
| 129 | + } |
130 | 130 | } |
131 | 131 | } |
132 | 132 |
|
@@ -226,9 +226,10 @@ public void afterInvocation(IInvokedMethod method, ITestResult testResult) { |
226 | 226 | // @Override omitted to avoid interface conflict |
227 | 227 | public void beforeInvocation(IInvokedMethod method, ITestResult testResult, ITestContext context) { |
228 | 228 | synchronized(methodListeners) { |
229 | | - for (IInvokedMethodListener methodListener : Lists.reverse(methodListeners)) { |
230 | | - methodListener.beforeInvocation(method, testResult); |
231 | | - } |
| 229 | + ListIterator<IInvokedMethodListener> iterator = methodListeners.listIterator(methodListeners.size()); |
| 230 | + while (iterator.hasPrevious()) { |
| 231 | + iterator.previous().beforeInvocation(method, testResult); |
| 232 | + } |
232 | 233 | } |
233 | 234 | } |
234 | 235 |
|
@@ -261,9 +262,10 @@ public void afterInvocation(IInvokedMethod method, ITestResult testResult, ITest |
261 | 262 | @Override |
262 | 263 | public void onTestStart(ITestResult result) { |
263 | 264 | synchronized(testListeners) { |
264 | | - for (ITestListener testListener : Lists.reverse(testListeners)) { |
265 | | - testListener.onTestStart(result); |
266 | | - } |
| 265 | + ListIterator<ITestListener> iterator = testListeners.listIterator(testListeners.size()); |
| 266 | + while (iterator.hasPrevious()) { |
| 267 | + iterator.previous().onTestStart(result); |
| 268 | + } |
267 | 269 | } |
268 | 270 | } |
269 | 271 |
|
@@ -343,9 +345,10 @@ public void onTestFailedButWithinSuccessPercentage(ITestResult result) { |
343 | 345 | @Override |
344 | 346 | public void onStart(ITestContext context) { |
345 | 347 | synchronized (testListeners) { |
346 | | - for (ITestListener testListener : Lists.reverse(testListeners)) { |
347 | | - testListener.onStart(context); |
348 | | - } |
| 348 | + ListIterator<ITestListener> iterator = testListeners.listIterator(testListeners.size()); |
| 349 | + while (iterator.hasPrevious()) { |
| 350 | + iterator.previous().onStart(context); |
| 351 | + } |
349 | 352 | } |
350 | 353 | } |
351 | 354 |
|
@@ -394,9 +397,10 @@ public List<IMethodInstance> intercept(List<IMethodInstance> methods, ITestConte |
394 | 397 | @Override |
395 | 398 | public void onBeforeClass(ITestClass testClass) { |
396 | 399 | synchronized (classListeners) { |
397 | | - for (IClassListener classListener : Lists.reverse(classListeners)) { |
398 | | - classListener.onBeforeClass(testClass); |
399 | | - } |
| 400 | + ListIterator<IClassListener> iterator = classListeners.listIterator(classListeners.size()); |
| 401 | + while (iterator.hasPrevious()) { |
| 402 | + iterator.previous().onBeforeClass(testClass); |
| 403 | + } |
400 | 404 | } |
401 | 405 | } |
402 | 406 |
|
@@ -479,7 +483,7 @@ public <T extends ITestNGListener> Optional<T> getAttachedListener(Class<T> list |
479 | 483 | return Optional.of((T) listener); |
480 | 484 | } |
481 | 485 | } |
482 | | - return Optional.absent(); |
| 486 | + return Optional.empty(); |
483 | 487 | } |
484 | 488 |
|
485 | 489 | /** |
|
0 commit comments