diff --git a/TESTING.md b/TESTING.md index 02a3d14ab0bf..2f3637bae8ae 100644 --- a/TESTING.md +++ b/TESTING.md @@ -51,7 +51,8 @@ Currently, there isn't an emulator for Google Cloud Storage, so an alternative i 3. Create a `RemoteGcsHelper` object using your project ID and JSON key. Here is an example that uses the `RemoteGcsHelper` to create a bucket. ```java - RemoteGcsHelper gcsHelper = RemoteGcsHelper.create(PROJECT_ID, "/path/to/my/JSON/key.json"); + RemoteGcsHelper gcsHelper = + RemoteGcsHelper.create(PROJECT_ID, new FileInputStream("/path/to/my/JSON/key.json")); Storage storage = gcsHelper.options().service(); String bucket = RemoteGcsHelper.generateBucketName(); storage.create(BucketInfo.of(bucket)); diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java b/gcloud-java-storage/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java index 5e39bce5ed94..29fdc651af9f 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java @@ -479,8 +479,8 @@ public Tuple read(StorageObject from, Map options, lo } @Override - public void write(String uploadId, byte[] toWrite, int toWriteOffset, StorageObject dest, - long destOffset, int length, boolean last) throws StorageException { + public void write(String uploadId, byte[] toWrite, int toWriteOffset, long destOffset, int length, + boolean last) throws StorageException { try { GenericUrl url = new GenericUrl(uploadId); HttpRequest httpRequest = storage.getRequestFactory().buildPutRequest(url, @@ -571,7 +571,7 @@ private RewriteResponse rewrite(RewriteRequest req, String token) throws Storage try { Long maxBytesRewrittenPerCall = req.megabytesRewrittenPerCall != null ? req.megabytesRewrittenPerCall * MEGABYTE : null; - com.google.api.services.storage.model.RewriteResponse rewriteReponse = storage.objects() + com.google.api.services.storage.model.RewriteResponse rewriteResponse = storage.objects() .rewrite(req.source.getBucket(), req.source.getName(), req.target.getBucket(), req.target.getName(), req.target.getContentType() != null ? req.target : null) .setSourceGeneration(req.source.getGeneration()) @@ -590,11 +590,11 @@ private RewriteResponse rewrite(RewriteRequest req, String token) throws Storage .execute(); return new RewriteResponse( req, - rewriteReponse.getResource(), - rewriteReponse.getObjectSize().longValue(), - rewriteReponse.getDone(), - rewriteReponse.getRewriteToken(), - rewriteReponse.getTotalBytesRewritten().longValue()); + rewriteResponse.getResource(), + rewriteResponse.getObjectSize().longValue(), + rewriteResponse.getDone(), + rewriteResponse.getRewriteToken(), + rewriteResponse.getTotalBytesRewritten().longValue()); } catch (IOException ex) { throw translate(ex); } diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/spi/StorageRpc.java b/gcloud-java-storage/src/main/java/com/google/gcloud/spi/StorageRpc.java index c5fd1b3e2250..e15a27114810 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/spi/StorageRpc.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/spi/StorageRpc.java @@ -264,8 +264,8 @@ Tuple read(StorageObject from, Map options, long posi String open(StorageObject object, Map options) throws StorageException; - void write(String uploadId, byte[] toWrite, int toWriteOffset, StorageObject dest, - long destOffset, int length, boolean last) throws StorageException; + void write(String uploadId, byte[] toWrite, int toWriteOffset, long destOffset, int length, + boolean last) throws StorageException; RewriteResponse openRewrite(RewriteRequest rewriteRequest) throws StorageException; diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Acl.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Acl.java index fd75e10d92fa..0eca39f3b3e5 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Acl.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Acl.java @@ -73,14 +73,14 @@ protected String value() { } @Override - public boolean equals(Object o) { - if (this == o) { + public boolean equals(Object obj) { + if (this == obj) { return true; } - if (o == null || getClass() != o.getClass()) { + if (obj == null || getClass() != obj.getClass()) { return false; } - Entity entity = (Entity) o; + Entity entity = (Entity) obj; return Objects.equals(type, entity.type) && Objects.equals(value, entity.value); } @@ -226,7 +226,7 @@ public static final class Project extends Entity { private static final long serialVersionUID = 7933776866530023027L; - private final ProjectRole pRole; + private final ProjectRole projectRole; private final String projectId; public enum ProjectRole { @@ -236,12 +236,12 @@ public enum ProjectRole { /** * Creates a project entity. * - * @param pRole a role in the project, used to select project's teams + * @param projectRole a role in the project, used to select project's teams * @param projectId id of the project */ - public Project(ProjectRole pRole, String projectId) { - super(Type.PROJECT, pRole.name().toLowerCase() + "-" + projectId); - this.pRole = pRole; + public Project(ProjectRole projectRole, String projectId) { + super(Type.PROJECT, projectRole.name().toLowerCase() + "-" + projectId); + this.projectRole = projectRole; this.projectId = projectId; } @@ -249,7 +249,7 @@ public Project(ProjectRole pRole, String projectId) { * Returns the role in the project for this entity. */ public ProjectRole projectRole() { - return pRole; + return projectRole; } /** @@ -275,7 +275,7 @@ String toPb() { } /** - * Creats an ACL object. + * Creates an ACL object. * * @param entity the entity for this ACL object * @param role the role to associate to the {@code entity} object diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BatchResponse.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BatchResponse.java index 9ac799e74a15..98e7ce09cef0 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BatchResponse.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BatchResponse.java @@ -113,7 +113,7 @@ static Result empty() { } } - public BatchResponse(List> deleteResult, List> updateResult, + BatchResponse(List> deleteResult, List> updateResult, List> getResult) { this.deleteResult = ImmutableList.copyOf(deleteResult); this.updateResult = ImmutableList.copyOf(updateResult); diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Blob.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Blob.java index 6bbc3843f97e..c39a0aa73871 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Blob.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Blob.java @@ -39,8 +39,7 @@ /** * A Google cloud storage object. * - *

- * Objects of this class are immutable. Operations that modify the blob like {@link #update} and + *

Objects of this class are immutable. Operations that modify the blob like {@link #update} and * {@link #copyTo} return a new object. To get a {@code Blob} object with the most recent * information use {@link #reload}. *

@@ -239,13 +238,13 @@ public Blob reload(BlobSourceOption... options) { * made on the metadata generation of the current blob. If you want to update the information only * if the current blob metadata are at their latest version use the {@code metagenerationMatch} * option: {@code blob.update(newInfo, BlobTargetOption.metagenerationMatch())}. - *

- * Original metadata are merged with metadata in the provided {@code blobInfo}. To replace + * + *

Original metadata are merged with metadata in the provided {@code blobInfo}. To replace * metadata instead you first have to unset them. Unsetting metadata can be done by setting the * provided {@code blobInfo}'s metadata to {@code null}. *

- *

- * Example usage of replacing blob's metadata: + * + *

Example usage of replacing blob's metadata: *

    {@code blob.update(blob.info().toBuilder().metadata(null).build());}
    *    {@code blob.update(blob.info().toBuilder().metadata(newMetadata).build());}
    * 
@@ -261,6 +260,17 @@ public Blob update(BlobInfo blobInfo, BlobTargetOption... options) { return new Blob(storage, storage.update(blobInfo, options)); } + /** + * Deletes this blob. + * + * @param options blob delete options + * @return {@code true} if blob was deleted, {@code false} if it was not found + * @throws StorageException upon failure + */ + public boolean delete(BlobSourceOption... options) { + return storage.delete(info.blobId(), toSourceOptions(info, options)); + } + /** * Sends a copy request for the current blob to the target blob. Possibly also some of the * metadata are copied (e.g. content-type). @@ -277,17 +287,6 @@ public CopyWriter copyTo(BlobId targetBlob, BlobSourceOption... options) { return storage.copy(copyRequest); } - /** - * Deletes this blob. - * - * @param options blob delete options - * @return {@code true} if blob was deleted, {@code false} if it was not found - * @throws StorageException upon failure - */ - public boolean delete(BlobSourceOption... options) { - return storage.delete(info.blobId(), toSourceOptions(info, options)); - } - /** * Sends a copy request for the current blob to the target bucket, preserving its name. Possibly * copying also some of the metadata (e.g. content-type). @@ -381,8 +380,8 @@ public static List get(final Storage storage, BlobId... blobs) { return Collections.unmodifiableList(Lists.transform(storage.get(blobs), new Function() { @Override - public Blob apply(BlobInfo f) { - return f != null ? new Blob(storage, f) : null; + public Blob apply(BlobInfo blobInfo) { + return blobInfo != null ? new Blob(storage, blobInfo) : null; } })); } @@ -410,8 +409,8 @@ public static List update(final Storage storage, BlobInfo... infos) { return Collections.unmodifiableList(Lists.transform(storage.update(infos), new Function() { @Override - public Blob apply(BlobInfo f) { - return f != null ? new Blob(storage, f) : null; + public Blob apply(BlobInfo blobInfo) { + return blobInfo != null ? new Blob(storage, blobInfo) : null; } })); } diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobInfo.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobInfo.java index 9d1fd4f5e25c..b27d00d68a16 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobInfo.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobInfo.java @@ -277,7 +277,7 @@ Builder mediaLink(String mediaLink) { */ public Builder metadata(Map metadata) { this.metadata = metadata != null - ? new HashMap(metadata) : Data.nullOf(ImmutableEmptyMap.class); + ? new HashMap<>(metadata) : Data.>nullOf(ImmutableEmptyMap.class); return this; } @@ -576,8 +576,9 @@ public ObjectAccessControl apply(Acl acl) { Map pbMetadata = metadata; if (metadata != null && !Data.isNull(metadata)) { pbMetadata = Maps.newHashMapWithExpectedSize(metadata.size()); - for (String key : metadata.keySet()) { - pbMetadata.put(key, firstNonNull(metadata.get(key), Data.nullOf(String.class))); + for (Map.Entry entry : metadata.entrySet()) { + pbMetadata.put(entry.getKey(), + firstNonNull(entry.getValue(), Data.nullOf(String.class))); } } storageObject.setMetadata(pbMetadata); diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobReadChannel.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobReadChannel.java index 54d39649cb70..106d18466dac 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobReadChannel.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobReadChannel.java @@ -26,8 +26,10 @@ /** * A channel for reading data from a Google Cloud Storage object. * - * Implementations of this class may buffer data internally to reduce remote calls. This interface - * implements {@link Restorable} to allow saving the reader's state to continue reading afterwards. + *

Implementations of this class may buffer data internally to reduce remote calls. This + * interface implements {@link Restorable} to allow saving the reader's state to continue reading + * afterwards. + *

*/ public interface BlobReadChannel extends ReadableByteChannel, Closeable, Restorable { diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobWriteChannel.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobWriteChannel.java index fe9164532120..9682c6345659 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobWriteChannel.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobWriteChannel.java @@ -25,9 +25,10 @@ /** * A channel for writing data to a Google Cloud Storage object. * - * Implementations of this class may further buffer data internally to reduce remote calls. Written - * data will only be visible after calling {@link #close()}. This interface implements + *

Implementations of this class may further buffer data internally to reduce remote calls. + * Written data will only be visible after calling {@link #close()}. This interface implements * {@link Restorable} to allow saving the writer's state to continue writing afterwards. + *

*/ public interface BlobWriteChannel extends WritableByteChannel, Closeable, Restorable { diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobWriteChannelImpl.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobWriteChannelImpl.java index 95656985043f..acde4178533c 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobWriteChannelImpl.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobWriteChannelImpl.java @@ -91,7 +91,7 @@ private void flush() { runWithRetries(callable(new Runnable() { @Override public void run() { - storageRpc.write(uploadId, buffer, 0, storageObject, position, length, false); + storageRpc.write(uploadId, buffer, 0, position, length, false); } }), options.retryParams(), StorageImpl.EXCEPTION_HANDLER); } catch (RetryHelper.RetryHelperException e) { @@ -139,7 +139,7 @@ public void close() throws IOException { runWithRetries(callable(new Runnable() { @Override public void run() { - storageRpc.write(uploadId, buffer, 0, storageObject, position, limit, true); + storageRpc.write(uploadId, buffer, 0, position, limit, true); } }), options.retryParams(), StorageImpl.EXCEPTION_HANDLER); } catch (RetryHelper.RetryHelperException e) { diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Bucket.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Bucket.java index 38a767508356..8a90de143100 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Bucket.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Bucket.java @@ -46,8 +46,7 @@ /** * A Google cloud storage bucket. * - *

- * Objects of this class are immutable. Operations that modify the bucket like {@link #update} + *

Objects of this class are immutable. Operations that modify the bucket like {@link #update} * return a new object. To get a {@code Bucket} object with the most recent information use * {@link #reload}. *

@@ -72,7 +71,7 @@ private static class BlobPageFetcher implements PageImpl.NextPageFetcher { @Override public Page nextPage() { Page nextInfoPage = infoPage.nextPage(); - return new PageImpl(new BlobPageFetcher(options, nextInfoPage), + return new PageImpl<>(new BlobPageFetcher(options, nextInfoPage), nextInfoPage.nextPageCursor(), new LazyBlobIterable(options, nextInfoPage.values())); } } diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/CopyWriter.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/CopyWriter.java index 5f2632b2acde..1e5427a847d4 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/CopyWriter.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/CopyWriter.java @@ -55,8 +55,8 @@ public class CopyWriter implements Restorable { /** * Returns the updated information for the written blob. Calling this method when {@code isDone()} * is {@code false} will block until all pending chunks are copied. - *

- * This method has the same effect of doing: + * + *

This method has the same effect of doing: *

    {@code while (!copyWriter.isDone()) {
    *        copyWriter.copyChunk();
    *    }}
diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Option.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Option.java
index 798db688c8ec..2ec8426bfa9f 100644
--- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Option.java
+++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Option.java
@@ -25,7 +25,7 @@
 import java.util.Objects;
 
 /**
- * Base class for Storage operation option
+ * Base class for Storage operation option.
  */
 class Option implements Serializable {
 
diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java
index 23c3c19a6676..a6c04e45e6c6 100644
--- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java
+++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java
@@ -50,7 +50,7 @@
  */
 public interface Storage extends Service {
 
-  public static final String DEFAULT_CONTENT_TYPE = "application/octet-stream";
+  String DEFAULT_CONTENT_TYPE = "application/octet-stream";
 
   enum PredefinedAcl {
     AUTHENTICATED_READ("authenticatedRead"),
@@ -488,6 +488,14 @@ public static BlobSourceOption generationMatch() {
       return new BlobSourceOption(StorageRpc.Option.IF_GENERATION_MATCH, null);
     }
 
+    /**
+     * Returns an option for blob's data generation match. If this option is used the request will
+     * fail if blob's generation does not match the provided value.
+     */
+    public static BlobSourceOption generationMatch(long generation) {
+      return new BlobSourceOption(StorageRpc.Option.IF_GENERATION_MATCH, generation);
+    }
+
     /**
      * Returns an option for blob's data generation mismatch. If this option is used the request
      * will fail if blob's generation matches. The generation value to compare with the actual
@@ -499,10 +507,6 @@ public static BlobSourceOption generationNotMatch() {
       return new BlobSourceOption(StorageRpc.Option.IF_GENERATION_NOT_MATCH, null);
     }
 
-    public static BlobSourceOption generationMatch(long generation) {
-      return new BlobSourceOption(StorageRpc.Option.IF_GENERATION_MATCH, generation);
-    }
-
     /**
      * Returns an option for blob's data generation mismatch. If this option is used the request
      * will fail if blob's generation matches the provided value.
@@ -554,6 +558,14 @@ public static BlobGetOption generationMatch() {
       return new BlobGetOption(StorageRpc.Option.IF_GENERATION_MATCH, (Long) null);
     }
 
+    /**
+     * Returns an option for blob's data generation match. If this option is used the request will
+     * fail if blob's generation does not match the provided value.
+     */
+    public static BlobGetOption generationMatch(long generation) {
+      return new BlobGetOption(StorageRpc.Option.IF_GENERATION_MATCH, generation);
+    }
+
     /**
      * Returns an option for blob's data generation mismatch. If this option is used the request
      * will fail if blob's generation matches. The generation value to compare with the actual
@@ -565,10 +577,6 @@ public static BlobGetOption generationNotMatch() {
       return new BlobGetOption(StorageRpc.Option.IF_GENERATION_NOT_MATCH, (Long) null);
     }
 
-    public static BlobGetOption generationMatch(long generation) {
-      return new BlobGetOption(StorageRpc.Option.IF_GENERATION_MATCH, generation);
-    }
-
     /**
      * Returns an option for blob's data generation mismatch. If this option is used the request
      * will fail if blob's generation matches the provided value.
@@ -1287,8 +1295,8 @@ private static void checkContentType(BlobInfo blobInfo) throws IllegalArgumentEx
    * Update blob information. Original metadata are merged with metadata in the provided
    * {@code blobInfo}. To replace metadata instead you first have to unset them. Unsetting metadata
    * can be done by setting the provided {@code blobInfo}'s metadata to {@code null}.
-   * 

- * Example usage of replacing blob's metadata: + * + *

Example usage of replacing blob's metadata: *

    {@code service.update(BlobInfo.builder("bucket", "name").metadata(null).build());}
    *    {@code service.update(BlobInfo.builder("bucket", "name").metadata(newMetadata).build());}
    * 
@@ -1302,8 +1310,8 @@ private static void checkContentType(BlobInfo blobInfo) throws IllegalArgumentEx * Update blob information. Original metadata are merged with metadata in the provided * {@code blobInfo}. To replace metadata instead you first have to unset them. Unsetting metadata * can be done by setting the provided {@code blobInfo}'s metadata to {@code null}. - *

- * Example usage of replacing blob's metadata: + * + *

Example usage of replacing blob's metadata: *

    {@code service.update(BlobInfo.builder("bucket", "name").metadata(null).build());}
    *    {@code service.update(BlobInfo.builder("bucket", "name").metadata(newMetadata).build());}
    * 
@@ -1360,8 +1368,8 @@ private static void checkContentType(BlobInfo blobInfo) throws IllegalArgumentEx * returns, regardless of the {@link CopyRequest#megabytesCopiedPerChunk} parameter. * If source and destination have different location or storage class {@link CopyWriter#result()} * might issue multiple RPC calls depending on blob's size. - *

- * Example usage of copy: + * + *

Example usage of copy: *

    {@code BlobInfo blob = service.copy(copyRequest).result();}
    * 
* To explicitly issue chunk copy requests use {@link CopyWriter#copyChunk()} instead: @@ -1449,8 +1457,8 @@ private static void checkContentType(BlobInfo blobInfo) throws IllegalArgumentEx * is only valid within a certain time period. * This is particularly useful if you don't want publicly * accessible blobs, but don't want to require users to explicitly log in. - *

- * Example usage of creating a signed URL that is valid for 2 weeks: + * + *

Example usage of creating a signed URL that is valid for 2 weeks: *

   {@code
    *     service.signUrl(BlobInfo.builder("bucket", "name").build(), 14, TimeUnit.DAYS);
    * }
diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/StorageImpl.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/StorageImpl.java index d1535c92dfdb..85e0b02025af 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/StorageImpl.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/StorageImpl.java @@ -269,6 +269,11 @@ public Page list(BucketListOption... options) { return listBuckets(options(), optionMap(options)); } + @Override + public Page list(final String bucket, BlobListOption... options) { + return listBlobs(bucket, options(), optionMap(options)); + } + private static Page listBuckets(final StorageOptions serviceOptions, final Map optionsMap) { try { @@ -295,11 +300,6 @@ public BucketInfo apply(com.google.api.services.storage.model.Bucket bucketPb) { } } - @Override - public Page list(final String bucket, BlobListOption... options) { - return listBlobs(bucket, options(), optionMap(options)); - } - private static Page listBlobs(final String bucket, final StorageOptions serviceOptions, final Map optionsMap) { try { @@ -554,8 +554,6 @@ private BlobWriteChannel writer(BlobInfo blobInfo, BlobTargetOption... options) @Override public URL signUrl(BlobInfo blobInfo, long duration, TimeUnit unit, SignUrlOption... options) { - long expiration = TimeUnit.SECONDS.convert( - options().clock().millis() + unit.toMillis(duration), TimeUnit.MILLISECONDS); EnumMap optionMap = Maps.newEnumMap(SignUrlOption.Option.class); for (SignUrlOption option : options) { optionMap.put(option.option(), option.value()); @@ -588,6 +586,8 @@ public URL signUrl(BlobInfo blobInfo, long duration, TimeUnit unit, SignUrlOptio stBuilder.append(blobInfo.contentType()); } stBuilder.append('\n'); + long expiration = TimeUnit.SECONDS.convert( + options().clock().millis() + unit.toMillis(duration), TimeUnit.MILLISECONDS); stBuilder.append(expiration).append('\n'); StringBuilder path = new StringBuilder(); if (!blobInfo.bucket().startsWith("/")) { @@ -606,9 +606,9 @@ public URL signUrl(BlobInfo blobInfo, long duration, TimeUnit unit, SignUrlOptio Signature signer = Signature.getInstance("SHA256withRSA"); signer.initSign(cred.getPrivateKey()); signer.update(stBuilder.toString().getBytes(UTF_8)); + stBuilder = new StringBuilder("https://storage.googleapis.com").append(path); String signature = URLEncoder.encode(BaseEncoding.base64().encode(signer.sign()), UTF_8.name()); - stBuilder = new StringBuilder("https://storage.googleapis.com").append(path); stBuilder.append("?GoogleAccessId=").append(cred.getClientEmail()); stBuilder.append("&Expires=").append(expiration); stBuilder.append("&Signature=").append(signature); @@ -654,12 +654,29 @@ private static List transformResultList( List> results, final T errorValue) { return Lists.transform(results, new Function, T>() { @Override - public T apply(BatchResponse.Result f) { - return f.failed() ? errorValue : f.get(); + public T apply(BatchResponse.Result result) { + return result.failed() ? errorValue : result.get(); } }); } + private static void addToOptionMap(StorageRpc.Option option, T defaultValue, + Map map) { + addToOptionMap(option, option, defaultValue, map); + } + + private static void addToOptionMap(StorageRpc.Option getOption, StorageRpc.Option putOption, + T defaultValue, Map map) { + if (map.containsKey(getOption)) { + @SuppressWarnings("unchecked") + T value = (T) map.remove(getOption); + checkArgument(value != null || defaultValue != null, + "Option " + getOption.value() + " is missing a value"); + value = firstNonNull(value, defaultValue); + map.put(putOption, value); + } + } + private Map optionMap(Long generation, Long metaGeneration, Iterable options) { return optionMap(generation, metaGeneration, options, false); @@ -691,23 +708,6 @@ public T apply(BatchResponse.Result f) { return ImmutableMap.copyOf(temp); } - private static void addToOptionMap(StorageRpc.Option option, T defaultValue, - Map map) { - addToOptionMap(option, option, defaultValue, map); - } - - private static void addToOptionMap(StorageRpc.Option getOption, StorageRpc.Option putOption, - T defaultValue, Map map) { - if (map.containsKey(getOption)) { - @SuppressWarnings("unchecked") - T value = (T) map.remove(getOption); - checkArgument(value != null || defaultValue != null, - "Option " + getOption.value() + " is missing a value"); - value = firstNonNull(value, defaultValue); - map.put(putOption, value); - } - } - private Map optionMap(Option... options) { return optionMap(null, null, Arrays.asList(options)); } diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/package-info.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/package-info.java index 137afd38b6ae..a55b23c3666c 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/package-info.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/package-info.java @@ -34,7 +34,7 @@ * channel.close(); * }}
* - * When using gcloud-java from outside of App/Compute Engine, you have to When using gcloud-java from outside of App/Compute Engine, you have to specify a * project ID and * provide diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/RemoteGcsHelper.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/RemoteGcsHelper.java index f5cdae83f999..77cb5661a614 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/RemoteGcsHelper.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/RemoteGcsHelper.java @@ -23,8 +23,6 @@ import com.google.gcloud.storage.StorageException; import com.google.gcloud.storage.StorageOptions; -import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.util.UUID; @@ -39,7 +37,14 @@ import java.util.logging.Logger; /** - * Utility to create a remote storage configuration for testing + * Utility to create a remote storage configuration for testing. Storage options can be obtained via + * the {@link #options()} method. Returned options have custom {@link StorageOptions#retryParams()}: + * {@link RetryParams#retryMaxAttempts()} is {@code 10}, {@link RetryParams#retryMinAttempts()} is + * {@code 6}, {@link RetryParams#maxRetryDelayMillis()} is {@code 30000}, + * {@link RetryParams#totalRetryPeriodMillis()} is {@code 120000} and + * {@link RetryParams#initialRetryDelayMillis()} is {@code 250}. + * {@link StorageOptions#connectTimeout()} and {@link StorageOptions#readTimeout()} are both set + * to {@code 60000}. */ public class RemoteGcsHelper { @@ -118,28 +123,6 @@ public static RemoteGcsHelper create(String projectId, InputStream keyStream) } } - /** - * Creates a {@code RemoteGcsHelper} object for the given project id and JSON key path. - * - * @param projectId id of the project to be used for running the tests - * @param keyPath path to the JSON key to be used for running the tests - * @return A {@code RemoteGcsHelper} object for the provided options. - * @throws com.google.gcloud.storage.testing.RemoteGcsHelper.GcsHelperException if the file - * pointed by {@code keyPath} does not exist - */ - public static RemoteGcsHelper create(String projectId, String keyPath) - throws GcsHelperException { - try { - InputStream keyFileStream = new FileInputStream(keyPath); - return create(projectId, keyFileStream); - } catch (FileNotFoundException ex) { - if (log.isLoggable(Level.WARNING)) { - log.log(Level.WARNING, ex.getMessage()); - } - throw GcsHelperException.translate(ex); - } - } - /** * Creates a {@code RemoteGcsHelper} object using default project id and authentication * credentials. diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/package-info.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/package-info.java index 82b3578284dc..8afdd8a9660d 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/package-info.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/package-info.java @@ -18,9 +18,10 @@ * A testing helper for Google Cloud Storage. * *

A simple usage example: + * *

Before the test: *

 {@code
- * RemoteGcsHelper gcsHelper = RemoteGcsHelper.create(PROJECT_ID, "/path/to/JSON/key.json");
+ * RemoteGcsHelper gcsHelper = RemoteGcsHelper.create();
  * Storage storage = gcsHelper.options().service();
  * String bucket = RemoteGcsHelper.generateBucketName();
  * storage.create(BucketInfo.of(bucket));
diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobTest.java
index 3998ae554327..4f5eb4022744 100644
--- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobTest.java
+++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobTest.java
@@ -25,6 +25,7 @@
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
@@ -100,7 +101,7 @@ public void testReload() throws Exception {
     expect(storage.get(BLOB_INFO.blobId(), new Storage.BlobGetOption[0])).andReturn(updatedInfo);
     replay(storage);
     Blob updatedBlob = blob.reload();
-    assertSame(storage, blob.storage());
+    assertSame(storage, updatedBlob.storage());
     assertEquals(updatedInfo, updatedBlob.info());
   }
 
@@ -272,13 +273,13 @@ public void testDeleteNone() throws Exception {
 
   @Test
   public void testDeleteSome() throws Exception {
-    List deleleResultList = Arrays.asList(true, true, true);
-    expect(storage.delete(BLOB_ID_ARRAY)).andReturn(deleleResultList);
+    List deleteResult = Arrays.asList(true, true, true);
+    expect(storage.delete(BLOB_ID_ARRAY)).andReturn(deleteResult);
     replay(storage);
     List result = Blob.delete(storage, BLOB_ID_ARRAY);
-    assertEquals(deleleResultList.size(), result.size());
-    for (int i = 0; i < deleleResultList.size(); i++) {
-      assertEquals(deleleResultList.get(i), result.get(i));
+    assertEquals(deleteResult.size(), result.size());
+    for (int i = 0; i < deleteResult.size(); i++) {
+      assertEquals(deleteResult.get(i), result.get(i));
     }
   }
 
@@ -295,6 +296,7 @@ public void testLoadFromId() throws Exception {
     expect(storage.get(BLOB_INFO.blobId())).andReturn(BLOB_INFO);
     replay(storage);
     Blob loadedBlob = Blob.load(storage, BLOB_INFO.blobId());
+    assertNotNull(loadedBlob);
     assertEquals(BLOB_INFO, loadedBlob.info());
   }
 }
diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobWriteChannelImplTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobWriteChannelImplTest.java
index c2107ff13998..952be543a913 100644
--- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobWriteChannelImplTest.java
+++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobWriteChannelImplTest.java
@@ -102,8 +102,8 @@ public void testWriteWithoutFlush() throws IOException {
   public void testWriteWithFlush() throws IOException {
     expect(storageRpcMock.open(BLOB_INFO.toPb(), EMPTY_RPC_OPTIONS)).andReturn(UPLOAD_ID);
     Capture capturedBuffer = Capture.newInstance();
-    storageRpcMock.write(eq(UPLOAD_ID), capture(capturedBuffer), eq(0),
-        eq(BLOB_INFO.toPb()), eq(0L), eq(CUSTOM_CHUNK_SIZE), eq(false));
+    storageRpcMock.write(eq(UPLOAD_ID), capture(capturedBuffer), eq(0), eq(0L),
+        eq(CUSTOM_CHUNK_SIZE), eq(false));
     replay(storageRpcMock);
     writer = new BlobWriteChannelImpl(options, BLOB_INFO, EMPTY_RPC_OPTIONS);
     writer.chunkSize(CUSTOM_CHUNK_SIZE);
@@ -116,9 +116,8 @@ public void testWriteWithFlush() throws IOException {
   public void testWritesAndFlush() throws IOException {
     expect(storageRpcMock.open(BLOB_INFO.toPb(), EMPTY_RPC_OPTIONS)).andReturn(UPLOAD_ID);
     Capture capturedBuffer = Capture.newInstance();
-    storageRpcMock.write(eq(UPLOAD_ID), capture(capturedBuffer), eq(0),
-        eq(BLOB_INFO.toPb()), eq(0L), eq(DEFAULT_CHUNK_SIZE),
-        eq(false));
+    storageRpcMock.write(eq(UPLOAD_ID), capture(capturedBuffer), eq(0), eq(0L),
+        eq(DEFAULT_CHUNK_SIZE), eq(false));
     replay(storageRpcMock);
     writer = new BlobWriteChannelImpl(options, BLOB_INFO, EMPTY_RPC_OPTIONS);
     ByteBuffer[] buffers = new ByteBuffer[DEFAULT_CHUNK_SIZE / MIN_CHUNK_SIZE];
@@ -138,8 +137,7 @@ public void testWritesAndFlush() throws IOException {
   public void testCloseWithoutFlush() throws IOException {
     expect(storageRpcMock.open(BLOB_INFO.toPb(), EMPTY_RPC_OPTIONS)).andReturn(UPLOAD_ID);
     Capture capturedBuffer = Capture.newInstance();
-    storageRpcMock.write(eq(UPLOAD_ID), capture(capturedBuffer), eq(0),
-        eq(BLOB_INFO.toPb()), eq(0L), eq(0), eq(true));
+    storageRpcMock.write(eq(UPLOAD_ID), capture(capturedBuffer), eq(0), eq(0L), eq(0), eq(true));
     replay(storageRpcMock);
     writer = new BlobWriteChannelImpl(options, BLOB_INFO, EMPTY_RPC_OPTIONS);
     assertTrue(writer.isOpen());
@@ -153,8 +151,7 @@ public void testCloseWithFlush() throws IOException {
     expect(storageRpcMock.open(BLOB_INFO.toPb(), EMPTY_RPC_OPTIONS)).andReturn(UPLOAD_ID);
     Capture capturedBuffer = Capture.newInstance();
     ByteBuffer buffer = randomBuffer(MIN_CHUNK_SIZE);
-    storageRpcMock.write(eq(UPLOAD_ID), capture(capturedBuffer), eq(0),
-        eq(BLOB_INFO.toPb()), eq(0L), eq(MIN_CHUNK_SIZE),
+    storageRpcMock.write(eq(UPLOAD_ID), capture(capturedBuffer), eq(0), eq(0L), eq(MIN_CHUNK_SIZE),
         eq(true));
     replay(storageRpcMock);
     writer = new BlobWriteChannelImpl(options, BLOB_INFO, EMPTY_RPC_OPTIONS);
@@ -170,8 +167,7 @@ public void testCloseWithFlush() throws IOException {
   public void testWriteClosed() throws IOException {
     expect(storageRpcMock.open(BLOB_INFO.toPb(), EMPTY_RPC_OPTIONS)).andReturn(UPLOAD_ID);
     Capture capturedBuffer = Capture.newInstance();
-    storageRpcMock.write(eq(UPLOAD_ID), capture(capturedBuffer), eq(0),
-        eq(BLOB_INFO.toPb()), eq(0L), eq(0), eq(true));
+    storageRpcMock.write(eq(UPLOAD_ID), capture(capturedBuffer), eq(0), eq(0L), eq(0), eq(true));
     replay(storageRpcMock);
     writer = new BlobWriteChannelImpl(options, BLOB_INFO, EMPTY_RPC_OPTIONS);
     writer.close();
@@ -189,8 +185,7 @@ public void testSaveAndRestore() throws IOException {
     Capture capturedBuffer = Capture.newInstance(CaptureType.ALL);
     Capture capturedPosition = Capture.newInstance(CaptureType.ALL);
     storageRpcMock.write(eq(UPLOAD_ID), capture(capturedBuffer), eq(0),
-        eq(BLOB_INFO.toPb()), captureLong(capturedPosition),
-        eq(DEFAULT_CHUNK_SIZE), eq(false));
+        captureLong(capturedPosition), eq(DEFAULT_CHUNK_SIZE), eq(false));
     expectLastCall().times(2);
     replay(storageRpcMock);
     ByteBuffer buffer1 = randomBuffer(DEFAULT_CHUNK_SIZE);
@@ -210,8 +205,7 @@ public void testSaveAndRestore() throws IOException {
   public void testSaveAndRestoreClosed() throws IOException {
     expect(storageRpcMock.open(BLOB_INFO.toPb(), EMPTY_RPC_OPTIONS)).andReturn(UPLOAD_ID);
     Capture capturedBuffer = Capture.newInstance();
-    storageRpcMock.write(eq(UPLOAD_ID), capture(capturedBuffer), eq(0),
-        eq(BLOB_INFO.toPb()), eq(0L), eq(0), eq(true));
+    storageRpcMock.write(eq(UPLOAD_ID), capture(capturedBuffer), eq(0), eq(0L), eq(0), eq(true));
     replay(storageRpcMock);
     writer = new BlobWriteChannelImpl(options, BLOB_INFO, EMPTY_RPC_OPTIONS);
     writer.close();
diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BucketTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BucketTest.java
index 596f43a3c87a..81e7a68b2465 100644
--- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BucketTest.java
+++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BucketTest.java
@@ -23,6 +23,7 @@
 import static org.easymock.EasyMock.verify;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
 
@@ -95,7 +96,7 @@ public void testReload() throws Exception {
     expect(storage.get(updatedInfo.name())).andReturn(updatedInfo);
     replay(storage);
     Bucket updatedBucket = bucket.reload();
-    assertSame(storage, bucket.storage());
+    assertSame(storage, updatedBucket.storage());
     assertEquals(updatedInfo, updatedBucket.info());
   }
 
@@ -219,6 +220,7 @@ public void testLoad() throws Exception {
     expect(storage.get(BUCKET_INFO.name())).andReturn(BUCKET_INFO);
     replay(storage);
     Bucket loadedBucket = Bucket.load(storage, BUCKET_INFO.name());
+    assertNotNull(loadedBucket);
     assertEquals(BUCKET_INFO, loadedBucket.info());
   }
 }
diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java
index 22b0a35c0620..30ce858dc20e 100644
--- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java
+++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java
@@ -271,7 +271,7 @@ public void testGetBlobFailNonExistingGeneration() {
   public void testListBlobsSelectedFields() {
     String[] blobNames = {"test-list-blobs-selected-fields-blob1",
         "test-list-blobs-selected-fields-blob2"};
-    ImmutableMap metadata = ImmutableMap.of("k", "v");
+    ImmutableMap metadata = ImmutableMap.of("k", "v");
     BlobInfo blob1 = BlobInfo.builder(BUCKET, blobNames[0])
         .contentType(CONTENT_TYPE)
         .metadata(metadata)
diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/RemoteGcsHelperTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/RemoteGcsHelperTest.java
index 3c3d1aebb3df..6b67a9576dc6 100644
--- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/RemoteGcsHelperTest.java
+++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/RemoteGcsHelperTest.java
@@ -24,18 +24,14 @@
 import com.google.gcloud.storage.testing.RemoteGcsHelper;
 
 import org.easymock.EasyMock;
-import org.junit.BeforeClass;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
-import java.nio.file.Files;
-import java.nio.file.Paths;
 import java.util.Iterator;
 import java.util.List;
-import java.util.UUID;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 
@@ -97,18 +93,10 @@ public Iterator iterateAll() {
       return BLOB_LIST.iterator();
     }
   };
-  private static String keyPath = "/does/not/exist/key." + UUID.randomUUID().toString() + ".json";
 
   @Rule
   public ExpectedException thrown = ExpectedException.none();
 
-  @BeforeClass
-  public static void beforeClass() {
-    while (Files.exists(Paths.get(JSON_KEY))) {
-      keyPath = "/does/not/exist/key." + UUID.randomUUID().toString() + ".json";
-    }
-  }
-
   @Test
   public void testForceDelete() throws InterruptedException, ExecutionException {
     Storage storageMock = EasyMock.createMock(Storage.class);
@@ -165,11 +153,4 @@ public void testCreateFromStream() {
     assertEquals(120000, options.retryParams().totalRetryPeriodMillis());
     assertEquals(250, options.retryParams().initialRetryDelayMillis());
   }
-
-  @Test
-  public void testCreateNoKey() {
-    thrown.expect(RemoteGcsHelper.GcsHelperException.class);
-    thrown.expectMessage(keyPath + " (No such file or directory)");
-    RemoteGcsHelper.create(PROJECT_ID, keyPath);
-  }
 }
diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/StorageImplTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/StorageImplTest.java
index dea635c3d264..007ac4b2a15a 100644
--- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/StorageImplTest.java
+++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/StorageImplTest.java
@@ -398,8 +398,7 @@ public void testGetBucketWithOptions() {
 
   @Test
   public void testGetBucketWithSelectedFields() {
-    Capture> capturedOptions =
-        Capture.>newInstance();
+    Capture> capturedOptions = Capture.newInstance();
     EasyMock.expect(storageRpcMock.get(EasyMock.eq(BucketInfo.of(BUCKET_NAME1).toPb()),
         EasyMock.capture(capturedOptions))).andReturn(BUCKET_INFO1.toPb());
     EasyMock.replay(storageRpcMock);
@@ -417,8 +416,7 @@ public void testGetBucketWithSelectedFields() {
 
   @Test
   public void testGetBucketWithEmptyFields() {
-    Capture> capturedOptions =
-        Capture.>newInstance();
+    Capture> capturedOptions = Capture.newInstance();
     EasyMock.expect(storageRpcMock.get(EasyMock.eq(BucketInfo.of(BUCKET_NAME1).toPb()),
         EasyMock.capture(capturedOptions))).andReturn(BUCKET_INFO1.toPb());
     EasyMock.replay(storageRpcMock);
@@ -470,8 +468,7 @@ public void testGetBlobWithOptionsFromBlobId() {
 
   @Test
   public void testGetBlobWithSelectedFields() {
-    Capture> capturedOptions =
-        Capture.>newInstance();
+    Capture> capturedOptions = Capture.newInstance();
     EasyMock.expect(storageRpcMock.get(EasyMock.eq(BlobId.of(BUCKET_NAME1, BLOB_NAME1).toPb()),
         EasyMock.capture(capturedOptions))).andReturn(BLOB_INFO1.toPb());
     EasyMock.replay(storageRpcMock);
@@ -493,8 +490,7 @@ public void testGetBlobWithSelectedFields() {
 
   @Test
   public void testGetBlobWithEmptyFields() {
-    Capture> capturedOptions =
-        Capture.>newInstance();
+    Capture> capturedOptions = Capture.newInstance();
     EasyMock.expect(storageRpcMock.get(EasyMock.eq(BlobId.of(BUCKET_NAME1, BLOB_NAME1).toPb()),
         EasyMock.capture(capturedOptions))).andReturn(BLOB_INFO1.toPb());
     EasyMock.replay(storageRpcMock);
@@ -555,8 +551,7 @@ public void testListBucketsWithOptions() {
   @Test
   public void testListBucketsWithSelectedFields() {
     String cursor = "cursor";
-    Capture> capturedOptions =
-        Capture.>newInstance();
+    Capture> capturedOptions = Capture.newInstance();
     ImmutableList bucketList = ImmutableList.of(BUCKET_INFO1, BUCKET_INFO2);
     Tuple> result =
         Tuple.of(cursor, Iterables.transform(bucketList, BucketInfo.TO_PB_FUNCTION));
@@ -577,8 +572,7 @@ public void testListBucketsWithSelectedFields() {
   @Test
   public void testListBucketsWithEmptyFields() {
     String cursor = "cursor";
-    Capture> capturedOptions =
-        Capture.>newInstance();
+    Capture> capturedOptions = Capture.newInstance();
     ImmutableList bucketList = ImmutableList.of(BUCKET_INFO1, BUCKET_INFO2);
     Tuple> result =
         Tuple.of(cursor, Iterables.transform(bucketList, BucketInfo.TO_PB_FUNCTION));
@@ -638,8 +632,7 @@ public void testListBlobsWithOptions() {
   @Test
   public void testListBlobsWithSelectedFields() {
     String cursor = "cursor";
-    Capture> capturedOptions =
-        Capture.>newInstance();
+    Capture> capturedOptions = Capture.newInstance();
     ImmutableList blobList = ImmutableList.of(BLOB_INFO1, BLOB_INFO2);
     Tuple> result =
         Tuple.of(cursor, Iterables.transform(blobList, BlobInfo.TO_PB_FUNCTION));
@@ -668,8 +661,7 @@ public void testListBlobsWithSelectedFields() {
   @Test
   public void testListBlobsWithEmptyFields() {
     String cursor = "cursor";
-    Capture> capturedOptions =
-        Capture.>newInstance();
+    Capture> capturedOptions = Capture.newInstance();
     ImmutableList blobList = ImmutableList.of(BLOB_INFO1, BLOB_INFO2);
     Tuple> result =
         Tuple.of(cursor, Iterables.transform(blobList, BlobInfo.TO_PB_FUNCTION));