diff --git a/testing-modules/testing-libraries-2/pom.xml b/testing-modules/testing-libraries-2/pom.xml index b0680c1e40..810d034836 100644 --- a/testing-modules/testing-libraries-2/pom.xml +++ b/testing-modules/testing-libraries-2/pom.xml @@ -1,6 +1,6 @@ + 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"> 4.0.0 testing-libraries-2 testing-libraries-2 @@ -91,6 +91,32 @@ report + + check-coverage + verify + + check + + + + + BUNDLE + + + INSTRUCTION + COVEREDRATIO + 0.70 + + + BRANCH + COVEREDRATIO + 0.68 + + + + + + diff --git a/testing-modules/testing-libraries-2/src/main/java/com/baeldung/jacocoexclusions/service/ProductService.java b/testing-modules/testing-libraries-2/src/main/java/com/baeldung/jacocoexclusions/service/ProductService.java index c87295e642..9a4a734438 100644 --- a/testing-modules/testing-libraries-2/src/main/java/com/baeldung/jacocoexclusions/service/ProductService.java +++ b/testing-modules/testing-libraries-2/src/main/java/com/baeldung/jacocoexclusions/service/ProductService.java @@ -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; } +} \ No newline at end of file diff --git a/testing-modules/testing-libraries-2/src/test/java/com/baeldung/jacocoexclusions/service/ProductServiceUnitTest.java b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/jacocoexclusions/service/ProductServiceUnitTest.java index 609be33640..02582c869c 100644 --- a/testing-modules/testing-libraries-2/src/test/java/com/baeldung/jacocoexclusions/service/ProductServiceUnitTest.java +++ b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/jacocoexclusions/service/ProductServiceUnitTest.java @@ -9,7 +9,13 @@ 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); + } }