-
-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
174 additions
and
0 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
...h/jhipster/lite/generator/server/javatool/jacoco/domain/JacocoThresholdModuleFactory.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,54 @@ | ||
package tech.jhipster.lite.generator.server.javatool.jacoco.domain; | ||
|
||
import static tech.jhipster.lite.module.domain.JHipsterModule.*; | ||
|
||
import tech.jhipster.lite.error.domain.Assert; | ||
import tech.jhipster.lite.module.domain.JHipsterModule; | ||
import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties; | ||
|
||
public class JacocoThresholdModuleFactory { | ||
|
||
public JHipsterModule buildModule(JHipsterModuleProperties properties) { | ||
Assert.notNull("properties", properties); | ||
|
||
return moduleBuilder(properties) | ||
.mandatoryReplacements() | ||
.in("pom.xml") | ||
.add( | ||
justLineAfter( | ||
regex("\\s*<outputDirectory>target\\/jacoco\\/<\\/outputDirectory>[\n\r]*\\s*<\\/configuration>[\n\r]*\\s*<\\/execution>") | ||
), | ||
""" | ||
<execution> | ||
<id>check</id> | ||
<goals> | ||
<goal>check</goal> | ||
</goals> | ||
<configuration> | ||
<dataFile>target/jacoco/allTest.exec</dataFile> | ||
<rules> | ||
<rule> | ||
<element>CLASS</element> | ||
<limits> | ||
<limit> | ||
<counter>LINE</counter> | ||
<value>COVEREDRATIO</value> | ||
<minimum>1.00</minimum> | ||
</limit> | ||
<limit> | ||
<counter>BRANCH</counter> | ||
<value>COVEREDRATIO</value> | ||
<minimum>1.00</minimum> | ||
</limit> | ||
</limits> | ||
</rule> | ||
</rules> | ||
</configuration> | ||
</execution> | ||
""" | ||
) | ||
.and() | ||
.and() | ||
.build(); | ||
} | ||
} |
120 changes: 120 additions & 0 deletions
120
...ipster/lite/generator/server/javatool/jacoco/domain/JacocoThresholdModuleFactoryTest.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,120 @@ | ||
package tech.jhipster.lite.generator.server.javatool.jacoco.domain; | ||
|
||
import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.*; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import tech.jhipster.lite.TestFileUtils; | ||
import tech.jhipster.lite.UnitTest; | ||
import tech.jhipster.lite.module.domain.JHipsterModule; | ||
import tech.jhipster.lite.module.domain.JHipsterModulesFixture; | ||
import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties; | ||
|
||
@UnitTest | ||
class JacocoThresholdModuleFactoryTest { | ||
|
||
private static final JacocoThresholdModuleFactory factory = new JacocoThresholdModuleFactory(); | ||
|
||
@Test | ||
void shouldBuildModule() { | ||
JHipsterModuleProperties properties = JHipsterModulesFixture.propertiesBuilder(TestFileUtils.tmpDirForTest()).build(); | ||
|
||
JHipsterModule module = factory.buildModule(properties); | ||
|
||
assertThatModuleWithFiles(module, pomFile()) | ||
.createFile("pom.xml") | ||
.containing( | ||
""" | ||
<plugin> | ||
<groupId>org.jacoco</groupId> | ||
<artifactId>jacoco-maven-plugin</artifactId> | ||
<version>${jacoco.version}</version> | ||
<executions> | ||
<execution> | ||
<id>pre-unit-tests</id> | ||
<goals> | ||
<goal>prepare-agent</goal> | ||
</goals> | ||
</execution> | ||
<!-- Ensures that the code coverage report for unit tests is created after unit tests have been run --> | ||
<execution> | ||
<id>post-unit-test</id> | ||
<phase>test</phase> | ||
<goals> | ||
<goal>report</goal> | ||
</goals> | ||
</execution> | ||
<execution> | ||
<id>pre-integration-tests</id> | ||
<goals> | ||
<goal>prepare-agent-integration</goal> | ||
</goals> | ||
</execution> | ||
<!-- Ensures that the code coverage report for integration tests is created after integration tests have been run --> | ||
<execution> | ||
<id>post-integration-tests</id> | ||
<phase>post-integration-test</phase> | ||
<goals> | ||
<goal>report-integration</goal> | ||
</goals> | ||
</execution> | ||
<execution> | ||
<id>merge</id> | ||
<phase>verify</phase> | ||
<goals> | ||
<goal>merge</goal> | ||
</goals> | ||
<configuration> | ||
<fileSets> | ||
<fileSet implementation="org.apache.maven.shared.model.fileset.FileSet"> | ||
<directory>${project.basedir}</directory> | ||
<includes> | ||
<include>**/*.exec</include> | ||
</includes> | ||
</fileSet> | ||
</fileSets> | ||
<destFile>target/jacoco/allTest.exec</destFile> | ||
</configuration> | ||
</execution> | ||
<execution> | ||
<id>post-merge-report</id> | ||
<phase>verify</phase> | ||
<goals> | ||
<goal>report</goal> | ||
</goals> | ||
<configuration> | ||
<dataFile>target/jacoco/allTest.exec</dataFile> | ||
<outputDirectory>target/jacoco/</outputDirectory> | ||
</configuration> | ||
</execution> | ||
<execution> | ||
<id>check</id> | ||
<goals> | ||
<goal>check</goal> | ||
</goals> | ||
<configuration> | ||
<dataFile>target/jacoco/allTest.exec</dataFile> | ||
<rules> | ||
<rule> | ||
<element>CLASS</element> | ||
<limits> | ||
<limit> | ||
<counter>LINE</counter> | ||
<value>COVEREDRATIO</value> | ||
<minimum>1.00</minimum> | ||
</limit> | ||
<limit> | ||
<counter>BRANCH</counter> | ||
<value>COVEREDRATIO</value> | ||
<minimum>1.00</minimum> | ||
</limit> | ||
</limits> | ||
</rule> | ||
</rules> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
""" | ||
); | ||
} | ||
} |