From dc6e611fef4acd0f6e8209703609aead7e4e839c Mon Sep 17 00:00:00 2001 From: uzma Date: Fri, 7 Jul 2023 00:36:48 +0100 Subject: [PATCH 1/2] [BAEL-6697] code for jacoco fail build --- testing-modules/testing-libraries-2/pom.xml | 30 +++++++++++++++++-- .../service/ProductService.java | 10 +++++-- .../service/ProductServiceUnitTest.java | 8 ++++- 3 files changed, 43 insertions(+), 5 deletions(-) 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); + } } From e3db03acdaa1b71c55a94485b7f5174555443951 Mon Sep 17 00:00:00 2001 From: uzma Date: Mon, 17 Jul 2023 14:19:08 +0100 Subject: [PATCH 2/2] [PV-6697] space after test --- .../jacocoexclusions/service/ProductServiceUnitTest.java | 1 + 1 file changed, 1 insertion(+) 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 02582c869c..b51f2b4547 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 @@ -12,6 +12,7 @@ class ProductServiceUnitTest { double salePrice = productService.getSalePrice(100, true); assertEquals(salePrice, 75); } + @Test public void givenOriginalPrice_whenGetSalePriceWithFlagFalse_thenReturnsDiscountedPrice() { ProductService productService = new ProductService();