S3ConnectivityCheck { public void checkS3Put(AmazonS3 s3, String bucket, String key) { try { byte[] source = { 0x0 }; ByteArrayInputStream is = new ByteArrayInputStream(source); final PutObjectRequest object = new PutObjectRequest(bucket, key, is, new ObjectMetadata()); s3.putObject(object); } catch (Exception e) { log.error("Unable to write an object to AWS S3: bucket={}, key={}.", bucket, key); throw e; } }  void checkS3Put(AmazonS3 s3, String bucket, String key);  }
@Test public void checkS3() { Mockito.when( s3.putObject( Mockito.any(PutObjectRequest.class))) .thenReturn(new PutObjectResult()); underTest.checkS3Put(s3, "bucket", "key"); }
@Test(expected = SdkClientException.class) public void checkS3WithError() { Mockito.when( s3.putObject( Mockito.any(PutObjectRequest.class))) .thenThrow(new SdkClientException("")); underTest.checkS3Put(s3, "bucket", "key"); }