From 91b18ac99159d7837465baa38180e7268868c89f Mon Sep 17 00:00:00 2001 From: Pritham Marupaka Date: Tue, 7 Jan 2025 12:15:00 -0500 Subject: [PATCH 1/2] Modify ConjureBodySerDeTest#testErrorsDecoded to test e2e error decoding --- .../dialogue/serde/ConjureBodySerDeTest.java | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/dialogue-serde/src/test/java/com/palantir/conjure/java/dialogue/serde/ConjureBodySerDeTest.java b/dialogue-serde/src/test/java/com/palantir/conjure/java/dialogue/serde/ConjureBodySerDeTest.java index da7ea260c..684c5acdd 100644 --- a/dialogue-serde/src/test/java/com/palantir/conjure/java/dialogue/serde/ConjureBodySerDeTest.java +++ b/dialogue-serde/src/test/java/com/palantir/conjure/java/dialogue/serde/ConjureBodySerDeTest.java @@ -19,14 +19,15 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableList; import com.palantir.conjure.java.api.errors.ErrorType; import com.palantir.conjure.java.api.errors.RemoteException; import com.palantir.conjure.java.api.errors.SerializableError; import com.palantir.conjure.java.api.errors.ServiceException; +import com.palantir.conjure.java.serialization.ObjectMappers; import com.palantir.dialogue.BinaryRequestBody; import com.palantir.dialogue.BodySerDe; import com.palantir.dialogue.RequestBody; @@ -47,6 +48,7 @@ @ExtendWith(MockitoExtension.class) public class ConjureBodySerDeTest { + private static final ObjectMapper SERVER_MAPPER = ObjectMappers.newServerObjectMapper(); private static final TypeMarker TYPE = new TypeMarker() {}; private static final TypeMarker> OPTIONAL_TYPE = new TypeMarker>() {}; @@ -137,14 +139,12 @@ public void testRequestUnknownContentType() throws IOException { } @Test - public void testErrorsDecoded() { - TestResponse response = new TestResponse().code(400); - + public void testErrorsDecoded() throws JsonProcessingException { ServiceException serviceException = new ServiceException(ErrorType.INVALID_ARGUMENT); SerializableError serialized = SerializableError.forException(serviceException); - errorDecoder = mock(ErrorDecoder.class); - when(errorDecoder.isError(response)).thenReturn(true); - when(errorDecoder.decode(response)).thenReturn(new RemoteException(serialized, 400)); + TestResponse response = TestResponse.withBody(SERVER_MAPPER.writeValueAsString(serialized)) + .code(400) + .contentType("application/json"); BodySerDe serializers = conjureBodySerDe("text/plain"); @@ -220,14 +220,12 @@ public void testEmptyResponse_success() { } @Test - public void testEmptyResponse_failure() { - TestResponse response = new TestResponse().code(400); - + public void testEmptyResponse_failure() throws JsonProcessingException { ServiceException serviceException = new ServiceException(ErrorType.INVALID_ARGUMENT); SerializableError serialized = SerializableError.forException(serviceException); - errorDecoder = mock(ErrorDecoder.class); - when(errorDecoder.isError(response)).thenReturn(true); - when(errorDecoder.decode(response)).thenReturn(new RemoteException(serialized, 400)); + TestResponse response = TestResponse.withBody(SERVER_MAPPER.writeValueAsString(serialized)) + .code(400) + .contentType("application/json"); BodySerDe serializers = conjureBodySerDe("application/json"); From 2ee97c841f0aab6a68d7192b22b26b90457d373c Mon Sep 17 00:00:00 2001 From: svc-changelog Date: Wed, 8 Jan 2025 18:33:53 +0000 Subject: [PATCH 2/2] Add generated changelog entries --- changelog/@unreleased/pr-2459.v2.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelog/@unreleased/pr-2459.v2.yml diff --git a/changelog/@unreleased/pr-2459.v2.yml b/changelog/@unreleased/pr-2459.v2.yml new file mode 100644 index 000000000..4a75c1dbd --- /dev/null +++ b/changelog/@unreleased/pr-2459.v2.yml @@ -0,0 +1,5 @@ +type: improvement +improvement: + description: Don't mock `ErrorDecoder` in `ConjureBodySerDeTest` + links: + - https://github.com/palantir/dialogue/pull/2459