-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Configure Jacoco for multimodule project in SonarQube
- Loading branch information
Showing
8 changed files
with
319 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...aven-plugin/src/test/java/pl/wavesoftware/plugs/tools/maven/plugin/BaseMavenTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright (c) 2019 Wave Software | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package pl.wavesoftware.plugs.tools.maven.plugin; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import pl.wavesoftware.maven.testing.junit5.MavenInvoker; | ||
import pl.wavesoftware.maven.testing.junit5.MavenInvokerExtension; | ||
import pl.wavesoftware.maven.testing.junit5.MavenProjectCustomizer; | ||
import pl.wavesoftware.maven.testing.junit5.MojoExtension; | ||
|
||
import java.io.File; | ||
import java.nio.file.Path; | ||
|
||
import static pl.wavesoftware.eid.utils.EidExecutions.tryToExecute; | ||
import static pl.wavesoftware.eid.utils.EidPreconditions.checkNotNull; | ||
|
||
@ExtendWith({ | ||
MojoExtension.class, | ||
MavenInvokerExtension.class | ||
}) | ||
abstract class BaseMavenTestCase { | ||
private final Path pomDirectory; | ||
private final MavenProjectCustomizer customizer; | ||
|
||
BaseMavenTestCase(Path pomDirectory) { | ||
this.pomDirectory = pomDirectory; | ||
customizer = project -> { | ||
File destination = fromTargetClasses(pomDirectory) | ||
.resolve("target") | ||
.resolve(project.getBuild().getFinalName() + "." + project.getPackaging()) | ||
.toFile(); | ||
project.getArtifact().setFile(destination); | ||
}; | ||
} | ||
|
||
@BeforeEach | ||
void before(MavenInvoker invoker) { | ||
invoker | ||
.forDirectory(fromTargetClasses(pomDirectory)) | ||
.execute("clean", "package"); | ||
} | ||
|
||
MavenProjectCustomizer getCustomizer() { | ||
return customizer; | ||
} | ||
|
||
Path getPomDirectory() { | ||
return pomDirectory; | ||
} | ||
|
||
private static Path fromTargetClasses(Path pomDirectory) { | ||
Path testClasses = tryToExecute(() -> | ||
new File(checkNotNull( | ||
PackagePlugMojoIT.class.getClassLoader().getResource("."), | ||
"20190117:004601" | ||
).toURI()).toPath(), | ||
"20190201:003826" | ||
); | ||
return testClasses.resolve(pomDirectory); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,97 +20,157 @@ | |
import org.apache.maven.monitor.logging.DefaultLog; | ||
import org.apache.maven.plugin.logging.Log; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mockito; | ||
import org.mockito.Spy; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.slf4j.LoggerFactory; | ||
import pl.wavesoftware.maven.testing.junit5.MavenInvoker; | ||
import pl.wavesoftware.maven.testing.junit5.MavenInvokerExtension; | ||
import pl.wavesoftware.maven.testing.junit5.MavenProjectCustomizer; | ||
import pl.wavesoftware.maven.testing.junit5.MojoExtension; | ||
import org.springframework.core.io.ClassPathResource; | ||
import org.springframework.core.io.Resource; | ||
import pl.wavesoftware.maven.testing.junit5.MojoFactory; | ||
|
||
import java.io.File; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatCode; | ||
import static org.mockito.ArgumentMatchers.contains; | ||
import static org.mockito.Mockito.atLeastOnce; | ||
import static org.mockito.Mockito.verify; | ||
import static pl.wavesoftware.eid.utils.EidExecutions.tryToExecute; | ||
import static pl.wavesoftware.eid.utils.EidPreconditions.checkNotNull; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Krzysztof Suszynski</a> | ||
* @since 0.1.0 | ||
*/ | ||
@ExtendWith({ | ||
MojoExtension.class, | ||
MavenInvokerExtension.class, | ||
MockitoExtension.class | ||
}) | ||
class PackagePlugMojoIT { | ||
|
||
private final Path pomDirectory = Paths.get("simpliest"); | ||
private final MavenProjectCustomizer customizer = project -> { | ||
File destination = fromTargetClasses(pomDirectory) | ||
.resolve("target") | ||
.resolve(project.getBuild().getFinalName() + "." + project.getPackaging()) | ||
.toFile(); | ||
project.getArtifact().setFile(destination); | ||
}; | ||
|
||
@Spy | ||
private Log log = new DefaultLog(new Slf4jLogger( | ||
private static final Log DEFAULT_LOG = new DefaultLog(new Slf4jLogger( | ||
LoggerFactory.getLogger(PackagePlugMojoIT.class) | ||
)); | ||
|
||
@BeforeEach | ||
void before(MavenInvoker invoker) { | ||
invoker | ||
.forDirectory(fromTargetClasses(pomDirectory)) | ||
.execute("clean", "compile", "jar:jar"); | ||
@Nested | ||
@ExtendWith(MockitoExtension.class) | ||
class Simpliest extends BaseMavenTestCase { | ||
@Spy | ||
private Log log = DEFAULT_LOG; | ||
|
||
Simpliest() { | ||
super(Paths.get("simpliest")); | ||
} | ||
|
||
@AfterEach | ||
void after() { | ||
Mockito.verifyNoMoreInteractions(log); | ||
Mockito.validateMockitoUsage(); | ||
} | ||
|
||
@Test | ||
@DisplayName("Execute mojo on simpliest project") | ||
void execute(MojoFactory factory) { | ||
// given | ||
PackagePlugMojo mojo = factory | ||
.customizer(getCustomizer()) | ||
.builder(PackagePlugMojo.class) | ||
.withPomDirectory(getPomDirectory()) | ||
.build(PackagePlugMojo.GOAL); | ||
mojo.setLog(log); | ||
|
||
// when & then | ||
assertThatCode(mojo::execute).doesNotThrowAnyException(); | ||
verify(log, atLeastOnce()).isDebugEnabled(); | ||
verify(log).isInfoEnabled(); | ||
verify(log).info(contains("Building plug: ")); | ||
verify(log).debug(contains( | ||
"simpliest-0.1.0-plg.jar was successful." | ||
)); | ||
verify(log).debug(contains("Artifact attached to the build")); | ||
Resource resource = new ClassPathResource( | ||
"/simpliest/target/simpliest-0.1.0-plg.jar" | ||
); | ||
assertThat(resource.exists()).isTrue(); | ||
} | ||
} | ||
|
||
@AfterEach | ||
void after() { | ||
Mockito.verifyNoMoreInteractions(log); | ||
Mockito.validateMockitoUsage(); | ||
@Nested | ||
class Pom extends BaseMavenTestCase { | ||
|
||
Pom() { | ||
super(Paths.get("pom")); | ||
} | ||
|
||
@Test | ||
@DisplayName("Execute mojo on pom project") | ||
void execute(MojoFactory factory) { | ||
// given | ||
PackagePlugMojo mojo = factory | ||
.customizer(getCustomizer()) | ||
.builder(PackagePlugMojo.class) | ||
.withPomDirectory(getPomDirectory()) | ||
.build(PackagePlugMojo.GOAL); | ||
mojo.setLog(DEFAULT_LOG); | ||
|
||
// when & then | ||
assertThatCode(mojo::execute).doesNotThrowAnyException(); | ||
Resource resource = new ClassPathResource( | ||
"/pom/target/a-pom-0.1.0-plug.jar" | ||
); | ||
assertThat(resource.exists()).isFalse(); | ||
} | ||
} | ||
|
||
@Test | ||
void execute(MojoFactory factory) { | ||
// given | ||
PackagePlugMojo mojo = factory | ||
.customizer(customizer) | ||
.builder(PackagePlugMojo.class) | ||
.withPomDirectory(pomDirectory) | ||
.build(PackagePlugMojo.GOAL); | ||
mojo.setLog(log); | ||
|
||
// when & then | ||
assertThatCode(mojo::execute).doesNotThrowAnyException(); | ||
verify(log, atLeastOnce()).isDebugEnabled(); | ||
verify(log).isInfoEnabled(); | ||
verify(log).info(contains("Building plug: ")); | ||
verify(log).debug(contains( | ||
"simpliest-0.1.0-plg.jar was successful." | ||
)); | ||
verify(log).debug(contains("Artifact attached to the build")); | ||
@Nested | ||
class Skipped extends BaseMavenTestCase { | ||
|
||
Skipped() { | ||
super(Paths.get("skipped")); | ||
} | ||
|
||
@Test | ||
@DisplayName("Execute mojo on skipped project") | ||
void execute(MojoFactory factory) { | ||
// given | ||
PackagePlugMojo mojo = factory | ||
.customizer(getCustomizer()) | ||
.builder(PackagePlugMojo.class) | ||
.withPomDirectory(getPomDirectory()) | ||
.build(PackagePlugMojo.GOAL); | ||
mojo.setLog(DEFAULT_LOG); | ||
|
||
// when & then | ||
assertThatCode(mojo::execute).doesNotThrowAnyException(); | ||
Resource resource = new ClassPathResource( | ||
"/skipped/target/skipped-0.1.0-plug.jar" | ||
); | ||
assertThat(resource.exists()).isFalse(); | ||
} | ||
} | ||
|
||
private static Path fromTargetClasses(Path pomDirectory) { | ||
Path testClasses = tryToExecute(() -> | ||
new File(checkNotNull( | ||
PackagePlugMojoIT.class.getClassLoader().getResource("."), | ||
"20190117:004601" | ||
).toURI()).toPath(), | ||
"20190201:003826" | ||
); | ||
return testClasses.resolve(pomDirectory); | ||
@Nested | ||
class CodeWithDependencies extends BaseMavenTestCase { | ||
CodeWithDependencies() { | ||
super(Paths.get("code-with-deps")); | ||
} | ||
|
||
@Test | ||
@DisplayName("Execute mojo on code-with-deps project") | ||
void execute(MojoFactory factory) { | ||
// given | ||
PackagePlugMojo mojo = factory | ||
.customizer(getCustomizer()) | ||
.builder(PackagePlugMojo.class) | ||
.withPomDirectory(getPomDirectory()) | ||
.build(PackagePlugMojo.GOAL); | ||
mojo.setLog(DEFAULT_LOG); | ||
|
||
// when & then | ||
assertThatCode(mojo::execute).doesNotThrowAnyException(); | ||
Resource resource = new ClassPathResource( | ||
"/code-with-deps/target/code-with-deps-0.1.0-plug.jar" | ||
); | ||
assertThat(resource.exists()).isTrue(); | ||
} | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
tools/plugs-maven-plugin/src/test/resources/code-with-deps/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<!-- | ||
~ Copyright (c) 2019 Wave Software | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>org.example</groupId> | ||
<artifactId>code-with-deps</artifactId> | ||
<version>0.1.0</version> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-context</artifactId> | ||
<version>5.1.5.RELEASE</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apiguardian</groupId> | ||
<artifactId>apiguardian-api</artifactId> | ||
<version>1.0.0</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
Oops, something went wrong.