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