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