Skip to content

Commit

Permalink
Merge pull request #1404 from missedone/issue/1400
Browse files Browse the repository at this point in the history
issue #1400: don't add duplicate reporter
  • Loading branch information
cbeust authored Apr 7, 2017
2 parents 76c52be + 0454118 commit 1e1d341
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
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

0 comments on commit 1e1d341

Please sign in to comment.