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:
parent
62b5a591af
commit
8087dad2b2
|
@ -27,6 +27,12 @@
|
|||
<artifactId>hibernate-jpa-2.1-api</artifactId>
|
||||
<version>${hibernate-jpa-2.1-api.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj-core.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -76,6 +82,7 @@
|
|||
<hibernate-jpa-2.1-api.version>1.0.0.Final</hibernate-jpa-2.1-api.version>
|
||||
<!-- delombok maven plugin -->
|
||||
<delombok-maven-plugin.version>1.16.10.0</delombok-maven-plugin.version>
|
||||
<assertj-core.version>3.8.0</assertj-core.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue