StorageSample { public static String listBucket(final String bucketName) throws IOException, GeneralSecurityException { GoogleCredentials credential = GoogleCredentials.getApplicationDefault() .createScoped(Collections.singleton(STORAGE_SCOPE)); String uri = "https: HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport(); HttpRequestFactory requestFactory = httpTransport.createRequestFactory(new HttpCredentialsAdapter(credential)); GenericUrl url = new GenericUrl(uri); HttpRequest request = requestFactory.buildGetRequest(url); HttpResponse response = request.execute(); String content = response.parseAsString(); return content; } private  StorageSample(); static String listBucket(final String bucketName); static void main(final String[] args);  }
@Test public void testListBucket() throws Exception { String listing = StorageSample.listBucket(PROJECT_ID); assertThat(listing) .containsMatch( ".*<ListBucketResult.*" + "<Name>" + PROJECT_ID + "</Name>.*" + "</ListBucketResult>.*"); }