View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.surefire.testng.conf;
20  
21  import java.util.HashMap;
22  import java.util.Map;
23  
24  import junit.framework.TestCase;
25  import org.apache.maven.surefire.api.testset.TestSetFailedException;
26  
27  import static org.apache.maven.surefire.testng.conf.TestNGMapConfiguratorTest.FIRST_LISTENER;
28  import static org.apache.maven.surefire.testng.conf.TestNGMapConfiguratorTest.LISTENER_PROP;
29  import static org.apache.maven.surefire.testng.conf.TestNGMapConfiguratorTest.SECOND_LISTENER;
30  
31  /**
32   *
33   */
34  public class TestNG5143ConfiguratorTest extends TestCase {
35      public void testListenersOnSeparateLines() throws Exception {
36          String listenersOnSeveralLines = String.format("%s , %n %s", FIRST_LISTENER, SECOND_LISTENER);
37          Map convertedOptions = getConvertedOptions(LISTENER_PROP, listenersOnSeveralLines);
38          String listeners = (String) convertedOptions.get(String.format("-%s", LISTENER_PROP));
39          assertEquals(FIRST_LISTENER + "," + SECOND_LISTENER, listeners);
40      }
41  
42      public void testListenersOnTheSameLine() throws Exception {
43          String listenersOnSeveralLines = String.format("%s,%s", FIRST_LISTENER, SECOND_LISTENER);
44          Map convertedOptions = getConvertedOptions(LISTENER_PROP, listenersOnSeveralLines);
45          String listeners = (String) convertedOptions.get(String.format("-%s", LISTENER_PROP));
46          assertEquals(FIRST_LISTENER + "," + SECOND_LISTENER, listeners);
47      }
48  
49      public void testReporter() throws Exception {
50          Map<String, Object> convertedOptions = getConvertedOptions("reporter", "classname");
51          assertNull("classname", convertedOptions.get("-reporterslist"));
52          String reporter = (String) convertedOptions.get("-reporter");
53          assertEquals("classname", reporter);
54      }
55  
56      private Map getConvertedOptions(String key, String value) throws TestSetFailedException {
57          TestNGMapConfigurator testNGMapConfigurator = new TestNG5143Configurator();
58          Map<String, String> raw = new HashMap<>();
59          raw.put(key, value);
60          return testNGMapConfigurator.getConvertedOptions(raw);
61      }
62  }