### Question:
AwsObjectStorageConnector implements ObjectStorageConnector { @Override public ObjectStorageMetadataResponse getObjectStorageMetadata(ObjectStorageMetadataRequest request) { AwsCredentialView awsCredentialView = new AwsCredentialView(request.getCredential()); try { AmazonS3 s3Client = awsClient.createS3Client(awsCredentialView); String bucketLocation = fixBucketLocation(s3Client.getBucketLocation(request.getObjectStoragePath())); return ObjectStorageMetadataResponse.builder() .withRegion(bucketLocation) .withStatus(ResponseStatus.OK) .build(); } catch (AmazonS3Exception e) { if (e.getStatusCode() != ACCESS_DENIED_ERROR_CODE) { throw new CloudConnectorException(String.format("Cannot get object storage location for %s. " + "Provider error message: %s", request.getObjectStoragePath(), e.getErrorMessage()), e); } return ObjectStorageMetadataResponse.builder() .withStatus(ResponseStatus.ACCESS_DENIED) .build(); } }  @Override ObjectStorageMetadataResponse getObjectStorageMetadata(ObjectStorageMetadataRequest request); @Override ObjectStorageValidateResponse validateObjectStorage(ObjectStorageValidateRequest request); @Override Platform platform(); @Override Variant variant();  }### Answer:
@Test public void getObjectStorageMetadata() { when(s3Client.getBucketLocation(BUCKET_NAME)).thenReturn(REGION_NAME); ObjectStorageMetadataRequest request = ObjectStorageMetadataRequest.builder().withObjectStoragePath(BUCKET_NAME).build(); ObjectStorageMetadataResponse result = underTest.getObjectStorageMetadata(request); verify(s3Client).getBucketLocation(BUCKET_NAME); assertEquals(REGION_NAME, result.getRegion()); assertEquals(ResponseStatus.OK, result.getStatus()); }
@Test public void getObjectStorageMetadataAccessDenied() { AmazonS3Exception exception = new AmazonS3Exception(ERROR_MESSAGE); exception.setStatusCode(403); when(s3Client.getBucketLocation(BUCKET_NAME)).thenThrow(exception); ObjectStorageMetadataRequest request = ObjectStorageMetadataRequest.builder().withObjectStoragePath(BUCKET_NAME).build(); ObjectStorageMetadataResponse result = underTest.getObjectStorageMetadata(request); verify(s3Client).getBucketLocation(BUCKET_NAME); assertNull(result.getRegion()); assertEquals(ResponseStatus.ACCESS_DENIED, result.getStatus()); }
@Test public void getObjectStorageMetadataThrows() { AmazonS3Exception exception = new AmazonS3Exception(ERROR_MESSAGE); thrown.expect(CloudConnectorException.class); thrown.expectMessage(String.format("Cannot get object storage location for %s. Provider error message: %s", BUCKET_NAME, ERROR_MESSAGE)); when(s3Client.getBucketLocation(BUCKET_NAME)).thenThrow(exception); ObjectStorageMetadataRequest request = ObjectStorageMetadataRequest.builder().withObjectStoragePath(BUCKET_NAME).build(); underTest.getObjectStorageMetadata(request); }