[testng] 79/355: Suite Listener is registered twice (#557)
Eugene Zhukov
eugene-guest at moszumanska.debian.org
Tue Aug 18 10:19:50 UTC 2015
This is an automated email from the git hooks/post-receive script.
eugene-guest pushed a commit to annotated tag OpenBSD
in repository testng.
commit a21c2f6b471c550402a4db5abcddb11bcc3dba5d
Author: miheys <mihails.volkovs at gmail.com>
Date: Wed Oct 8 18:50:11 2014 +0300
Suite Listener is registered twice (#557)
---
src/main/java/org/testng/SuiteRunner.java | 6 ++-
src/main/java/org/testng/TestNG.java | 2 +-
.../SuiteAndConfigurationListenerTest.java | 58 ++++++++++++++++++++++
src/test/resources/testng.xml | 1 +
4 files changed, 65 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/testng/SuiteRunner.java b/src/main/java/org/testng/SuiteRunner.java
index d1fa95c..94d78d4 100644
--- a/src/main/java/org/testng/SuiteRunner.java
+++ b/src/main/java/org/testng/SuiteRunner.java
@@ -334,6 +334,10 @@ public class SuiteRunner implements ISuite, Serializable, IInvokedMethodListener
m_reporters.add(listener);
}
+ void addConfigurationListener(IConfigurationListener listener) {
+ m_configuration.addConfigurationListener(listener);
+ }
+
public List<IReporter> getReporters() {
return m_reporters;
}
@@ -405,7 +409,7 @@ public class SuiteRunner implements ISuite, Serializable, IInvokedMethodListener
addReporter((IReporter) listener);
}
if (listener instanceof IConfigurationListener) {
- m_configuration.addConfigurationListener((IConfigurationListener) listener);
+ addConfigurationListener((IConfigurationListener) listener);
}
}
diff --git a/src/main/java/org/testng/TestNG.java b/src/main/java/org/testng/TestNG.java
index 35844c1..442590a 100644
--- a/src/main/java/org/testng/TestNG.java
+++ b/src/main/java/org/testng/TestNG.java
@@ -1313,7 +1313,7 @@ public class TestNG {
}
for (IConfigurationListener cl : m_configuration.getConfigurationListeners()) {
- result.addListener(cl);
+ result.addConfigurationListener(cl);
}
return result;
diff --git a/src/test/java/test/listeners/SuiteAndConfigurationListenerTest.java b/src/test/java/test/listeners/SuiteAndConfigurationListenerTest.java
new file mode 100644
index 0000000..f4130aa
--- /dev/null
+++ b/src/test/java/test/listeners/SuiteAndConfigurationListenerTest.java
@@ -0,0 +1,58 @@
+package test.listeners;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.testng.Assert;
+import org.testng.IConfigurationListener;
+import org.testng.ISuite;
+import org.testng.ISuiteListener;
+import org.testng.ITestResult;
+import org.testng.annotations.Listeners;
+import org.testng.annotations.Test;
+
+import test.listeners.SuiteAndConfigurationListenerTest.MyListener;
+
+/**
+ * Check that if a listener implements IConfigurationListener additionally to
+ * ISuiteListener, ISuiteListener gets invoked exactly once.
+ *
+ * @author Mihails Volkovs
+ */
+ at Listeners(MyListener.class)
+public class SuiteAndConfigurationListenerTest {
+ public static class MyListener implements ISuiteListener, IConfigurationListener {
+
+ private static volatile AtomicInteger started = new AtomicInteger(0);
+
+ public MyListener() {
+ }
+
+ @Override
+ public void onStart(ISuite suite) {
+ started.incrementAndGet();
+ }
+
+ @Override
+ public void onFinish(ISuite suite) {
+ }
+
+ @Override
+ public void onConfigurationSuccess(ITestResult itr) {
+ }
+
+ @Override
+ public void onConfigurationFailure(ITestResult itr) {
+ }
+
+ @Override
+ public void onConfigurationSkip(ITestResult itr) {
+ }
+
+ }
+
+ @Test
+ public void bothListenersShouldRun() {
+ Assert.assertEquals(MyListener.started.get(), 1, "ISuiteListener was not invoked exactly once:");
+ }
+
+}
diff --git a/src/test/resources/testng.xml b/src/test/resources/testng.xml
index ca8b566..9794953 100644
--- a/src/test/resources/testng.xml
+++ b/src/test/resources/testng.xml
@@ -143,6 +143,7 @@
<class name="test.listeners.ResultEndMillisTest" />
<class name="test.listeners.ListenerTest"/>
<class name="test.listeners.SuiteAndInvokedMethodListenerTest" />
+ <class name="test.listeners.SuiteAndConfigurationListenerTest" />
<class name="test.listeners.ListenerInXmlTest" />
<class name="test.listeners.ExecutionListenerTest" />
<class name="test.listeners.ConfigurationListenerTest" />
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/testng.git
More information about the pkg-java-commits
mailing list