Skip to content

Commit 741a3a5

Browse files
committed
override toString() method in ArgumentValue class
Signed-off-by: Dennis Griese <[email protected]>
1 parent ae40015 commit 741a3a5

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

spring-graphql/src/main/java/org/springframework/graphql/data/ArgumentValue.java

+17
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,23 @@ public int hashCode() {
137137
return result;
138138
}
139139

140+
/**
141+
* Returns a non-empty string representation of this {@code ArgumentValue}
142+
* suitable for debugging.
143+
*
144+
* @return the string representation of this instance
145+
*/
146+
@Override
147+
public String toString() {
148+
if (this.omitted) {
149+
return "ArgumentValue.omitted";
150+
}
151+
if (this.value == null){
152+
return "ArgumentValue.empty";
153+
}
154+
return "ArgumentValue[%s]".formatted(this.value);
155+
}
156+
140157

141158
/**
142159
* Static factory method for an argument value that was provided, even if

spring-graphql/src/test/java/org/springframework/graphql/data/ArgumentValueTests.java

+14
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,18 @@ void ifPresentShouldSkipWhenOmitted() {
8080
assertThat(called.get()).isFalse();
8181
}
8282

83+
@Test
84+
void toStringShouldReturnOmittedWhenOmitted() {
85+
assertThat(ArgumentValue.omitted()).hasToString("ArgumentValue.omitted");
86+
}
87+
88+
@Test
89+
void toStringShouldReturnEmptyWhenNull() {
90+
assertThat(ArgumentValue.ofNullable(null)).hasToString("ArgumentValue.empty");
91+
}
92+
93+
@Test
94+
void toStringShouldReturnValueWhenValue() {
95+
assertThat(ArgumentValue.ofNullable("hello")).hasToString("ArgumentValue[hello]");
96+
}
8397
}

0 commit comments

Comments
 (0)