[BAEL-4406] Add JaCoCo exclusions

This commit is contained in:
uzma khan
2021-05-30 23:02:47 +01:00
parent 1c9bccca01
commit 6f55a1201a
31 changed files with 633 additions and 0 deletions
@@ -0,0 +1 @@
lombok.addLombokGeneratedAnnotation = true
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
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">
<parent>
<artifactId>maven-plugins</artifactId>
<groupId>com.baeldung</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>maven-jacoco</artifactId>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.20</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-verifier-plugin</artifactId>
<version>${maven.verifier.version}</version>
<executions>
<execution>
<phase>none</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<configuration>
<excludes>
<exclude>com/baeldung/**/ExcludedPOJO.class</exclude>
<exclude>com/baeldung/**/*DTO.*</exclude>
<exclude>**/config/*</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<jacoco.version>0.8.6</jacoco.version>
<!-- <maven.compiler.source>11</maven.compiler.source>-->
<!-- <maven.compiler.target>11</maven.compiler.target>-->
</properties>
</project>
@@ -0,0 +1,11 @@
package com.baeldung.config;
import com.baeldung.service.ProductService;
public class AppConfig {
public ProductService productService() {
return new ProductService();
}
}
@@ -0,0 +1,12 @@
package com.baeldung.domain;
import lombok.Builder;
import lombok.Data;
@Builder
@Data
public class Product {
private int id;
private String name;
}
@@ -0,0 +1,4 @@
package com.baeldung.dto;
public class ExcludedPOJO {
}
@@ -0,0 +1,4 @@
package com.baeldung.dto;
public class ProductDTO {
}
@@ -0,0 +1,11 @@
package com.baeldung.generated;
@Generated
public class Customer {
// every thing in this class will be excluded from jacoco report because of @Generated
@Override
public String toString() {
return "Customer{}";
}
}
@@ -0,0 +1,15 @@
package com.baeldung.generated;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
@Documented
@Retention(RUNTIME)
@Target({TYPE, METHOD})
public @interface Generated {
}
@@ -0,0 +1,16 @@
package com.baeldung.service;
import com.baeldung.generated.Generated;
public class CustomerService {
//this method will be excluded from coverage due to @Generated.
@Generated
public String getProductId() {
return "An ID";
}
public String getCustomerName() {
return "some name";
}
}
@@ -0,0 +1,9 @@
package com.baeldung.service;
public class ProductService {
private static final double DISCOUNT = 0.25;
public double getSalePrice(double originalPrice) {
return originalPrice - originalPrice * DISCOUNT;
}
}
@@ -0,0 +1,14 @@
package com.baeldung.service;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertNotNull;
class CustomerServiceUnitTest {
@Test
public void givenCustomer_whenGetCustomer_thenReturnNewCustomer() {
CustomerService customerService = new CustomerService();
assertNotNull(customerService.getCustomerName());
}
}
@@ -0,0 +1,15 @@
package com.baeldung.service;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
class ProductServiceUnitTest {
@Test
public void givenOriginalPrice_whenGetSalePrice_thenReturnsDiscountedPrice() {
ProductService productService = new ProductService();
double salePrice = productService.getSalePrice(100);
assertEquals(salePrice, 75);
}
}
+1
View File
@@ -19,6 +19,7 @@
<module>custom-rule</module>
<module>maven-enforcer</module>
<module>jaxws</module>
<module>maven-jacoco</module>
</modules>
<build>