1 package org.apache.maven.shared.utils.cli;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Arrays;
23 import java.util.HashMap;
24 import java.util.Locale;
25 import java.util.Map;
26 import java.util.Properties;
27 import org.apache.maven.shared.utils.Os;
28
29 import junit.framework.TestCase;
30
31 @SuppressWarnings( { "JavaDoc", "deprecation" } )
32 public class CommandLineUtilsTest
33 extends TestCase
34 {
35
36
37
38
39
40 public void testGetSystemEnvVarsCaseInsensitive()
41 {
42 Properties vars = CommandLineUtils.getSystemEnvVars( false );
43 for ( Object o : vars.keySet() )
44 {
45 String variable = (String) o;
46 assertEquals( variable.toUpperCase( Locale.ENGLISH ), variable );
47 }
48 }
49
50 public void testEnsureCaseSensitivity()
51 throws Exception
52 {
53 Map<String, String> data = new HashMap<String, String>();
54 data.put( "abz", "cool" );
55 assertTrue( CommandLineUtils.ensureCaseSensitivity( data, false ).containsKey( "ABZ" ) );
56 assertTrue( CommandLineUtils.ensureCaseSensitivity( data, true ).containsKey( "abz" ) );
57 }
58
59
60
61
62 public void testGetSystemEnvVarsWindows()
63 throws Exception
64 {
65 if ( !Os.isFamily( Os.FAMILY_WINDOWS ) )
66 {
67 return;
68 }
69 Properties vars = CommandLineUtils.getSystemEnvVars();
70 for ( Object o : vars.keySet() )
71 {
72 String variable = (String) o;
73 assertEquals( variable.toUpperCase( Locale.ENGLISH ), variable );
74 }
75 }
76
77
78
79
80 public void testTranslateCommandline()
81 throws Exception
82 {
83 assertCmdLineArgs( new String[] {}, null );
84 assertCmdLineArgs( new String[] {}, "" );
85
86 assertCmdLineArgs( new String[] { "foo", "bar" }, "foo bar" );
87 assertCmdLineArgs( new String[] { "foo", "bar" }, " foo bar " );
88
89 assertCmdLineArgs( new String[] { "foo", " double quotes ", "bar" }, "foo \" double quotes \" bar" );
90 assertCmdLineArgs( new String[] { "foo", " single quotes ", "bar" }, "foo ' single quotes ' bar" );
91
92 assertCmdLineArgs( new String[] { "foo", " \" ", "bar" }, "foo ' \" ' bar" );
93 assertCmdLineArgs( new String[] { "foo", " ' ", "bar" }, "foo \" ' \" bar" );
94 }
95
96 private void assertCmdLineArgs( String[] expected, String cmdLine )
97 throws Exception
98 {
99 String[] actual = CommandLineUtils.translateCommandline( cmdLine );
100 assertNotNull( actual );
101 assertEquals( expected.length, actual.length );
102 assertEquals( Arrays.asList( expected ), Arrays.asList( actual ) );
103 }
104
105 }