1 package org.apache.maven.scm.provider.git.gitexe.command;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
35
36 public class GitCommandLineUtilsAddTargetTest
37 {
38
39
40
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
54
55 @Test
56 public void testAddTargetWindows()
57 {
58 assumeTrue( runsOnWindows() );
59 final File workingDir = new File( "C:\\prj" );
60
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 }