File tree Expand file tree Collapse file tree
testing-modules/testing-libraries-2
main/java/com/baeldung/jacocoexclusions/service
test/java/com/baeldung/jacocoexclusions/service Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 >
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 >
Original file line number Diff line number Diff line change 33public 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+ }
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments