Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue #1400: don't add duplicate reporter #1404

Merged
merged 3 commits into from
Apr 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Fixed: GITHUB-1365: Be able to override default XML parser (@ChristiKh & Julien
Fixed: GITHUB-1360: TestNG does not distinguish between methods of different priorities (Krishnan Mahadevan)
Fixed: GITHUB-1144: Add Class and Constructor as legal native dependency injection (Guillaume Juillot)
Fixed: GITHUB-1380: Circular dependencies may fail in parallel (Julien Herr)
Fixed: GITHUB-1400: TestNG, Multiple duplicate listener warnings on implementing multiple listener interfaces (@bipo1980 & Nick Tan)

6.11
2017/02/27
Expand Down
26 changes: 16 additions & 10 deletions src/main/java/org/testng/TestNG.java
Original file line number Diff line number Diff line change
Expand Up @@ -704,9 +704,15 @@ public void addListener(Object listener) {
addListener((ITestNGListener) listener);
}

private static <E> void maybeAddListener(Map<Class<? extends E>, E> map, Class<? extends E> type, E value) {
if (map.containsKey(value.getClass())) {
LOGGER.warn("Ignoring duplicate listener : " + value.getClass().getName());
private static <E> void maybeAddListener(Map<Class<? extends E>, E> map, E value) {
maybeAddListener(map, (Class<? extends E>) value.getClass(), value, false);
}

private static <E> void maybeAddListener(Map<Class<? extends E>, E> map, Class<? extends E> type, E value, boolean quiet) {
if (map.containsKey(type)) {
if (!quiet) {
LOGGER.warn("Ignoring duplicate listener : " + type.getName());
}
} else {
map.put(type, value);
}
Expand All @@ -718,19 +724,19 @@ public void addListener(ITestNGListener listener) {
}
if (listener instanceof ISuiteListener) {
ISuiteListener suite = (ISuiteListener) listener;
maybeAddListener(m_suiteListeners, suite.getClass(), suite);
maybeAddListener(m_suiteListeners, suite);
}
if (listener instanceof ITestListener) {
ITestListener test = (ITestListener) listener;
maybeAddListener(m_testListeners, test.getClass(), test);
maybeAddListener(m_testListeners, test);
}
if (listener instanceof IClassListener) {
IClassListener clazz = (IClassListener) listener;
maybeAddListener(m_classListeners, clazz.getClass(), clazz);
maybeAddListener(m_classListeners, clazz);
}
if (listener instanceof IReporter) {
IReporter reporter = (IReporter) listener;
maybeAddListener(m_reporters, reporter.getClass(), reporter);
maybeAddListener(m_reporters, reporter);
}
if (listener instanceof IAnnotationTransformer) {
setAnnotationTransformer((IAnnotationTransformer) listener);
Expand All @@ -740,7 +746,7 @@ public void addListener(ITestNGListener listener) {
}
if (listener instanceof IInvokedMethodListener) {
IInvokedMethodListener method = (IInvokedMethodListener) listener;
maybeAddListener(m_invokedMethodListeners, method.getClass(), method);
maybeAddListener(m_invokedMethodListeners, method);
}
if (listener instanceof IHookable) {
setHookable((IHookable) listener);
Expand All @@ -756,7 +762,7 @@ public void addListener(ITestNGListener listener) {
}
if (listener instanceof IAlterSuiteListener) {
IAlterSuiteListener alter = (IAlterSuiteListener) listener;
maybeAddListener(m_alterSuiteListeners, alter.getClass(), alter);
maybeAddListener(m_alterSuiteListeners, alter);
}
}

Expand Down Expand Up @@ -1394,7 +1400,7 @@ private SuiteRunner createSuiteRunner(XmlSuite xmlSuite) {
}

for (IReporter r : result.getReporters()) {
addListener(r);
maybeAddListener(m_reporters, r.getClass(), r, true);
}

for (IConfigurationListener cl : m_configuration.getConfigurationListeners()) {
Expand Down