Skip to content

Commit

Permalink
Don't mock ErrorDecoder in ConjureBodySerDeTest (#2459)
Browse files Browse the repository at this point in the history
Don't mock `ErrorDecoder` in `ConjureBodySerDeTest`
  • Loading branch information
mpritham authored Jan 8, 2025
1 parent 56531a9 commit eec4e86
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-2459.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Don't mock `ErrorDecoder` in `ConjureBodySerDeTest`
links:
- https://github.com/palantir/dialogue/pull/2459
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -47,6 +48,7 @@
@ExtendWith(MockitoExtension.class)
public class ConjureBodySerDeTest {

private static final ObjectMapper SERVER_MAPPER = ObjectMappers.newServerObjectMapper();
private static final TypeMarker<String> TYPE = new TypeMarker<String>() {};
private static final TypeMarker<Optional<String>> OPTIONAL_TYPE = new TypeMarker<Optional<String>>() {};

Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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");

Expand Down

0 comments on commit eec4e86

Please sign in to comment.