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.mockito.Mockito.mock;
34  import static org.mockito.Mockito.spy;
35  import static org.mockito.Mockito.when;
36  import static org.fest.assertions.Assertions.assertThat;
37  
38  /**
39   * @since 2.20
40   */
41  public class IntegrationTestMojoTest
42  {
43      private IntegrationTestMojo mojo;
44  
45      @Before
46      public void init() throws InvalidVersionSpecificationException, IOException
47      {
48          Artifact artifact = new DefaultArtifact( "g", "a", createFromVersionSpec( "1.0" ), "compile", "jar", "", null );
49          artifact.setFile( new File( "./target/tmp/a-1.0.jar" ) );
50          new File( "./target/tmp" ).mkdir();
51          artifact.getFile().createNewFile();
52          mojo = spy( IntegrationTestMojo.class );
53          MavenProject project = mock( MavenProject.class );
54          when( project.getArtifact() ).thenReturn( artifact );
55          when( mojo.getProject() ).thenReturn( project );
56      }
57  
58      @Test
59      public void shouldBeJar()
60      {
61          mojo.setDefaultClassesDirectory( new File( "./target/classes" ) );
62          File binaries = mojo.getClassesDirectory();
63          assertThat( binaries.getName() ).isEqualTo( "a-1.0.jar" );
64      }
65  
66      @Test
67      public void shouldBeAnotherJar()
68      {
69          mojo.setClassesDirectory( new File( "./target/another-1.0.jar" ) );
70          mojo.setDefaultClassesDirectory( new File( "./target/classes" ) );
71          File binaries = mojo.getClassesDirectory();
72          assertThat( binaries.getName() ).isEqualTo( "another-1.0.jar" );
73      }
74  
75      @Test
76      public void shouldBeClasses()
77      {
78          mojo.setClassesDirectory( new File( "./target/classes" ) );
79          mojo.setDefaultClassesDirectory( new File( "./target/classes" ) );
80          File binaries = mojo.getClassesDirectory();
81          assertThat( binaries.getName() ).isEqualTo( "classes" );
82      }
83  }