forked from eugenp/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
1 parent
62b5a59
commit 8087dad
Showing
4 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
lombok/src/main/java/com/baeldung/lombok/intro/ClientBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
lombok/src/main/java/com/baeldung/lombok/intro/ImmutableClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.baeldung.lombok.intro; | ||
|
||
import lombok.Value; | ||
|
||
@Value | ||
final class ImmutableClient { | ||
|
||
private int id; | ||
private String name; | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
lombok/src/test/java/com/baeldung/lombok/intro/BuilderMethodUnitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |