Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,23 @@ public int hashCode() {
return result;
}

/**
* Returns a non-empty string representation of this {@code ArgumentValue}
* suitable for debugging.
*
* @return the string representation of this instance
*/
@Override
public String toString() {
if (this.omitted) {
return "ArgumentValue.omitted";
}
if (this.value == null){
return "ArgumentValue.empty";
}
return "ArgumentValue[%s]".formatted(this.value);
}


/**
* Static factory method for an argument value that was provided, even if
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,18 @@ void ifPresentShouldSkipWhenOmitted() {
assertThat(called.get()).isFalse();
}

@Test
void toStringShouldReturnOmittedWhenOmitted() {
assertThat(ArgumentValue.omitted()).hasToString("ArgumentValue.omitted");
}

@Test
void toStringShouldReturnEmptyWhenNull() {
assertThat(ArgumentValue.ofNullable(null)).hasToString("ArgumentValue.empty");
}

@Test
void toStringShouldReturnValueWhenValue() {
assertThat(ArgumentValue.ofNullable("hello")).hasToString("ArgumentValue[hello]");
}
}