View Javadoc
1   package org.apache.maven.surefire.testng.conf;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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  
30  /**
31   * @author Kristian Rosenvold
32   */
33  public class TestNGMapConfiguratorTest
34      extends TestCase
35  {
36      private static final String FIRST_LISTENER = "org.testng.TestListenerAdapter";
37      private static final String SECOND_LISTENER = "org.testng.reporters.ExitCodeListener";
38      public static final String LISTENER_PROP = "listener";
39  
40      public void testGetConvertedOptions()
41          throws Exception
42      {
43          Map convertedOptions = getConvertedOptions( "mixed", "true" );
44          Boolean bool = (Boolean) convertedOptions.get( "-mixed" );
45          assertTrue( bool.booleanValue() );
46      }
47  
48      public void testListenersOnSeparateLines()
49          throws Exception
50      {
51          String listenersOnSeveralLines = String.format( "%s , %n %s",
52                  FIRST_LISTENER, SECOND_LISTENER);
53          Map convertedOptions = getConvertedOptions(LISTENER_PROP, listenersOnSeveralLines);
54          List listeners = (List) convertedOptions.get( String.format("-%s", LISTENER_PROP));
55          assertEquals(2, listeners.size());
56      }
57  
58      public void testListenersOnTheSameLine()
59          throws Exception
60      {
61          String listenersOnSeveralLines = String.format( "%s,%s",
62                  FIRST_LISTENER, SECOND_LISTENER);
63          Map convertedOptions = getConvertedOptions( LISTENER_PROP, listenersOnSeveralLines);
64          List listeners = (List) convertedOptions.get( String.format("-%s", LISTENER_PROP));
65          assertEquals(2, listeners.size());
66      }
67  
68      public void testGroupByInstances()
69          throws Exception
70      {
71          Map convertedOptions = getConvertedOptions( "group-by-instances", "true" );
72          Boolean bool = (Boolean) convertedOptions.get( "-group-by-instances" );
73          assertTrue( bool.booleanValue() );
74      }
75  
76      private Map getConvertedOptions( String key, String value )
77          throws TestSetFailedException
78      {
79          TestNGMapConfigurator testNGMapConfigurator = new TestNGMapConfigurator();
80          Map raw = new HashMap();
81          raw.put( key, value );
82          return testNGMapConfigurator.getConvertedOptions( raw );
83      }
84  }