1 package org.apache.maven.shared.verifier;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.nio.file.Files;
23 import java.nio.file.Path;
24 import java.nio.file.Paths;
25 import java.util.Properties;
26
27 import org.junit.jupiter.api.Test;
28 import org.junit.jupiter.api.io.TempDir;
29
30 import static org.hamcrest.MatcherAssert.assertThat;
31 import static org.hamcrest.Matchers.is;
32
33
34 public class Embedded3xLauncherTest
35 {
36 @TempDir
37 public Path temporaryDir;
38
39
40 private final String workingDir = Paths.get( "src/test/resources" ).toAbsolutePath().toString();
41
42 @Test
43 public void testWithClasspath() throws Exception
44 {
45 MavenLauncher launcher = Embedded3xLauncher.createFromClasspath();
46 runLauncher( launcher );
47 }
48
49 @Test
50 public void testWithMavenHome() throws Exception
51 {
52 MavenLauncher launcher = Embedded3xLauncher.createFromMavenHome(
53 System.getProperty( "maven.home" ), null, null );
54 runLauncher( launcher );
55 }
56
57 private void runLauncher( MavenLauncher launcher ) throws Exception
58 {
59 Path logFile = temporaryDir.resolve( "build.log" );
60
61 int exitCode = launcher.run( new String[] {"clean"}, new Properties(), workingDir, logFile.toFile() );
62
63 assertThat( "exit code unexpected, build log: " + System.lineSeparator() +
64 new String( Files.readAllBytes( logFile ) ), exitCode, is( 0 ) );
65 }
66 }