View Javadoc
1   package org.apache.maven.scm.provider.git.gitexe.command;
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 static org.junit.Assert.assertEquals;
23  import static org.junit.Assume.assumeTrue;
24  
25  import java.io.File;
26  import java.util.Arrays;
27  import java.util.List;
28  
29  import org.codehaus.plexus.util.Os;
30  import org.codehaus.plexus.util.cli.Commandline;
31  import org.junit.Test;
32  
33  /**
34   * @author mfriedenhagen
35   */
36  public class GitCommandLineUtilsAddTargetTest
37  {
38  
39      /**
40       * Test of addTarget method, of class GitCommandLineUtils on Non-Windows systems.
41       */
42      @Test
43      public void testAddTargetNonWindows()
44      {
45          assumeTrue( !runsOnWindows() );
46          final File workingDir = new File( "/prj" );
47          final List<File> filesToAdd = Arrays.asList( new File( "/prj/pom.xml" ), new File( "/prj/mod1/pom.xml" ) );
48          final String expectedArguments = "[add, pom.xml, mod1/pom.xml]";
49          check( workingDir, filesToAdd, expectedArguments );
50      }
51  
52      /**
53       * Test of addTarget method, of class GitCommandLineUtils on Windows.
54       */
55      @Test
56      public void testAddTargetWindows()
57      {
58          assumeTrue( runsOnWindows() );
59          final File workingDir = new File( "C:\\prj" );
60          // Note that the second file has a lowercase drive letter, see https://jira.codehaus.org/browse/SCM-667
61          final List<File> filesToAdd =
62              Arrays.asList( new File( "C:\\prj\\pom.xml" ), new File( "c:\\prj\\mod1\\pom.xml" ) );
63          final String expectedArguments = "[add, pom.xml, mod1\\pom.xml]";
64          check( workingDir, filesToAdd, expectedArguments );
65      }
66  
67      private void check( final File workingDir, final List<File> filesToAdd, final String expectedArguments )
68      {
69          final Commandline cl = GitCommandLineUtils.getBaseGitCommandLine( workingDir, "add" );
70          GitCommandLineUtils.addTarget( cl, filesToAdd );
71          final String arguments = Arrays.toString( cl.getArguments() );
72          assertEquals( 3, cl.getArguments().length );
73          assertEquals( expectedArguments, arguments );
74      }
75  
76      private boolean runsOnWindows()
77      {
78          return Os.isFamily( Os.FAMILY_WINDOWS );
79      }
80  }