Mengexclude Code yang digenerate oleh Lombok pada coverage report

ketika memprogram dengan Java mungkin tiidak asing lagi dengan Project Lombok , yang mana merupakan salah satu library yang digunakan untuk meminimize boilerplate code pada POJO kususnya method-method setter, getter, equals, hashcode, dan antek - anteknya.
Anggaplah terdapat sebuah POJO class Product.java
@Entity
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class Product {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String name;
private int price;
private int quantity;
private String imageLocation;
public void updateProduct(Product updatedProduct) {
this.name = updatedProduct.name;
this.price = updatedProduct.price;
this.quantity = updatedProduct.quantity;
}
public ProductDTO convertToDTO() {
return ProductDTO.builder()
.id(this.id)
.name(this.name)
.price(this.price)
.quantity(this.quantity)
.imageUrl(this.imageLocation)
.build();
}
}
untuk dua method di atas updateProduct dan convertToDTO sudah dibuat unit testnya namun ketika cek coverage reportnya, cukup mengesankan.


Coveragenya tidak sampai 50%, untuk mengatasi problem coverage ini ada beberapa cara yang bisa dilakukan
Mengexclude class model tersebut dari coverage report dari project
Mengexclude generated code dari
Lombok
Yang nomor 1 kurang disarankan karena kadang class model juga memiliki bisnis prosessnya sendiri, tidak hanya setter, getter, dan antek-anteknya saja.
Pada Lombok versi 1.14 diperkenalkan fitur lombok configuration system yang mana developer dapat mengkonfigurasi fitur lombok pada proyek atau workspace, biasanya dilakukan dengan menambahkan lombok.config pada root project, untuk apa saja yang bisa dikonfigurasi bisa dilihat di official Lombok projectnya https://projectlombok.org/features/configuration.
Dari semua pilihan konfigurasi pada official websitenya, ada satu configurasi yang membatu untuk mengexclude generated code yaitu lombok.addLombokGeneratedAnnotation = true , dengan menambahakan configurasi ini semua code yang digenerate oleh Lombok akan memiliki annotation @Generated , dengan adanya annotation ini Jacoco akan mengabaikan code terkait pada coverage.
@Generated
public int hashCode() {
int PRIME = true;
int result = 1;
result = result * 59 + this.getId();
result = result * 59 + this.getPrice();
result = result * 59 + this.getQuantity();
Object $name = this.getName();
result = result * 59 + ($name == null ? 43 : $name.hashCode());
Object $imageLocation = this.getImageLocation();
result = result * 59 + ($imageLocation == null ? 43 : $imageLocation.hashCode());
return result;
}
tanpa configurasi lombok.addLombokGeneratedAnnotation = true
public int hashCode() {
int PRIME = true;
int result = 1;
result = result * 59 + this.getId();
result = result * 59 + this.getPrice();
result = result * 59 + this.getQuantity();
Object $name = this.getName();
result = result * 59 + ($name == null ? 43 : $name.hashCode());
Object $imageLocation = this.getImageLocation();
result = result * 59 + ($imageLocation == null ? 43 : $imageLocation.hashCode());
return result;
}
Coverage result pada Product.java setelah menambahkan lombok.addLombokGeneratedAnnotation = true pada lombok.config


![[Config] Konfigurasi VPS Linux](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fstock%2Funsplash%2F40XgDxBfYXM%2Fupload%2F4abd040c2310d933545447e36e0aa765.jpeg&w=3840&q=75)
![[Error] npx create-react-app](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fstock%2Funsplash%2FO_Xy25Dj7Mo%2Fupload%2F857d641313b8e971d5d750198efa52d0.jpeg&w=3840&q=75)
