[BAEL-6697] code for jacoco fail build

This commit is contained in:
uzma 2023-07-07 00:36:48 +01:00
parent 1db057ebc8
commit dc6e611fef
3 changed files with 43 additions and 5 deletions

View File

@ -91,6 +91,32 @@
<goal>report</goal> <goal>report</goal>
</goals> </goals>
</execution> </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> </executions>
</plugin> </plugin>
</plugins> </plugins>

View File

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

View File

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