View Javadoc
1   package org.apache.maven.scm.provider.git.gitexe.command.add;
2   
3   import java.io.File;
4   import java.util.ArrayList;
5   import java.util.List;
6   
7   import org.apache.maven.scm.ScmTestCase;
8   import org.codehaus.plexus.util.cli.Commandline;
9   
10  /*
11   * Licensed to the Apache Software Foundation (ASF) under one
12   * or more contributor license agreements.  See the NOTICE file
13   * distributed with this work for additional information
14   * regarding copyright ownership.  The ASF licenses this file
15   * to you under the Apache License, Version 2.0 (the
16   * "License"); you may not use this file except in compliance
17   * with the License.  You may obtain a copy of the License at
18   *
19   * http://www.apache.org/licenses/LICENSE-2.0
20   *
21   * Unless required by applicable law or agreed to in writing,
22   * software distributed under the License is distributed on an
23   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
24   * KIND, either express or implied.  See the License for the
25   * specific language governing permissions and limitations
26   * under the License.
27   */
28  
29  /**
30   * Check if the {@code GitAddCommand#createCommandLine(File, List)} returns the correct
31   * command line execution string.
32   * @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
33   *
34   */
35  public class GitExeAddCommandTest 
36      extends ScmTestCase 
37  {
38      
39      public void testAddCommandSingleFile() throws Exception
40      {
41          List<File> files = new ArrayList<File>();
42          
43          files.add( new File( "myFile.java" ) );
44          
45          testCommandLine( "scm:git:http://foo.com/git", files, "git add -- myFile.java" );
46      }
47      
48      public void testAddCommandMultipleFiles() throws Exception
49      {
50          List<File> files = new ArrayList<File>();
51          
52          files.add( new File( "myFile.java" ) );
53          files.add( new File( "myFile2.java" ) );
54          files.add( new File( "myFile3.java" ) );
55          
56          testCommandLine( "scm:git:http://foo.com/git", files, "git add -- myFile.java myFile2.java myFile3.java" );
57      }
58      
59      // ----------------------------------------------------------------------
60      // private helper functions
61      // ----------------------------------------------------------------------
62  
63      private void testCommandLine( String scmUrl, List<File> files, String commandLine )
64          throws Exception
65      {
66          File workingDirectory = getTestFile( "target/git-add-command-test" );
67  
68          Commandline cl = GitAddCommand.createCommandLine(workingDirectory, files );
69  
70          assertCommandLine( commandLine, workingDirectory, cl );
71      }
72  
73  }