View Javadoc
1   package org.apache.maven.plugin.failsafe;
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 org.apache.maven.artifact.Artifact;
23  import org.apache.maven.artifact.DefaultArtifact;
24  import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
25  import org.apache.maven.project.MavenProject;
26  import org.junit.Before;
27  import org.junit.Test;
28  
29  import java.io.File;
30  import java.io.IOException;
31  
32  import static org.apache.maven.artifact.versioning.VersionRange.createFromVersionSpec;
33  import static org.fest.assertions.Assertions.assertThat;
34  import static org.mockito.Mockito.mock;
35  import static org.mockito.Mockito.when;
36  
37  /**
38   * @since 2.20
39   */
40  public class IntegrationTestMojoTest
41  {
42      private IntegrationTestMojo mojo;
43  
44      @Before
45      public void init() throws InvalidVersionSpecificationException, IOException
46      {
47          Artifact artifact = new DefaultArtifact( "g", "a", createFromVersionSpec( "1.0" ), "compile", "jar", "", null );
48          artifact.setFile( new File( "./target/tmp/a-1.0.jar" ) );
49          new File( "./target/tmp" ).mkdir();
50          artifact.getFile().createNewFile();
51          mojo = new IntegrationTestMojo();
52          MavenProject project = mock( MavenProject.class );
53          when( project.getArtifact() ).thenReturn( artifact );
54          mojo.setProject( project );
55      }
56  
57      @Test
58      public void shouldBeJar()
59      {
60          mojo.setDefaultClassesDirectory( new File( "./target/classes" ) );
61          File binaries = mojo.getMainBuildPath();
62          assertThat( binaries.getName() ).isEqualTo( "a-1.0.jar" );
63      }
64  
65      @Test
66      public void shouldBeAnotherJar()
67      {
68          mojo.setMainBuildPath( new File( "./target/another-1.0.jar" ) );
69          mojo.setDefaultClassesDirectory( new File( "./target/classes" ) );
70          File binaries = mojo.getMainBuildPath();
71          assertThat( binaries.getName() ).isEqualTo( "another-1.0.jar" );
72      }
73  
74      @Test
75      public void shouldBeClasses()
76      {
77          mojo.setMainBuildPath( new File( "./target/classes" ) );
78          mojo.setDefaultClassesDirectory( new File( "./target/classes" ) );
79          File binaries = mojo.getMainBuildPath();
80          assertThat( binaries.getName() ).isEqualTo( "classes" );
81      }
82  
83      @Test
84      public void shouldGetNullEnv()
85      {
86          assertThat( mojo.getExcludedEnvironmentVariables() )
87                  .hasSize( 0 );
88      }
89  
90      @Test
91      public void shouldGetEnv()
92      {
93          mojo.setExcludedEnvironmentVariables( new String[] { "ABC", "KLM" } );
94          assertThat( mojo.getExcludedEnvironmentVariables() )
95                  .hasSize( 2 )
96                  .contains( "ABC", "KLM" );
97      }
98  
99      @Test
100     public void testShouldGetPropertyFile()
101     {
102         mojo.setSystemPropertiesFile( new File( "testShouldGetPropertyFile" ) );
103         assertThat( mojo.getSystemPropertiesFile() )
104                 .isEqualTo( new File( "testShouldGetPropertyFile" ) );
105     }
106 }