Add toString() method in ArgumentValue
See gh-1196 Signed-off-by: Dennis Griese <d.griese1987@gmail.com>
This commit is contained in:
@@ -137,6 +137,23 @@ public final class ArgumentValue<T> {
|
||||
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
|
||||
|
||||
@@ -80,4 +80,18 @@ class ArgumentValueTests {
|
||||
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]");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user