1 package test.issue107;
2 
3 import org.testng.Assert;
4 import org.testng.TestListenerAdapter;
5 import org.testng.TestNG;
6 import org.testng.annotations.Test;
7 import org.testng.xml.XmlSuite;
8 import org.testng.xml.XmlTest;
9 import test.SimpleBaseTest;
10 
11 import java.util.Arrays;
12 import java.util.Map;
13 
14 /**
15  * @author Vladislav.Rassokhin
16  */
17 public class Issue107Test extends SimpleBaseTest {
18 
19   @Test(description = "GITHUB-107, Check that suite parameters set from listener does not affects tests count")
testSuiteParameterModificationFromListener()20   public void testSuiteParameterModificationFromListener() throws Exception {
21     final XmlSuite suite = createXmlSuite("Simple suite");
22 
23     final Map<String, String> parameters = suite.getParameters();
24     parameters.put(TestTestngCounter.PARAMETER_NAME, "some value that must be overriden in listener");
25     suite.setParameters(parameters);
26 
27     runTest(suite);
28   }
29 
30   @Test(description = "GITHUB-107, Check that suite parameters modification from listener does not affects tests count")
testSuiteParameterSetFromListener()31   public void testSuiteParameterSetFromListener() throws Exception {
32     final XmlSuite suite = createXmlSuite("Simple suite");
33 
34     runTest(suite);
35   }
36 
runTest(XmlSuite suite)37   private void runTest(XmlSuite suite) {
38     final XmlTest test = createXmlTest(suite, "Simple Test", TestTestngCounter.class.getName());
39     suite.setTests(Arrays.asList(test));
40 
41     final TestListenerAdapter tla = new TestListenerAdapter();
42     final TestNG tng = create();
43     tng.setXmlSuites(Arrays.asList(suite));
44     tng.addListener(tla);
45     tng.run();
46 
47     Assert.assertEquals(tla.getFailedTests().size(), 0);
48     Assert.assertEquals(tla.getPassedTests().size(), 2);
49   }
50 }
51