Skip to content

Commit d30e588

Browse files
committed
Re-wording the JVM arg name for better clarity.
1 parent 4fef3c4 commit d30e588

File tree

2 files changed

+30
-27
lines changed

2 files changed

+30
-27
lines changed

testng-core-api/src/main/java/org/testng/internal/RuntimeBehavior.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,22 @@ public final class RuntimeBehavior {
1919
public static final String TESTNG_DEFAULT_VERBOSE = "testng.default.verbose";
2020
public static final String IGNORE_CALLBACK_INVOCATION_SKIPS = "testng.ignore.callback.skip";
2121
public static final String SYMMETRIC_LISTENER_EXECUTION = "testng.listener.execution.symmetric";
22-
public static final String IDE_PACKAGE_NAMES = "testng.ide.listeners.package.name";
22+
public static final String PREFERENTIAL_LISTENERS = "testng.preferential.listeners.package";
2323

2424
private RuntimeBehavior() {}
2525

2626
public static boolean ignoreCallbackInvocationSkips() {
2727
return Boolean.getBoolean(IGNORE_CALLBACK_INVOCATION_SKIPS);
2828
}
2929

30-
public static List<String> getIdePackageNames() {
30+
/**
31+
* @return - A comma separated list of packages that represent special listeners which users will
32+
* expect to be executed after executing the regular listeners. Here special listeners can be
33+
* anything that a user feels should be executed ALWAYS at the end.
34+
*/
35+
public static List<String> getPreferentialListeners() {
3136
String packages =
32-
Optional.ofNullable(System.getProperty(IDE_PACKAGE_NAMES)).orElse("com.intellij.rt.*");
37+
Optional.ofNullable(System.getProperty(PREFERENTIAL_LISTENERS)).orElse("com.intellij.rt.*");
3338
return Arrays.asList(packages.split(","));
3439
}
3540

testng-core/src/main/java/org/testng/internal/ListenerOrderDeterminer.java

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,37 @@
1111
import org.testng.internal.collections.Pair;
1212

1313
/**
14-
* A Utility that helps us differentiate between a user's listener and an IDE Listener.
14+
* A Utility that helps us differentiate between a user's listener and preferential Listener.
1515
*
1616
* <p>When dealing with TestNG listeners we would need to ensure that the user created listeners are
17-
* invoked first followed by IDE listeners. This is required so that we always honour any state
18-
* changes that a user's listener may have done to the internal state of objects that can affect the
19-
* outcome of the execution (for e.g.,{@link org.testng.ITestResult})
17+
* invoked first followed by Preferential listeners. This is required so that we always honour any
18+
* state changes that a user's listener may have done to the internal state of objects that can
19+
* affect the outcome of the execution (for e.g.,{@link org.testng.ITestResult})
2020
*
2121
* <p>The ordering must be done such that, when dealing with "beforeXXX|afterXXX" we group all the
22-
* IDE listeners at the end. That way, we can always ensure that the IDE listeners always honour the
23-
* changes that were done to the TestNG internal states and give a consistent experience for users
24-
* in the IDE.
22+
* IDE listeners at the end. That way, we can always ensure that the preferential listeners (for
23+
* e.g., IDE listeners) always honour the changes that were done to the TestNG internal states and
24+
* give a consistent experience for users.
2525
*/
2626
public final class ListenerOrderDeterminer {
2727

2828
private ListenerOrderDeterminer() {
2929
// Defeat instantiation
3030
}
3131

32-
private static final List<String> IDE_PACKAGES =
33-
RuntimeBehavior.getIdePackageNames().stream()
32+
private static final List<String> PREFERENTIAL_PACKAGES =
33+
RuntimeBehavior.getPreferentialListeners().stream()
3434
.map(each -> each.replaceAll("\\Q.*\\E", ""))
3535
.collect(Collectors.toList());
3636

37-
private static final Predicate<Class<?>> IDE_LISTENER =
38-
clazz -> IDE_PACKAGES.stream().anyMatch(each -> clazz.getPackage().getName().contains(each));
37+
private static final Predicate<Class<?>> SHOULD_ADD_AT_END =
38+
clazz ->
39+
PREFERENTIAL_PACKAGES.stream()
40+
.anyMatch(each -> clazz.getPackage().getName().contains(each));
3941

4042
/**
4143
* @param original - The original collection of listeners
42-
* @return - A re-ordered collection wherein TestNG's known listeners are added at the end
44+
* @return - A re-ordered collection wherein preferential listeners are added at the end
4345
*/
4446
public static <T> List<T> order(Collection<T> original) {
4547
Pair<List<T>, List<T>> ordered = arrange(original);
@@ -51,34 +53,30 @@ public static <T> List<T> order(Collection<T> original) {
5153
/**
5254
* @param original - The original collection of listeners
5355
* @return - A reversed ordered list wherein the user listeners are found in reverse order
54-
* followed by TestNG known listeners also in reverse order.
56+
* followed by preferential listeners also in reverse order.
5557
*/
5658
public static <T> List<T> reversedOrder(Collection<T> original) {
5759
Pair<List<T>, List<T>> ordered = arrange(original);
58-
List<T> ideListeners = ordered.first();
60+
List<T> preferentialListeners = ordered.first();
5961
List<T> regularListeners = ordered.second();
6062
Collections.reverse(regularListeners);
61-
Collections.reverse(ideListeners);
62-
return Lists.merge(regularListeners, ideListeners);
63-
}
64-
65-
private static boolean isIDEListener(Class<?> clazz) {
66-
return IDE_LISTENER.test(clazz);
63+
Collections.reverse(preferentialListeners);
64+
return Lists.merge(regularListeners, preferentialListeners);
6765
}
6866

6967
private static <T> Pair<List<T>, List<T>> arrange(Collection<T> original) {
70-
List<T> ideListeners = new ArrayList<>();
68+
List<T> preferentialListeners = new ArrayList<>();
7169
List<T> regularListeners = new ArrayList<>();
7270
original.stream()
7371
.filter(Objects::nonNull)
7472
.forEach(
7573
each -> {
76-
if (isIDEListener(each.getClass())) {
77-
ideListeners.add(each);
74+
if (SHOULD_ADD_AT_END.test(each.getClass())) {
75+
preferentialListeners.add(each);
7876
} else {
7977
regularListeners.add(each);
8078
}
8179
});
82-
return new Pair<>(ideListeners, regularListeners);
80+
return new Pair<>(preferentialListeners, regularListeners);
8381
}
8482
}

0 commit comments

Comments
 (0)