nacx commented on a change in pull request #82:
URL: https://github.com/apache/jclouds/pull/82#discussion_r487221374



##########
File path: apis/sts/src/test/java/org/jclouds/aws/util/AWSUtilsTest.java
##########
@@ -88,6 +95,20 @@ public void testNoExceptionParsingTextPlain() {
       assertNull(utils.parseAWSErrorFromContent(command.getCurrentRequest(), 
response));
    }
 
+   /**
+    * Do not attempt to parse empty payload.
+    */
+   @Test
+   public void testNoExceptionEmptyPayload() {
+      utils.logger = mock(Logger.class);
+      utils.logger.warn(anyObject(Throwable.class), anyString());
+      expectLastCall().andThrow(new IllegalStateException("log spam"));
+      replay(utils.logger);
+      HttpResponse response = 
HttpResponse.builder().statusCode(NOT_FOUND.getStatusCode()).payload(new 
StringPayload("")).build();
+      
response.getPayload().getContentMetadata().setContentType("application/unknown");
+      assertNull(utils.parseAWSErrorFromContent(command.getCurrentRequest(), 
response));
+   }

Review comment:
       Is there any way we can better test this? The whole purpose of the 
change shouldn't be to _not send logs_, but to avoid parsing a body that we 
know is empty.
   Instead of mocking the logger, could we for example mock the 
response.getPayload to make sure it is not called more than once? Or something 
similar that helps us verify that the code reached the desired execution paths, 
without having to mess up with the logger.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to