Skip to content

Commit 24487e9

Browse files
authored
Test coverage for SerializableError.forException() with Optional values (#1051)
Test coverage for SerializableError.forException() with Optional values
1 parent fddb108 commit 24487e9

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

errors/src/test/java/com/palantir/conjure/java/api/errors/SerializableErrorTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.io.IOException;
2727
import java.util.List;
2828
import java.util.Map;
29+
import java.util.Optional;
2930
import java.util.regex.Pattern;
3031
import org.junit.jupiter.api.Test;
3132

@@ -125,6 +126,24 @@ public void forException_mapArrayArgValue_serializesWithToString() {
125126
assertThat(value).matches(Pattern.quote("[Ljava.lang.String;@") + "[0-9a-f]+"));
126127
}
127128

129+
@Test
130+
public void forException_optionalArgValue_serializesWithToString() {
131+
ErrorType error = ErrorType.INTERNAL;
132+
ServiceException exception = new ServiceException(
133+
error,
134+
SafeArg.of("safe-optional-present", Optional.of("hello")),
135+
UnsafeArg.of("unsafe-optional-empty", Optional.empty()));
136+
137+
SerializableError expected = new SerializableError.Builder()
138+
.errorCode(error.code().name())
139+
.errorName(error.name())
140+
.errorInstanceId(exception.getErrorInstanceId())
141+
.putParameters("safe-optional-present", "Optional[hello]")
142+
.putParameters("unsafe-optional-empty", "Optional.empty")
143+
.build();
144+
assertThat(SerializableError.forException(exception)).isEqualTo(expected);
145+
}
146+
128147
@Test
129148
public void testSerializationContainsRedundantParameters() throws Exception {
130149
assertThat(mapper.writeValueAsString(ERROR))

0 commit comments

Comments
 (0)