1 package org.apache.maven.cli;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23
24 import junit.framework.TestCase;
25
26 import org.apache.commons.cli.ParseException;
27
28 public class MavenCliTest
29 extends TestCase
30 {
31 private MavenCli cli;
32
33 private String origBasedir;
34
35 protected void setUp()
36 {
37 cli = new MavenCli();
38 origBasedir = System.getProperty( MavenCli.MULTIMODULE_PROJECT_DIRECTORY );
39 }
40
41 @Override
42 protected void tearDown()
43 throws Exception
44 {
45 if ( origBasedir != null )
46 {
47 System.setProperty( MavenCli.MULTIMODULE_PROJECT_DIRECTORY, origBasedir );
48 }
49 else
50 {
51 System.getProperties().remove( MavenCli.MULTIMODULE_PROJECT_DIRECTORY );
52 }
53 super.tearDown();
54 }
55
56 public void testCalculateDegreeOfConcurrencyWithCoreMultiplier()
57 {
58 int cores = Runtime.getRuntime().availableProcessors();
59
60 assertEquals( (int) ( cores * 2.2 ), cli.calculateDegreeOfConcurrencyWithCoreMultiplier( "C2.2" ) );
61
62 assertEquals( (int) ( cores * 2.2 ), cli.calculateDegreeOfConcurrencyWithCoreMultiplier( "2.2C" ) );
63
64 try
65 {
66 cli.calculateDegreeOfConcurrencyWithCoreMultiplier( "CXXX" );
67 fail( "Should have failed with a NumberFormatException" );
68 }
69 catch ( NumberFormatException e )
70 {
71
72 }
73 }
74
75 public void testMavenConfig()
76 throws Exception
77 {
78 System.setProperty( MavenCli.MULTIMODULE_PROJECT_DIRECTORY, new File( "src/test/projects/config" ).getCanonicalPath() );
79 CliRequest request = new CliRequest( new String[0], null );
80
81
82 cli.initialize( request );
83 cli.cli( request );
84 assertEquals( "multithreaded", request.commandLine.getOptionValue( "builder" ) );
85 assertEquals( "8", request.commandLine.getOptionValue( "threads" ) );
86
87
88 request = new CliRequest( new String[] { "--builder", "foobar" }, null );
89 cli.cli( request );
90 assertEquals( "foobar", request.commandLine.getOptionValue( "builder" ) );
91 }
92
93 public void testMavenConfigInvalid()
94 throws Exception
95 {
96 System.setProperty( MavenCli.MULTIMODULE_PROJECT_DIRECTORY, new File( "src/test/projects/config-illegal" ).getCanonicalPath() );
97 CliRequest request = new CliRequest( new String[0], null );
98
99 cli.initialize( request );
100 try
101 {
102 cli.cli( request );
103 fail();
104 }
105 catch ( ParseException expected )
106 {
107
108 }
109 }
110 }