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 junit.framework.TestCase;
23  import org.apache.maven.surefire.testset.TestSetFailedException;
24  
25  import java.util.HashMap;
26  import java.util.Map;
27  
28  import static org.apache.maven.surefire.testng.conf.TestNGMapConfiguratorTest.FIRST_LISTENER;
29  import static org.apache.maven.surefire.testng.conf.TestNGMapConfiguratorTest.LISTENER_PROP;
30  import static org.apache.maven.surefire.testng.conf.TestNGMapConfiguratorTest.SECOND_LISTENER;
31  
32  public class TestNG513ConfiguratorTest
33      extends TestCase
34  {
35  
36      public void testListenersOnSeparateLines()
37              throws Exception
38      {
39          String listenersOnSeveralLines = String.format( "%s , %n %s",
40                  FIRST_LISTENER, SECOND_LISTENER );
41          Map convertedOptions = getConvertedOptions( LISTENER_PROP, listenersOnSeveralLines );
42          String listeners = (String) convertedOptions.get( String.format( "-%s", LISTENER_PROP ) );
43          assertEquals( FIRST_LISTENER + "," + SECOND_LISTENER, listeners );
44      }
45  
46      public void testListenersOnTheSameLine()
47              throws Exception
48      {
49          String listenersOnSeveralLines = String.format( "%s,%s",
50                  FIRST_LISTENER, SECOND_LISTENER );
51          Map convertedOptions = getConvertedOptions( LISTENER_PROP, listenersOnSeveralLines );
52          String listeners = (String) convertedOptions.get( String.format( "-%s", LISTENER_PROP ) );
53          assertEquals( FIRST_LISTENER + "," + SECOND_LISTENER, listeners );
54      }
55  
56      public void testReporter()
57              throws Exception
58      {
59          Map<String, Object> convertedOptions = getConvertedOptions( "reporter", "classname" );
60          String reporter = (String) convertedOptions.get( "-reporterslist" );
61          assertEquals( "classname", reporter );
62      }
63  
64      private Map getConvertedOptions( String key, String value )
65              throws TestSetFailedException
66      {
67          TestNGMapConfigurator testNGMapConfigurator = new TestNG513Configurator();
68          Map<String, String> raw = new HashMap<>();
69          raw.put( key, value );
70          return testNGMapConfigurator.getConvertedOptions( raw );
71      }
72  }