[BAEL-4406] Move maven code to testing-libraries-2

This commit is contained in:
uzma khan
2021-06-03 10:11:38 +01:00
parent 20a329a603
commit aa3c00d9c6
15 changed files with 31 additions and 86 deletions

View File

@@ -0,0 +1 @@
lombok.addLombokGeneratedAnnotation = true

View File

@@ -13,6 +13,12 @@
</parent>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
@@ -85,6 +91,13 @@
<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>

View File

@@ -0,0 +1,11 @@
package com.baeldung.jacocoexclusions.config;
import com.baeldung.jacocoexclusions.service.ProductService;
public class AppConfig {
public ProductService productService() {
return new ProductService();
}
}

View File

@@ -0,0 +1,12 @@
package com.baeldung.jacocoexclusions.domain;
import lombok.Builder;
import lombok.Data;
@Builder
@Data
public class Product {
private int id;
private String name;
}

View File

@@ -0,0 +1,4 @@
package com.baeldung.jacocoexclusions.dto;
public class ExcludedPOJO {
}

View File

@@ -0,0 +1,4 @@
package com.baeldung.jacocoexclusions.dto;
public class ProductDTO {
}

View File

@@ -0,0 +1,11 @@
package com.baeldung.jacocoexclusions.generated;
@Generated
public class Customer {
// everything in this class will be excluded from jacoco report because of @Generated
@Override
public String toString() {
return "Customer{}";
}
}

View File

@@ -0,0 +1,15 @@
package com.baeldung.jacocoexclusions.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 {
}

View File

@@ -0,0 +1,16 @@
package com.baeldung.jacocoexclusions.service;
import com.baeldung.jacocoexclusions.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";
}
}

View File

@@ -0,0 +1,9 @@
package com.baeldung.jacocoexclusions.service;
public class ProductService {
private static final double DISCOUNT = 0.25;
public double getSalePrice(double originalPrice) {
return originalPrice - originalPrice * DISCOUNT;
}
}

View File

@@ -0,0 +1,14 @@
package com.baeldung.jacocoexclusions.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());
}
}

View File

@@ -0,0 +1,15 @@
package com.baeldung.jacocoexclusions.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);
}
}