-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.jilt.test; | ||
|
||
import org.jilt.test.data.defaultvalue.DefaultValue; | ||
import org.jilt.test.data.defaultvalue.DefaultValueBuilder; | ||
import org.junit.Test; | ||
|
||
import java.util.Collections; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class DefaultTest { | ||
|
||
@Test | ||
public void set_attribute_to_default_value_when_is_not_specified_in_builder(){ | ||
DefaultValue value = DefaultValueBuilder | ||
.defaultValue() | ||
.attr4(12) | ||
.build(); | ||
|
||
|
||
assertThat(value.attr1).isEqualTo(1); | ||
assertThat(value.attr2).isEqualTo("attr2"); | ||
assertThat(value.attr3).isTrue(); | ||
assertThat(value.attr4).isEqualTo(12); | ||
assertThat(value.attrs).isEqualTo(Collections.emptySet()); | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
src/test/java/org/jilt/test/data/defaultvalue/DefaultValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.jilt.test.data.defaultvalue; | ||
|
||
import org.jilt.Builder; | ||
|
||
import java.util.Set; | ||
|
||
@Builder | ||
public class DefaultValue { | ||
|
||
@Builder.Default("1") | ||
public int attr1; | ||
|
||
@Builder.Default("\"attr2\"") | ||
public String attr2; | ||
|
||
@Builder.Default("true") | ||
public boolean attr3; | ||
|
||
@Builder.Default("1000") | ||
public int attr4; | ||
|
||
@Builder.Default("java.util.Collections.emptySet()") | ||
public Set<String> attrs; | ||
|
||
public DefaultValue(int attr1, String attr2, boolean attr3, int attr4, Set<String> attrs) { | ||
this.attr1 = attr1; | ||
this.attr2 = attr2; | ||
this.attr3 = attr3; | ||
this.attr4 = attr4; | ||
this.attrs = attrs; | ||
} | ||
} |