View Javadoc
1   package org.apache.maven.plugin.surefire;
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 org.junit.Test;
23  
24  import java.util.ArrayList;
25  import java.util.List;
26  
27  import static java.util.Collections.addAll;
28  import static java.util.Collections.singleton;
29  import static org.apache.commons.lang3.SystemUtils.IS_OS_WINDOWS;
30  import static org.apache.maven.plugin.surefire.SurefireHelper.escapeToPlatformPath;
31  import static org.fest.assertions.Assertions.assertThat;
32  import static org.junit.Assume.assumeTrue;
33  
34  /**
35   * Test of {@link SurefireHelper}.
36   */
37  public class SurefireHelperTest
38  {
39      @Test
40      public void shouldBeThreeDumpFiles()
41      {
42          String[] dumps = SurefireHelper.getDumpFilesToPrint();
43          assertThat( dumps ).hasSize( 3 );
44          assertThat( dumps ).doesNotHaveDuplicates();
45          List<String> onlyStrings = new ArrayList<String>();
46          addAll( onlyStrings, dumps );
47          onlyStrings.removeAll( singleton( (String) null ) );
48          assertThat( onlyStrings ).hasSize( 3 );
49      }
50  
51      @Test
52      public void shouldCloneDumpFiles()
53      {
54          String[] dumps1 = SurefireHelper.getDumpFilesToPrint();
55          String[] dumps2 = SurefireHelper.getDumpFilesToPrint();
56          assertThat( dumps1 ).isNotSameAs( dumps2 );
57      }
58  
59      @Test
60      public void testConstants()
61      {
62          assertThat( SurefireHelper.DUMPSTREAM_FILENAME_FORMATTER )
63                  .isEqualTo( SurefireHelper.DUMP_FILE_PREFIX + "%d.dumpstream" );
64  
65          assertThat( String.format( SurefireHelper.DUMPSTREAM_FILENAME_FORMATTER, 5) )
66                  .endsWith( "-jvmRun5.dumpstream" );
67      }
68  
69      @Test
70      public void shouldEscapeWindowsPath()
71      {
72          assumeTrue( IS_OS_WINDOWS );
73          String root = "X:\\path\\to\\project\\";
74          String pathToJar = "target\\surefire\\surefirebooter4942721306300108667.jar";
75          int projectNameLength = 247 - root.length() - pathToJar.length();
76          StringBuilder projectFolder = new StringBuilder();
77          for ( int i = 0; i < projectNameLength; i++ )
78          {
79              projectFolder.append( 'x' );
80          }
81          String path = root + projectFolder + "\\" + pathToJar;
82          String escaped = escapeToPlatformPath( path );
83          assertThat( escaped ).isEqualTo( "\\\\?\\" + path );
84  
85          path = root + "\\" + pathToJar;
86          escaped = escapeToPlatformPath( path );
87          assertThat( escaped ).isEqualTo( root + "\\" + pathToJar );
88      }
89  }