1 package org.apache.maven.plugin.surefire.booterclient;
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 import java.io.IOException;
24 import java.util.Collections;
25
26 import org.apache.maven.shared.utils.StringUtils;
27 import org.apache.maven.shared.utils.cli.Commandline;
28 import org.apache.maven.surefire.booter.Classpath;
29 import org.apache.maven.surefire.booter.SurefireBooterForkException;
30
31 import junit.framework.TestCase;
32
33 public class ForkConfigurationTest
34 extends TestCase
35 {
36
37 public void testCreateCommandLine_UseSystemClassLoaderForkOnce_ShouldConstructManifestOnlyJar()
38 throws IOException, SurefireBooterForkException
39 {
40 ForkConfiguration config = getForkConfiguration( null, "java" );
41 File cpElement = getTempClasspathFile();
42
43 Commandline cli =
44 config.createCommandLine( Collections.singletonList( cpElement.getAbsolutePath() ), true, false, null, 1 );
45
46 String line = StringUtils.join( cli.getCommandline(), " " );
47 assertTrue( line.contains( "-jar" ) );
48 }
49
50 public void testArglineWithNewline()
51 throws IOException, SurefireBooterForkException
52 {
53
54 File cpElement = getTempClasspathFile();
55 ForkConfiguration forkConfiguration = getForkConfiguration( "abc\ndef", null );
56
57 final Commandline commandLine =
58 forkConfiguration.createCommandLine( Collections.singletonList( cpElement.getAbsolutePath() ), false, false,
59 null, 1 );
60 assertTrue( commandLine.toString().contains( "abc def" ) );
61 }
62
63 private File getTempClasspathFile()
64 throws IOException
65 {
66 File cpElement = File.createTempFile( "ForkConfigurationTest.", ".file" );
67 cpElement.deleteOnExit();
68 return cpElement;
69 }
70
71 public static ForkConfiguration getForkConfiguration( String argLine, String jvm )
72 throws IOException
73 {
74 return new ForkConfiguration( Classpath.emptyClasspath(), null, null, jvm, new File( "." ).getCanonicalFile(), argLine,
75 null, false, 1, false );
76 }
77
78 }