Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't mock ErrorDecoder in ConjureBodySerDeTest #2459

Merged
merged 2 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
mpritham marked this conversation as resolved.
Show resolved Hide resolved
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
Loading