View Javadoc
1   package org.apache.maven.scm.provider.git.gitexe.command.remove;
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.apache.maven.scm.ScmTestCase;
23  import org.codehaus.plexus.util.FileUtils;
24  import org.codehaus.plexus.util.cli.Commandline;
25  
26  import java.io.File;
27  import java.io.IOException;
28  import java.util.Arrays;
29  
30  /**
31   * @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
32   */
33  public class GitRemoveCommandTest
34      extends ScmTestCase
35  {
36  
37      public void testCommandRemoveWithFile()
38          throws Exception
39      {
40          File workingDirectory = createTempDirectory();
41  
42          File toBeRemoved = new File( workingDirectory.getAbsolutePath() + File.separator + "toto.xml" );
43          FileUtils.fileAppend( toBeRemoved.getAbsolutePath(), "data" );
44  
45          Commandline cl = GitRemoveCommand.createCommandLine( workingDirectory, Arrays.asList( toBeRemoved ) );
46  
47          assertCommandLine( "git rm toto.xml", workingDirectory, cl );
48  
49          FileUtils.deleteDirectory( workingDirectory );
50      }
51  
52      public void testCommandRemoveWithDirectory()
53          throws Exception
54      {
55          File workingDirectory = createTempDirectory();
56  
57          File toBeRemoved = new File( workingDirectory.getAbsolutePath() + File.separator + "toto" );
58          toBeRemoved.mkdir();
59  
60          Commandline cl = GitRemoveCommand.createCommandLine( workingDirectory, Arrays.asList( toBeRemoved ) );
61  
62          assertCommandLine( "git rm -r toto", workingDirectory, cl );
63  
64          FileUtils.deleteDirectory( workingDirectory );
65      }
66  
67      public void testCommandRemoveWithTwoDirectory()
68          throws Exception
69      {
70          File workingDirectory = createTempDirectory();
71  
72          File toBeRemoved1 = new File( workingDirectory.getAbsolutePath() + File.separator + "toto" );
73          toBeRemoved1.mkdir();
74  
75          File toBeRemoved2 = new File( workingDirectory.getAbsolutePath() + File.separator + "tata" );
76          toBeRemoved2.mkdir();
77  
78          Commandline cl =
79              GitRemoveCommand.createCommandLine( workingDirectory, Arrays.asList( toBeRemoved1, toBeRemoved2 ) );
80  
81          assertCommandLine( "git rm -r toto tata", workingDirectory, cl );
82  
83          FileUtils.deleteDirectory( workingDirectory );
84      }
85  
86      private File createTempDirectory()
87          throws IOException
88      {
89          File dir = File.createTempFile( "gitexe", "test" );
90          dir.delete();
91          dir.mkdir();
92          return dir;
93      }
94  }