1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  package org.apache.maven.surefire.testng.conf;
20  
21  import java.util.HashMap;
22  import java.util.List;
23  import java.util.Map;
24  
25  import junit.framework.TestCase;
26  import org.apache.maven.surefire.api.testset.TestSetFailedException;
27  import org.testng.ReporterConfig;
28  
29  
30  
31  
32  public class TestNGMapConfiguratorTest extends TestCase {
33      public static final String FIRST_LISTENER = "org.testng.TestListenerAdapter";
34      public static final String SECOND_LISTENER = "org.testng.reporters.ExitCodeListener";
35      public static final String LISTENER_PROP = "listener";
36  
37      public void testGetConvertedOptions() throws Exception {
38          Map convertedOptions = getConvertedOptions("mixed", "true");
39          boolean bool = (Boolean) convertedOptions.get("-mixed");
40          assertTrue(bool);
41      }
42  
43      public void testListenersOnSeparateLines() throws Exception {
44          String listenersOnSeveralLines = String.format("%s , %n %s", FIRST_LISTENER, SECOND_LISTENER);
45          Map convertedOptions = getConvertedOptions(LISTENER_PROP, listenersOnSeveralLines);
46          List listeners = (List) convertedOptions.get(String.format("-%s", LISTENER_PROP));
47          assertEquals(2, listeners.size());
48      }
49  
50      public void testListenersOnTheSameLine() throws Exception {
51          String listenersOnSeveralLines = String.format("%s,%s", FIRST_LISTENER, SECOND_LISTENER);
52          Map convertedOptions = getConvertedOptions(LISTENER_PROP, listenersOnSeveralLines);
53          List listeners = (List) convertedOptions.get(String.format("-%s", LISTENER_PROP));
54          assertEquals(2, listeners.size());
55      }
56  
57      public void testGroupByInstances() throws Exception {
58          Map convertedOptions = getConvertedOptions("group-by-instances", "true");
59          boolean bool = (Boolean) convertedOptions.get("-group-by-instances");
60          assertTrue(bool);
61      }
62  
63      public void testReporter() throws Exception {
64          Map<String, Object> convertedOptions = getConvertedOptions("reporter", "classname");
65          List<ReporterConfig> reporter = (List) convertedOptions.get("-reporterslist");
66          ReporterConfig reporterConfig = reporter.get(0);
67          assertEquals("classname", reporterConfig.getClassName());
68      }
69  
70      private Map getConvertedOptions(String key, String value) throws TestSetFailedException {
71          TestNGMapConfigurator testNGMapConfigurator = new TestNGMapConfigurator();
72          Map<String, String> raw = new HashMap<>();
73          raw.put(key, value);
74          return testNGMapConfigurator.getConvertedOptions(raw);
75      }
76  }