Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lombok/lombok.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import lombok_feature.config

config.stopBubbling = true
lombok.anyconstructor.addconstructorproperties=false
lombok.addLombokGeneratedAnnotation = true
lombok.addSuppressWarnings = false


1 change: 1 addition & 0 deletions lombok/lombok_feature.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lombok.experimental.flagUsage = warning
7 changes: 6 additions & 1 deletion lombok/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>${hibernate-jpa-2.1-api.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>23.0.0</version>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -70,7 +75,7 @@
<!-- various -->
<hibernate-jpa-2.1-api.version>1.0.0.Final</hibernate-jpa-2.1-api.version>
<!-- delombok maven plugin -->
<delombok-maven-plugin.version>1.18.10.0</delombok-maven-plugin.version>
<delombok-maven-plugin.version>1.18.20.0</delombok-maven-plugin.version>
</properties>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.baeldung.lombok.configexamples;

import lombok.*;
import lombok.extern.java.Log;

import java.util.logging.Level;

import static java.lang.Math.abs;

@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@Log
public class Account {

@NonNull
private Double balance = 0.;
@NonNull
private String accountHolder = "";

public Account addBalance(double amount) {
if (amount < 0) {
throw new IllegalArgumentException("Can not add negative amount");
}

this.balance += amount;
return this;
}

public Account withdraw(double amount) {
if (this.balance - abs(amount) < 0) {
domainLog.log(Level.INFO, String.format("Transaction denied for account holder: %s", this.accountHolder));
throw new IllegalArgumentException(String.format("Not enough balance, you have %.2f", this.balance));
}

this.balance -= abs(amount);
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.baeldung.lombok.configexamples;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.experimental.Accessors;

@AllArgsConstructor
@Getter
@Accessors(prefix = {"op"})
public class TransactionLog {
double amount;
String description;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
clear lombok.experimental.flagUsage

lombok.anyconstructor.addconstructorproperties=true
lombok.addNullAnnotations = jetbrains
lombok.accessors.chain = true
lombok.log.fieldName = domainLog
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.baeldung.lombok.configexamples;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

class AccountUnitTest {

@Test
void should_initialize_account() {
Account myAccount = new Account()
.setBalance(2000.00)
.setAccountHolder("John Snow");

assertEquals(2000.00, myAccount.getBalance());
assertEquals("John Snow", myAccount.getAccountHolder());
}

@Test
void should_throw_error_when_balance_becomes_negative() {
Account myAccount = new Account()
.setBalance(20.00)
.setAccountHolder("John Snow");

assertThrows(IllegalArgumentException.class, () -> myAccount.withdraw(100.00));
}

@Test
void should_throw_no_error_when_balance_becomes_zero() {
Account myAccount = new Account()
.setBalance(20.00)
.setAccountHolder("John Snow");

myAccount.withdraw(20.00);

assertEquals(0.00, myAccount.getBalance());
}

@Test
void should_update_balance_properly() {
Account myAccount = new Account()
.setBalance(20.00)
.setAccountHolder("John Snow");

myAccount.withdraw(5.00).withdraw(10.00);

assertEquals(5.00, myAccount.getBalance());
}
}