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.api.testset.TestSetFailedException;
24  
25  import java.util.HashMap;
26  import java.util.List;
27  import java.util.Map;
28  
29  import static org.apache.maven.surefire.testng.conf.TestNGMapConfiguratorTest.FIRST_LISTENER;
30  import static org.apache.maven.surefire.testng.conf.TestNGMapConfiguratorTest.LISTENER_PROP;
31  import static org.apache.maven.surefire.testng.conf.TestNGMapConfiguratorTest.SECOND_LISTENER;
32  
33  /**
34   *
35   */
36  public class TestNG5141ConfiguratorTest extends TestCase
37  {
38  
39      public void testListenersOnSeparateLines()
40      {
41          try
42          {
43              String listenersOnSeveralLines = String.format( "%s , %n %s", FIRST_LISTENER, SECOND_LISTENER );
44              Map convertedOptions = getConvertedOptions( LISTENER_PROP, listenersOnSeveralLines );
45              List listeners = (List) convertedOptions.get( String.format( "-%s", LISTENER_PROP ) );
46              assertEquals( 2, listeners.size() );
47              fail();
48          }
49          catch ( TestSetFailedException e )
50          {
51              // TODO remove it when surefire will use "configure(CommandLineArgs)"
52          }
53      }
54  
55      public void testListenersOnTheSameLine()
56      {
57          try
58          {
59              String listenersOnSeveralLines = String.format( "%s,%s", FIRST_LISTENER, SECOND_LISTENER );
60              Map convertedOptions = getConvertedOptions( LISTENER_PROP, listenersOnSeveralLines );
61              List listeners = (List) convertedOptions.get( String.format( "-%s", LISTENER_PROP ) );
62              assertEquals( 2, listeners.size() );
63              fail();
64          }
65          catch ( TestSetFailedException e )
66          {
67              // TODO remove it when surefire will use "configure(CommandLineArgs)"
68          }
69      }
70  
71      private Map getConvertedOptions( String key, String value ) throws TestSetFailedException
72      {
73          TestNGMapConfigurator testNGMapConfigurator = new TestNG5141Configurator();
74          Map<String, String> raw = new HashMap<>();
75          raw.put( key, value );
76          return testNGMapConfigurator.getConvertedOptions( raw );
77      }
78  }