View Javadoc
1   package org.apache.maven.surefire.its;
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 LicenseUni.
20   */
21  
22  import org.apache.maven.surefire.its.fixture.OutputValidator;
23  import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
24  import org.apache.maven.surefire.its.fixture.SurefireLauncher;
25  import org.apache.maven.surefire.its.fixture.TestFile;
26  import org.junit.Test;
27  
28  import java.io.File;
29  
30  import static org.apache.commons.io.Charsets.UTF_8;
31  import static org.apache.maven.surefire.its.fixture.HelperAssertions.convertUnicodeToUTF8;
32  import static org.junit.Assert.assertFalse;
33  import static org.junit.Assert.assertTrue;
34  import static org.junit.Assume.assumeFalse;
35  
36  /**
37   * Verifies unicode filenames pass through correctly.
38   */
39  public class UnicodeTestNamesIT
40          extends SurefireJUnit4IntegrationTestCase
41  {
42      private static final String REPORT_FILE_CONTENT = "junit.twoTestCases.\u800C\u7D22\u5176\u60C5Test";
43      private static final String TXT_REPORT = "junit.twoTestCases.\u800C\u7D22\u5176\u60C5Test.txt";
44      private static final String XML_REPORT = "TEST-junit.twoTestCases.\u800C\u7D22\u5176\u60C5Test.xml";
45  
46      @Test
47      public void checkFileNamesWithUnicode()
48      {
49          SurefireLauncher unpacked = unpack( "unicode-testnames" );
50          File basedir = unpacked.getUnpackedAt();
51  
52          unpacked.execute( "clean" );
53  
54          File xxyz = new File( basedir, "src/test/java/junit/twoTestCases/XXYZTest.java" );
55          File dest = new File( basedir, "src/test/java/junit/twoTestCases/\u800C\u7D22\u5176\u60C5Test.java" );
56  
57          //noinspection ResultOfMethodCallIgnored
58          dest.delete();
59          assertTrue( xxyz.renameTo( dest ) );
60  
61          assertTrue( dest.exists() );
62          assumeFalse( new File( basedir, "src/test/java/junit/twoTestCases/????Test.java" ).exists() );
63  
64          OutputValidator outputValidator =
65                  unpacked.executeTest()
66                          .assertTestSuiteResults( 2, 0, 0, 0 );
67  
68          TestFile surefireReportFile = outputValidator.getSurefireReportsFile( TXT_REPORT, UTF_8 );
69          assertTrue( surefireReportFile.exists() );
70  
71          // See src/test/resources/unicode-testnames/pom.xml and property project.build.sourceEncoding set to UTF-8.
72          surefireReportFile.assertContainsText( convertUnicodeToUTF8( REPORT_FILE_CONTENT ) );
73  
74          TestFile surefireXmlReportFile = outputValidator.getSurefireReportsXmlFile( XML_REPORT );
75          assertTrue( surefireXmlReportFile.exists() );
76          assertFalse( surefireXmlReportFile.readFileToString().isEmpty() );
77  
78          // See src/test/resources/unicode-testnames/pom.xml and property project.build.sourceEncoding set to UTF-8.
79          surefireXmlReportFile.assertContainsText( convertUnicodeToUTF8( REPORT_FILE_CONTENT ) );
80      }
81  }