Skip to content

Commit

Permalink
BAEL-1787 - using Lombok @builder on methods (eugenp#4256)
Browse files Browse the repository at this point in the history
* 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
egoebelbecker authored and KevinGilmore committed May 16, 2018
1 parent 62b5a59 commit 8087dad
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lombok/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
11 changes: 11 additions & 0 deletions lombok/src/main/java/com/baeldung/lombok/intro/ClientBuilder.java
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);
}
}
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;

}
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);
}
}

0 comments on commit 8087dad

Please sign in to comment.