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 throws Exception
42 {
43 Properties vars = CommandLineUtils.getSystemEnvVars( false );
44 for ( Object o : vars.keySet() )
45 {
46 String variable = (String) o;
47 assertEquals( variable.toUpperCase( Locale.ENGLISH ), variable );
48 }
49 }
50
51 public void testEnsureCaseSensitivity()
52 throws Exception
53 {
54 Map<String, String> data = new HashMap<String, String>();
55 data.put( "abz", "cool" );
56 assertTrue( CommandLineUtils.ensureCaseSensitivity( data, false ).containsKey( "ABZ" ) );
57 assertTrue( CommandLineUtils.ensureCaseSensitivity( data, true ).containsKey( "abz" ) );
58 }
59
60
61
62
63 public void testGetSystemEnvVarsWindows()
64 throws Exception
65 {
66 if ( !Os.isFamily( Os.FAMILY_WINDOWS ) )
67 {
68 return;
69 }
70 Properties vars = CommandLineUtils.getSystemEnvVars();
71 for ( Object o : vars.keySet() )
72 {
73 String variable = (String) o;
74 assertEquals( variable.toUpperCase( Locale.ENGLISH ), variable );
75 }
76 }
77
78
79
80
81 public void testTranslateCommandline()
82 throws Exception
83 {
84 assertCmdLineArgs( new String[] {}, null );
85 assertCmdLineArgs( new String[] {}, "" );
86
87 assertCmdLineArgs( new String[] { "foo", "bar" }, "foo bar" );
88 assertCmdLineArgs( new String[] { "foo", "bar" }, " foo bar " );
89
90 assertCmdLineArgs( new String[] { "foo", " double quotes ", "bar" }, "foo \" double quotes \" bar" );
91 assertCmdLineArgs( new String[] { "foo", " single quotes ", "bar" }, "foo ' single quotes ' bar" );
92
93 assertCmdLineArgs( new String[] { "foo", " \" ", "bar" }, "foo ' \" ' bar" );
94 assertCmdLineArgs( new String[] { "foo", " ' ", "bar" }, "foo \" ' \" bar" );
95 }
96
97 private void assertCmdLineArgs( String[] expected, String cmdLine )
98 throws Exception
99 {
100 String[] actual = CommandLineUtils.translateCommandline( cmdLine );
101 assertNotNull( actual );
102 assertEquals( expected.length, actual.length );
103 assertEquals( Arrays.asList( expected ), Arrays.asList( actual ) );
104 }
105
106 }