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