File tree Expand file tree Collapse file tree
main/java/com/baeldung/lombok/intro
test/java/com/baeldung/lombok/intro Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 >
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 >
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments