-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3072 from krmahadevan/feature/2916
Support ordering of listeners
- Loading branch information
Showing
38 changed files
with
1,660 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
testng-core/src/main/java/org/testng/ListenerComparator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.testng; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
import org.testng.collections.Lists; | ||
|
||
/** | ||
* Listener interface that can be used to determine listener execution order. This interface will | ||
* NOT be used to determine execution order for {@link IReporter} implementations. | ||
* | ||
* <p>An implementation can be plugged into TestNG either via: | ||
* | ||
* <ol> | ||
* <li>{@link TestNG#setListenerComparator(ListenerComparator)} if you are using the {@link | ||
* TestNG} APIs. | ||
* <li>Via the configuration parameter <code>-listenercomparator</code> if you are using a build | ||
* tool | ||
* </ol> | ||
*/ | ||
@FunctionalInterface | ||
public interface ListenerComparator extends Comparator<ITestNGListener> { | ||
static <T extends ITestNGListener> List<T> sort(List<T> list, ListenerComparator comparator) { | ||
if (comparator == null) { | ||
return Collections.unmodifiableList(list); | ||
} | ||
List<T> original = Lists.newArrayList(list); | ||
original.sort(comparator); | ||
return Collections.unmodifiableList(original); | ||
} | ||
|
||
static <T extends ITestNGListener> Collection<T> sort( | ||
Collection<T> list, ListenerComparator comparator) { | ||
if (comparator == null) { | ||
return Collections.unmodifiableCollection(list); | ||
} | ||
List<T> original = Lists.newArrayList(list); | ||
original.sort(comparator); | ||
return Collections.unmodifiableCollection(original); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.