1 package org.apache.maven.plugin.failsafe;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
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 }