Skip to content

Commit

Permalink
refactor(retrofit2): add more details to the SpinnakerConversionExcep…
Browse files Browse the repository at this point in the history
…tion's message (#1226)

* refactor(test): flip the arguments of assertions for readability

* feat(retrofit2): add more details to the SpinnakerConversionException's message
  • Loading branch information
kirangodishala authored Feb 12, 2025
1 parent 4e1a797 commit e81dffc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public Response<T> execute() {
}
} catch (JsonProcessingException jpe) {
throw new SpinnakerConversionException(
"Failed to process response body", jpe, delegate.request());
"Failed to process response body: " + jpe.getMessage(), jpe, delegate.request());
} catch (IOException e) {
throw new SpinnakerNetworkException(e, delegate.request());
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,10 @@ void testSpinnakerConversionException() {
() -> retrofit2Service.getRetrofit2().execute(), SpinnakerConversionException.class);
assertThat(spinnakerConversionException.getRetryable()).isNotNull();
assertThat(spinnakerConversionException.getRetryable()).isFalse();
assertThat(spinnakerConversionException).hasMessage("Failed to process response body");
assertThat(spinnakerConversionException)
.hasMessage(
"Failed to process response body: Cannot deserialize value of type `java.lang.String` from Object value (token `JsonToken.START_OBJECT`)\n"
+ " at [Source: (okhttp3.ResponseBody$BomAwareReader); line: 1, column: 1]");
assertThat(spinnakerConversionException.getUrl())
.isEqualTo(mockWebServer.url("/retrofit2").toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void testRetrofit2Client() {
serviceClientProvider.getService(Retrofit2TestService.class, serviceEndpoint);
Map<String, String> response = Retrofit2SyncCall.execute(retrofit2TestService.getSomething());

assertEquals(response.get("message"), "success");
assertEquals("success", response.get("message"));
}

@Test
Expand All @@ -120,9 +120,9 @@ void testRetrofit2ClientWithResponse() {
serviceClientProvider.getService(Retrofit2TestService.class, serviceEndpoint);
Response<Map<String, String>> response =
Retrofit2SyncCall.executeCall(retrofit2TestService.getSomething());
assertEquals(response.code(), 200);
assertEquals(response.headers().get("Content-Type"), "application/json");
assertEquals(response.body().get("message"), "success");
assertEquals(200, response.code());
assertEquals("application/json", response.headers().get("Content-Type"));
assertEquals("success", response.body().get("message"));
}

@Test
Expand Down Expand Up @@ -175,10 +175,10 @@ void testRetrofit2Client_withHttpException() {
assertThrows(
SpinnakerHttpException.class,
() -> Retrofit2SyncCall.executeCall(retrofit2TestService.getSomething()));
assertEquals(exception.getResponseCode(), 400);
assertEquals(400, exception.getResponseCode());
assertEquals(
exception.getMessage(),
"Status: 400, Method: GET, URL: http://localhost:" + port + "/test, Message: error");
"Status: 400, Method: GET, URL: http://localhost:" + port + "/test, Message: error",
exception.getMessage());
}

@Test
Expand All @@ -200,7 +200,10 @@ void testRetrofit2Client_withConversionException() {
assertThrows(
SpinnakerConversionException.class,
() -> Retrofit2SyncCall.executeCall(retrofit2TestService.getSomething()));
assertEquals(exception.getMessage(), "Failed to process response body");
assertEquals(
"Failed to process response body: Unexpected end-of-input: was expecting closing quote for a string value\n"
+ " at [Source: (okhttp3.ResponseBody$BomAwareReader); line: 1, column: 29]",
exception.getMessage());
}

@Configuration
Expand Down

0 comments on commit e81dffc

Please sign in to comment.