BAEL-1787 - using Lombok @Builder on methods (#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.
This commit is contained in:
committed by
KevinGilmore
parent
62b5a591af
commit
8087dad2b2
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.baeldung.lombok.intro;
|
||||
|
||||
import lombok.Value;
|
||||
|
||||
@Value
|
||||
final class ImmutableClient {
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user