Merge pull request #14373 from ukhan1980/BAEL-6697-fail-maven-build-if-coverage-falls

[BAEL-6697] code for jacoco fail build
This commit is contained in:
davidmartinezbarua 2023-07-24 19:16:29 -03:00 committed by GitHub
commit 37510f10fd
3 changed files with 44 additions and 5 deletions

View File

@ -1,6 +1,6 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>testing-libraries-2</artifactId>
<name>testing-libraries-2</name>
@ -91,6 +91,32 @@
<goal>report</goal>
</goals>
</execution>
<execution>
<id>check-coverage</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<element>BUNDLE</element>
<limits>
<limit>
<counter>INSTRUCTION</counter>
<value>COVEREDRATIO</value>
<minimum>0.70</minimum>
</limit>
<limit>
<counter>BRANCH</counter>
<value>COVEREDRATIO</value>
<minimum>0.68</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>

View File

@ -3,7 +3,13 @@ package com.baeldung.jacocoexclusions.service;
public class ProductService {
private static final double DISCOUNT = 0.25;
public double getSalePrice(double originalPrice) {
return originalPrice - originalPrice * DISCOUNT;
public double getSalePrice(double originalPrice, boolean flag) {
double discount;
if (flag) {
discount = originalPrice - originalPrice * DISCOUNT;
} else {
discount = originalPrice;
}
return discount;
}
}

View File

@ -9,7 +9,14 @@ class ProductServiceUnitTest {
@Test
public void givenOriginalPrice_whenGetSalePrice_thenReturnsDiscountedPrice() {
ProductService productService = new ProductService();
double salePrice = productService.getSalePrice(100);
double salePrice = productService.getSalePrice(100, true);
assertEquals(salePrice, 75);
}
@Test
public void givenOriginalPrice_whenGetSalePriceWithFlagFalse_thenReturnsDiscountedPrice() {
ProductService productService = new ProductService();
double salePrice = productService.getSalePrice(100, false);
assertEquals(salePrice, 100);
}
}