S3ArtifactStore { public boolean bucketExists() { try { client.listObjects(new ListObjectsRequest(bucket, null, null, null, 0)); return true; } catch (Exception ex) { return false; } } S3ArtifactStore(AmazonS3 client, String bucket);  S3ArtifactStore(GoEnvironment env, String bucket);  S3ArtifactStore(String bucket); void setStorageClass(String storageClass); void put(String from, String to); void put(String from, String to, ObjectMetadata metadata); void put(PutObjectRequest putObjectRequest); String pathString(String pathOnS3); void get(String from, String to); ObjectMetadata getMetadata(String key); void getPrefix(String prefix, String to); boolean bucketExists(); boolean exists(String bucket, String key); RevisionStatus getLatest(Artifact artifact); String getLatestPrefix(String pipeline, String stage, String job, String pipelineCounter); static AmazonS3 getS3client(GoEnvironment env);  }
@Test public void shouldSuccessfullyCheckIfBucketExists() { doReturn(new ObjectListing()).when(mockClient).listObjects(any(ListObjectsRequest.class)); S3ArtifactStore store = new S3ArtifactStore(mockClient, "foo-bar"); assertThat(store.bucketExists(), is(true)); }
@Test public void shouldHandleBucketDoesNotExists() { doThrow(new RuntimeException("Bucket does not exist")).when(mockClient).listObjects(any(ListObjectsRequest.class)); S3ArtifactStore store = new S3ArtifactStore(mockClient, "foo-bar"); assertThat(store.bucketExists(), is(false)); }