-
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.
Make fields and properties annotated with @nullable optional.
- Loading branch information
Showing
4 changed files
with
59 additions
and
1 deletion.
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,22 @@ | ||
package org.jilt.test; | ||
|
||
import org.jilt.test.data.nullable.FullName; | ||
import org.junit.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.jilt.test.data.nullable.FullNameBuilder.fullName; | ||
|
||
public class FullNameTest { | ||
@Test | ||
public void nullable_attribute() throws Exception { | ||
FullName value = fullName() | ||
.firstName("First") | ||
.lastName(null) | ||
// middleName is implicitly optional, because of @Nullable | ||
.build(); | ||
|
||
assertThat(value.firstName).isEqualTo("First"); | ||
assertThat(value.middleName).isNull(); | ||
assertThat(value.lastName).isNull(); | ||
} | ||
} |
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,17 @@ | ||
package org.jilt.test.data.nullable; | ||
|
||
import org.jilt.Builder; | ||
import org.jilt.BuilderStyle; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
public final class FullName { | ||
public final String firstName, middleName, lastName; | ||
|
||
@Builder(style = BuilderStyle.TYPE_SAFE) | ||
public FullName(String firstName, @Nullable String middleName, String lastName) { | ||
this.firstName = firstName; | ||
this.middleName = middleName; | ||
this.lastName = lastName; | ||
} | ||
} |