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.its.jiras;
20  
21  import org.apache.maven.surefire.its.fixture.OutputValidator;
22  import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
23  import org.apache.maven.surefire.its.fixture.SurefireLauncher;
24  import org.junit.Test;
25  
26  import static org.junit.Assert.assertFalse;
27  
28  /**
29   * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
30   * @see <a href="https://issues.apache.org/jira/browse/SUREFIRE-1053">SUREFIRE-1053</a>
31   * @since 2.18
32   */
33  public class Surefire1053SystemPropertiesIT extends SurefireJUnit4IntegrationTestCase {
34      @Test
35      public void checkWarningsFileEncoding() {
36          unpack().sysProp("file.encoding", "ISO-8859-1")
37                  .executeTest()
38                  .verifyErrorFree(1)
39                  .verifyTextInLog("file.encoding cannot be set as system property, use <argLine>-D"
40                          + "file.encoding=...</argLine> instead");
41      }
42  
43      @Test
44      public void checkWarningsSysPropTwice() throws Exception {
45          OutputValidator validator = unpack().argLine("-DmyArg=myVal2 -Dfile.encoding=ISO-8859-1")
46                  .sysProp("file.encoding", "ISO-8859-1")
47                  .executeTest()
48                  .verifyErrorFree(1)
49                  .verifyTextInLog("The system property myArg is configured twice! "
50                          + "The property appears in <argLine/> and any of <systemPropertyVariables/>, "
51                          + "<systemProperties/> or user property.");
52  
53          for (String line : validator.loadLogLines()) {
54              assertFalse(
55                      "no warning for file.encoding not in argLine",
56                      line.contains("file.encoding cannot be set as system property, use <argLine>"));
57              assertFalse(
58                      "no warning for double definition of file.encoding",
59                      line.contains("The system property file.encoding is configured twice!"));
60          }
61      }
62  
63      private SurefireLauncher unpack() {
64          return unpack("surefire-1053-system-properties");
65      }
66  }