Merge pull request #5479 from Vizsoro/bael-2195

bael-2195 lombok builder default
This commit is contained in:
Tom Hombergs 2018-10-18 21:10:58 +02:00 committed by GitHub
commit 1bcfbed484
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 0 deletions

View File

@ -59,6 +59,7 @@
</goals>
<configuration>
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
<outputDirectory>${project.build.directory}/delombok</outputDirectory>
<addOutputDirectory>false</addOutputDirectory>
<formatPreferences>
<javaLangAsFQN>skip</javaLangAsFQN>

View File

@ -0,0 +1,17 @@
package com.baeldung.lombok.builder.defaultvalue;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Getter
@Setter
@Builder(toBuilder = true)
@NoArgsConstructor
@AllArgsConstructor
public class Pojo {
private String name = "foo";
private boolean original = true;
}

View File

@ -0,0 +1,25 @@
package com.baeldung.lombok.builder.defaultvalue;
import org.junit.Assert;
import org.junit.Test;
public class BuilderWithDefaultValueUnitTest {
@Test
public void givenBuilderWithDefaultValue_ThanDefaultValueIsPresent() {
Pojo build = new Pojo().toBuilder()
.build();
Assert.assertEquals("foo", build.getName());
Assert.assertTrue(build.isOriginal());
}
@Test
public void givenBuilderWithDefaultValue_NoArgsWorksAlso() {
Pojo build = new Pojo().toBuilder()
.build();
Pojo pojo = new Pojo();
Assert.assertEquals(build.getName(), pojo.getName());
Assert.assertTrue(build.isOriginal() == pojo.isOriginal());
}
}