[BAEL-4406] Move maven code to testing-libraries-2
This commit is contained in:
1
testing-modules/testing-libraries-2/lombok.config
Normal file
1
testing-modules/testing-libraries-2/lombok.config
Normal file
@@ -0,0 +1 @@
|
||||
lombok.addLombokGeneratedAnnotation = true
|
||||
@@ -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>
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.baeldung.jacocoexclusions.config;
|
||||
|
||||
import com.baeldung.jacocoexclusions.service.ProductService;
|
||||
|
||||
public class AppConfig {
|
||||
|
||||
public ProductService productService() {
|
||||
return new ProductService();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.baeldung.jacocoexclusions.dto;
|
||||
|
||||
public class ExcludedPOJO {
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.baeldung.jacocoexclusions.dto;
|
||||
|
||||
public class ProductDTO {
|
||||
}
|
||||
@@ -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{}";
|
||||
}
|
||||
}
|
||||
@@ -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 {
|
||||
}
|
||||
@@ -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";
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user