*/
@Nonnull
public Profile setFirstName(@Nullable String firstName) {
- this.firstName = firstName;
+ this.firstName = "".equals(firstName) ? null : firstName;
return this;
}
*/
@Nonnull
public Profile setMiddleName(@Nullable String middleName) {
- this.middleName = middleName;
+ this.middleName = "".equals(middleName) ? null : middleName;
return this;
}
*/
@Nonnull
public Profile setLastName(@Nullable String lastName) {
- this.lastName = lastName;
+ this.lastName = "".equals(lastName) ? null : lastName;
return this;
}
private val profile = Profile(sone)
@Test
+ fun `first name is initialized with null`() {
+ assertThat(profile.firstName, nullValue())
+ }
+
+ @Test
+ fun `setting first name to value will set it to value`() {
+ profile.firstName = "first name"
+ assertThat(profile.firstName, equalTo("first name"))
+ }
+
+ @Test
+ fun `setting first name to null will set it to null`() {
+ profile.firstName = null
+ assertThat(profile.firstName, nullValue())
+ }
+
+ @Test
+ fun `setting first name to empty string will set it to null`() {
+ profile.firstName = ""
+ assertThat(profile.firstName, nullValue())
+ }
+
+ @Test
+ fun `middle name is initialized with null`() {
+ assertThat(profile.middleName, nullValue())
+ }
+
+ @Test
+ fun `setting middle name to value will set it to value`() {
+ profile.middleName = "middle name"
+ assertThat(profile.middleName, equalTo("middle name"))
+ }
+
+ @Test
+ fun `setting middle name to null will set it to null`() {
+ profile.middleName = null
+ assertThat(profile.middleName, nullValue())
+ }
+
+ @Test
+ fun `setting middle name to empty string will set it to null`() {
+ profile.middleName = ""
+ assertThat(profile.middleName, nullValue())
+ }
+
+ @Test
+ fun `last name is initialized with null`() {
+ assertThat(profile.lastName, nullValue())
+ }
+
+ @Test
+ fun `setting last name to value will set it to value`() {
+ profile.lastName = "last name"
+ assertThat(profile.lastName, equalTo("last name"))
+ }
+
+ @Test
+ fun `setting last name to null will set it to null`() {
+ profile.lastName = null
+ assertThat(profile.lastName, nullValue())
+ }
+
+ @Test
+ fun `setting last name to empty string will set it to null`() {
+ profile.lastName = ""
+ assertThat(profile.lastName, nullValue())
+ }
+
+ @Test
fun `new fields are initialized with an empty string`() {
val newField = profile.addField("testField")
assertThat(newField.value, equalTo(""))