View Javadoc
1   package org.apache.maven.shared.verifier;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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  }