View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugin.failsafe;
20  
21  import java.io.File;
22  import java.io.IOException;
23  
24  import org.apache.maven.artifact.Artifact;
25  import org.apache.maven.artifact.DefaultArtifact;
26  import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
27  import org.apache.maven.project.MavenProject;
28  import org.junit.Before;
29  import org.junit.Test;
30  
31  import static org.apache.maven.artifact.versioning.VersionRange.createFromVersionSpec;
32  import static org.assertj.core.api.Assertions.assertThat;
33  import static org.mockito.Mockito.mock;
34  import static org.mockito.Mockito.when;
35  
36  /**
37   * @since 2.20
38   */
39  public class IntegrationTestMojoTest {
40      private IntegrationTestMojo mojo;
41  
42      @Before
43      public void init() throws InvalidVersionSpecificationException, IOException {
44          Artifact artifact = new DefaultArtifact("g", "a", createFromVersionSpec("1.0"), "compile", "jar", "", null);
45          artifact.setFile(new File("./target/tmp/a-1.0.jar"));
46          new File("./target/tmp").mkdir();
47          artifact.getFile().createNewFile();
48          mojo = new IntegrationTestMojo();
49          MavenProject project = mock(MavenProject.class);
50          when(project.getArtifact()).thenReturn(artifact);
51          mojo.setProject(project);
52      }
53  
54      @Test
55      public void shouldBeJar() {
56          mojo.setDefaultClassesDirectory(new File("./target/classes"));
57          File binaries = mojo.getMainBuildPath();
58          assertThat(binaries.getName()).isEqualTo("a-1.0.jar");
59      }
60  
61      @Test
62      public void shouldBeAnotherJar() {
63          mojo.setMainBuildPath(new File("./target/another-1.0.jar"));
64          mojo.setDefaultClassesDirectory(new File("./target/classes"));
65          File binaries = mojo.getMainBuildPath();
66          assertThat(binaries.getName()).isEqualTo("another-1.0.jar");
67      }
68  
69      @Test
70      public void shouldBeClasses() {
71          mojo.setMainBuildPath(new File("./target/classes"));
72          mojo.setDefaultClassesDirectory(new File("./target/classes"));
73          File binaries = mojo.getMainBuildPath();
74          assertThat(binaries.getName()).isEqualTo("classes");
75      }
76  
77      @Test
78      public void shouldGetNullEnv() {
79          assertThat(mojo.getExcludedEnvironmentVariables()).hasSize(0);
80      }
81  
82      @Test
83      public void shouldGetEnv() {
84          mojo.setExcludedEnvironmentVariables(new String[] {"ABC", "KLM"});
85          assertThat(mojo.getExcludedEnvironmentVariables()).hasSize(2).contains("ABC", "KLM");
86      }
87  
88      @Test
89      public void testShouldGetPropertyFile() {
90          mojo.setSystemPropertiesFile(new File("testShouldGetPropertyFile"));
91          assertThat(mojo.getSystemPropertiesFile()).isEqualTo(new File("testShouldGetPropertyFile"));
92      }
93  
94      @Test
95      public void shouldHaveJUnit5EnginesFilter() {
96          mojo.setIncludeJUnit5Engines(new String[] {"e1", "e2"});
97          assertThat(mojo.getIncludeJUnit5Engines()).isEqualTo(new String[] {"e1", "e2"});
98  
99          mojo.setExcludeJUnit5Engines(new String[] {"e1", "e2"});
100         assertThat(mojo.getExcludeJUnit5Engines()).isEqualTo(new String[] {"e1", "e2"});
101     }
102 }