Skip to content

Commit 37510f1

Browse files
Merge pull request #14373 from ukhan1980/BAEL-6697-fail-maven-build-if-coverage-falls
[BAEL-6697] code for jacoco fail build
2 parents 8805d35 + e3db03a commit 37510f1

3 files changed

Lines changed: 44 additions & 5 deletions

File tree

testing-modules/testing-libraries-2/pom.xml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<project xmlns="http://maven.apache.org/POM/4.0.0"
2-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
44
<modelVersion>4.0.0</modelVersion>
55
<artifactId>testing-libraries-2</artifactId>
66
<name>testing-libraries-2</name>
@@ -91,6 +91,32 @@
9191
<goal>report</goal>
9292
</goals>
9393
</execution>
94+
<execution>
95+
<id>check-coverage</id>
96+
<phase>verify</phase>
97+
<goals>
98+
<goal>check</goal>
99+
</goals>
100+
<configuration>
101+
<rules>
102+
<rule>
103+
<element>BUNDLE</element>
104+
<limits>
105+
<limit>
106+
<counter>INSTRUCTION</counter>
107+
<value>COVEREDRATIO</value>
108+
<minimum>0.70</minimum>
109+
</limit>
110+
<limit>
111+
<counter>BRANCH</counter>
112+
<value>COVEREDRATIO</value>
113+
<minimum>0.68</minimum>
114+
</limit>
115+
</limits>
116+
</rule>
117+
</rules>
118+
</configuration>
119+
</execution>
94120
</executions>
95121
</plugin>
96122
<plugin>

testing-modules/testing-libraries-2/src/main/java/com/baeldung/jacocoexclusions/service/ProductService.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
public class ProductService {
44
private static final double DISCOUNT = 0.25;
55

6-
public double getSalePrice(double originalPrice) {
7-
return originalPrice - originalPrice * DISCOUNT;
6+
public double getSalePrice(double originalPrice, boolean flag) {
7+
double discount;
8+
if (flag) {
9+
discount = originalPrice - originalPrice * DISCOUNT;
10+
} else {
11+
discount = originalPrice;
812
}
13+
return discount;
914
}
15+
}

testing-modules/testing-libraries-2/src/test/java/com/baeldung/jacocoexclusions/service/ProductServiceUnitTest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@ class ProductServiceUnitTest {
99
@Test
1010
public void givenOriginalPrice_whenGetSalePrice_thenReturnsDiscountedPrice() {
1111
ProductService productService = new ProductService();
12-
double salePrice = productService.getSalePrice(100);
12+
double salePrice = productService.getSalePrice(100, true);
1313
assertEquals(salePrice, 75);
1414
}
15+
16+
@Test
17+
public void givenOriginalPrice_whenGetSalePriceWithFlagFalse_thenReturnsDiscountedPrice() {
18+
ProductService productService = new ProductService();
19+
double salePrice = productService.getSalePrice(100, false);
20+
assertEquals(salePrice, 100);
21+
}
1522
}

0 commit comments

Comments
 (0)