diff --git a/lombok/pom.xml b/lombok/pom.xml index d11cffb34b..e0b0426c58 100644 --- a/lombok/pom.xml +++ b/lombok/pom.xml @@ -27,6 +27,12 @@ hibernate-jpa-2.1-api ${hibernate-jpa-2.1-api.version} + + org.assertj + assertj-core + ${assertj-core.version} + test + @@ -76,6 +82,7 @@ 1.0.0.Final 1.16.10.0 + 3.8.0 diff --git a/lombok/src/main/java/com/baeldung/lombok/intro/ClientBuilder.java b/lombok/src/main/java/com/baeldung/lombok/intro/ClientBuilder.java new file mode 100644 index 0000000000..e7851760c5 --- /dev/null +++ b/lombok/src/main/java/com/baeldung/lombok/intro/ClientBuilder.java @@ -0,0 +1,11 @@ +package com.baeldung.lombok.intro; + +import lombok.Builder; + +class ClientBuilder { + + @Builder(builderMethodName = "builder") + public static ImmutableClient newClient(int id, String name) { + return new ImmutableClient(id, name); + } +} diff --git a/lombok/src/main/java/com/baeldung/lombok/intro/ImmutableClient.java b/lombok/src/main/java/com/baeldung/lombok/intro/ImmutableClient.java new file mode 100644 index 0000000000..86be75ecd0 --- /dev/null +++ b/lombok/src/main/java/com/baeldung/lombok/intro/ImmutableClient.java @@ -0,0 +1,11 @@ +package com.baeldung.lombok.intro; + +import lombok.Value; + +@Value +final class ImmutableClient { + + private int id; + private String name; + +} diff --git a/lombok/src/test/java/com/baeldung/lombok/intro/BuilderMethodUnitTest.java b/lombok/src/test/java/com/baeldung/lombok/intro/BuilderMethodUnitTest.java new file mode 100644 index 0000000000..52ecc49c45 --- /dev/null +++ b/lombok/src/test/java/com/baeldung/lombok/intro/BuilderMethodUnitTest.java @@ -0,0 +1,18 @@ +package com.baeldung.lombok.intro; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.*; + +public class BuilderMethodUnitTest +{ + + @Test + public void givenBuilderMethod_ClientIsBuilt() { + ImmutableClient testImmutableClient = ClientBuilder.builder().name("foo").id(1).build(); + assertThat(testImmutableClient.getName()) + .isEqualTo("foo"); + assertThat(testImmutableClient.getId()) + .isEqualTo(1); + } +}