Skip to content

Commit 8087dad

Browse files
egoebelbeckerKevinGilmore
authored andcommitted
BAEL-1787 - using Lombok @builder on methods (eugenp#4256)
* BAEL-1787 - using Lombok @builder on methods * BAEL-1787 - rename class. Add AssertJ to Lombok project. * BAEL-1787 - rename class again. Change AssertJ tests.
1 parent 62b5a59 commit 8087dad

4 files changed

Lines changed: 47 additions & 0 deletions

File tree

‎lombok/pom.xml‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727
<artifactId>hibernate-jpa-2.1-api</artifactId>
2828
<version>${hibernate-jpa-2.1-api.version}</version>
2929
</dependency>
30+
<dependency>
31+
<groupId>org.assertj</groupId>
32+
<artifactId>assertj-core</artifactId>
33+
<version>${assertj-core.version}</version>
34+
<scope>test</scope>
35+
</dependency>
3036
</dependencies>
3137

3238
<build>
@@ -76,6 +82,7 @@
7682
<hibernate-jpa-2.1-api.version>1.0.0.Final</hibernate-jpa-2.1-api.version>
7783
<!-- delombok maven plugin -->
7884
<delombok-maven-plugin.version>1.16.10.0</delombok-maven-plugin.version>
85+
<assertj-core.version>3.8.0</assertj-core.version>
7986
</properties>
8087

8188
</project>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.baeldung.lombok.intro;
2+
3+
import lombok.Builder;
4+
5+
class ClientBuilder {
6+
7+
@Builder(builderMethodName = "builder")
8+
public static ImmutableClient newClient(int id, String name) {
9+
return new ImmutableClient(id, name);
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.baeldung.lombok.intro;
2+
3+
import lombok.Value;
4+
5+
@Value
6+
final class ImmutableClient {
7+
8+
private int id;
9+
private String name;
10+
11+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.baeldung.lombok.intro;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.assertj.core.api.Assertions.*;
6+
7+
public class BuilderMethodUnitTest
8+
{
9+
10+
@Test
11+
public void givenBuilderMethod_ClientIsBuilt() {
12+
ImmutableClient testImmutableClient = ClientBuilder.builder().name("foo").id(1).build();
13+
assertThat(testImmutableClient.getName())
14+
.isEqualTo("foo");
15+
assertThat(testImmutableClient.getId())
16+
.isEqualTo(1);
17+
}
18+
}

0 commit comments

Comments
 (0)