From c0f8ed17c73e8fb6e96d27cd5e87df0ff6590f71 Mon Sep 17 00:00:00 2001 From: akhil90s <46933461+akhil90s@users.noreply.github.com> Date: Sun, 16 May 2021 22:12:35 +0530 Subject: [PATCH] Code Coverage with SonarQube and Jacoco (#10674) * Code Coverage with SonarQube and Jacoco * SonarQube and Jacoco * Delete SonarQube and Jacoco From the Root directory * SonarQube and JaCoCo * SonarQube And JaCoCo * BAEL-4636 : Code Coverage with SonarQube and Jacoco * Shifted to testing-modules/testing-libraries-2 * Removing this project to make a single project * Code Coverage with SonarQube and Jacoco * Formatting in pom.xml file * Delete Directory * Delete unused directory * SonarQube And JaCoCo * SonarQube And JaCoCo --- testing-modules/testing-libraries-2/pom.xml | 47 +++++++++++++--- .../sonarqubeandjacoco/product/Product.java | 54 +++++++++++++++++++ .../product/ProductUnitTest.java | 26 +++++++++ 3 files changed, 120 insertions(+), 7 deletions(-) create mode 100644 testing-modules/testing-libraries-2/src/main/java/com/baeldung/sonarqubeandjacoco/product/Product.java create mode 100644 testing-modules/testing-libraries-2/src/test/java/com/baeldung/sonarqubeandjacoco/product/ProductUnitTest.java diff --git a/testing-modules/testing-libraries-2/pom.xml b/testing-modules/testing-libraries-2/pom.xml index 7f96280cac..b01a1a918b 100644 --- a/testing-modules/testing-libraries-2/pom.xml +++ b/testing-modules/testing-libraries-2/pom.xml @@ -12,6 +12,15 @@ ../ + + 0.8.6 + 1.19.0 + 1.0.0 + 1.1.0 + 5.6.2 + 3.16.1 + + org.assertj @@ -72,6 +81,36 @@ + + + maven-war-plugin + 2.4 + + false + + + + + org.jacoco + jacoco-maven-plugin + ${jacoco.version} + + + jacoco-initialize + + prepare-agent + + + + jacoco-site + package + + report + + + + + testing-libraries @@ -81,11 +120,5 @@ - - 1.19.0 - 1.0.0 - 1.1.0 - 5.6.2 - 3.16.1 - + diff --git a/testing-modules/testing-libraries-2/src/main/java/com/baeldung/sonarqubeandjacoco/product/Product.java b/testing-modules/testing-libraries-2/src/main/java/com/baeldung/sonarqubeandjacoco/product/Product.java new file mode 100644 index 0000000000..42f103a317 --- /dev/null +++ b/testing-modules/testing-libraries-2/src/main/java/com/baeldung/sonarqubeandjacoco/product/Product.java @@ -0,0 +1,54 @@ +package com.baeldung.sonarqubeandjacoco.product; + +public class Product { + + private int id; + private String name; + private int units; + private double price; + + public Product() { + super(); + } + + public Product(int id, String name, int units, double price) { + super(); + this.id = id; + this.name = name; + this.units = units; + this.price = price; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getUnits() { + return units; + } + + public void setUnits(int units) { + this.units = units; + } + + public double getPrice() { + return price; + } + + public void setPrice(double price) { + this.price = price; + } + +} \ No newline at end of file diff --git a/testing-modules/testing-libraries-2/src/test/java/com/baeldung/sonarqubeandjacoco/product/ProductUnitTest.java b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/sonarqubeandjacoco/product/ProductUnitTest.java new file mode 100644 index 0000000000..da649851e0 --- /dev/null +++ b/testing-modules/testing-libraries-2/src/test/java/com/baeldung/sonarqubeandjacoco/product/ProductUnitTest.java @@ -0,0 +1,26 @@ +package com.baeldung.sonarqubeandjacoco.product; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import org.junit.Test; + +import com.baeldung.sonarqubeandjacoco.product.Product; + +public class ProductUnitTest { + + @Test + public void test() { + Product product = new Product(); + product.setId(1); + assertNull(product.getName()); + assert (product.getId() == 1); + } + + @Test + public void testProduct() { + Product product = new Product(1, "product", 1, 2.0); + assertNotNull(product.getName()); + } + +}