From a02f0e932582013f54850a098dc44cf3668f341c Mon Sep 17 00:00:00 2001 From: Justine Tunney Date: Wed, 2 Mar 2016 19:23:54 -0500 Subject: [PATCH] Run google-java-format on GCS NIO I also made the following additional changes: - Don't use one-line javadocs, per request of @aozarov - Use public domain John Keats poetry published in 1819 - Minor cleanup to a few JavaDocs --- .../nio/CloudStorageConfiguration.java | 9 +- .../nio/CloudStorageFileAttributeView.java | 25 ++--- .../contrib/nio/CloudStorageFileSystem.java | 63 ++++++----- .../nio/CloudStorageFileSystemProvider.java | 104 ++++++++++-------- .../nio/CloudStorageObjectAttributes.java | 9 +- .../CloudStorageObjectImmutableException.java | 5 +- .../contrib/nio/CloudStorageOption.java | 16 ++- .../contrib/nio/CloudStorageOptions.java | 12 +- .../storage/contrib/nio/CloudStoragePath.java | 42 ++++--- ...CloudStoragePseudoDirectoryAttributes.java | 6 +- .../CloudStoragePseudoDirectoryException.java | 5 +- .../contrib/nio/CloudStorageReadChannel.java | 13 ++- .../storage/contrib/nio/CloudStorageUtil.java | 23 ++-- .../gcloud/storage/contrib/nio/UnixPath.java | 85 +++++++++----- .../storage/contrib/nio/package-info.java | 4 +- .../nio/CloudStorageConfigurationTest.java | 39 ++++--- .../CloudStorageFileAttributeViewTest.java | 16 ++- .../nio/CloudStorageFileAttributesTest.java | 22 ++-- .../CloudStorageFileSystemProviderTest.java | 79 +++++++------ .../nio/CloudStorageFileSystemTest.java | 28 ++--- .../contrib/nio/CloudStorageOptionsTest.java | 34 +++--- .../contrib/nio/CloudStoragePathTest.java | 30 ++--- .../nio/CloudStorageReadChannelTest.java | 11 +- .../nio/CloudStorageWriteChannelTest.java | 7 +- .../storage/contrib/nio/UnixPathTest.java | 16 ++- 25 files changed, 397 insertions(+), 306 deletions(-) diff --git a/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStorageConfiguration.java b/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStorageConfiguration.java index 6659bd4d8857..5dc4946c06b1 100644 --- a/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStorageConfiguration.java +++ b/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStorageConfiguration.java @@ -6,12 +6,14 @@ import java.util.Map; -/** CloudStorageConfiguration is the configuration class for - * {@link CloudStorageFileSystem#forBucket}. */ +/** + * Configuration for a {@link CloudStorageFileSystem} instance. + */ @AutoValue public abstract class CloudStorageConfiguration { - /** Returns the path of the current working directory. Defaults to the root directory. + /** + * Returns path of the current working directory. This defaults to the root directory. */ public abstract String workingDirectory(); @@ -107,7 +109,6 @@ public Builder blockSize(int value) { return this; } - /** Creates a new instance, but does not destroy the builder. */ public CloudStorageConfiguration build() { diff --git a/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStorageFileAttributeView.java b/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStorageFileAttributeView.java index 181870560bfe..0a63363d4893 100644 --- a/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStorageFileAttributeView.java +++ b/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStorageFileAttributeView.java @@ -1,6 +1,6 @@ package com.google.gcloud.storage.contrib.nio; -import static com.google.common.base.Verify.verifyNotNull; +import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.base.MoreObjects; import com.google.gcloud.storage.BlobInfo; @@ -15,21 +15,22 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; -/** Metadata view for a Google Cloud Storage object. +/** + * Metadata view for a Google Cloud Storage object. */ @Immutable public final class CloudStorageFileAttributeView implements BasicFileAttributeView { - //private final CloudStorageFileSystemProvider provider; private final Storage storage; private final CloudStoragePath path; CloudStorageFileAttributeView(Storage storage, CloudStoragePath path) { - this.storage = verifyNotNull(storage); - this.path = verifyNotNull(path); + this.storage = checkNotNull(storage); + this.path = checkNotNull(path); } - /** Returns {@value CloudStorageFileSystem#GCS_VIEW}. + /** + * Returns {@value CloudStorageFileSystem#GCS_VIEW}. */ @Override public String name() { @@ -38,8 +39,7 @@ public String name() { @Override public CloudStorageFileAttributes readAttributes() throws IOException { - if (path.seemsLikeADirectory() - && path.getFileSystem().config().usePseudoDirectories()) { + if (path.seemsLikeADirectory() && path.getFileSystem().config().usePseudoDirectories()) { return new CloudStoragePseudoDirectoryAttributes(path); } BlobInfo blobInfo = storage.get(path.getBlobId()); @@ -62,8 +62,8 @@ public void setTimes(FileTime lastModifiedTime, FileTime lastAccessTime, FileTim public boolean equals(@Nullable Object other) { return this == other || other instanceof CloudStorageFileAttributeView - && Objects.equals(storage, ((CloudStorageFileAttributeView) other).storage) - && Objects.equals(path, ((CloudStorageFileAttributeView) other).path); + && Objects.equals(storage, ((CloudStorageFileAttributeView) other).storage) + && Objects.equals(path, ((CloudStorageFileAttributeView) other).path); } @Override @@ -73,9 +73,6 @@ public int hashCode() { @Override public String toString() { - return MoreObjects.toStringHelper(this) - .add("storage", storage) - .add("path", path) - .toString(); + return MoreObjects.toStringHelper(this).add("storage", storage).add("path", path).toString(); } } diff --git a/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStorageFileSystem.java b/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStorageFileSystem.java index 8cec0845600c..50185974f924 100644 --- a/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStorageFileSystem.java +++ b/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStorageFileSystem.java @@ -57,8 +57,8 @@ public static CloudStorageFileSystem forBucket(String bucket) { * @see #forBucket(String) */ public static CloudStorageFileSystem forBucket(String bucket, CloudStorageConfiguration config) { - checkArgument(!bucket.startsWith(URI_SCHEME + ":"), - "Bucket name must not have schema: %s", bucket); + checkArgument( + !bucket.startsWith(URI_SCHEME + ":"), "Bucket name must not have schema: %s", bucket); return new CloudStorageFileSystem( new CloudStorageFileSystemProvider(), bucket, checkNotNull(config)); } @@ -75,9 +75,7 @@ public static CloudStorageFileSystem forBucket(String bucket, CloudStorageConfig private final CloudStorageConfiguration config; CloudStorageFileSystem( - CloudStorageFileSystemProvider provider, - String bucket, - CloudStorageConfiguration config) { + CloudStorageFileSystemProvider provider, String bucket, CloudStorageConfiguration config) { checkArgument(!bucket.isEmpty(), "bucket"); this.provider = provider; this.bucket = bucket; @@ -89,47 +87,56 @@ public CloudStorageFileSystemProvider provider() { return provider; } - /** Returns the Cloud Storage bucket name being served by this file system. - */ + /** + * Returns the Cloud Storage bucket name being served by this file system. + */ public String bucket() { return bucket; } - /** Returns the configuration object for this filesystem instance. - */ + /** + * Returns the configuration object for this filesystem instance. + */ public CloudStorageConfiguration config() { return config; } - /** Converts a cloud storage object name to a {@link Path} object. - */ + /** + * Converts a cloud storage object name to a {@link Path} object. + */ @Override public CloudStoragePath getPath(String first, String... more) { - checkArgument(!first.startsWith(URI_SCHEME + ":"), - "GCS FileSystem.getPath() must not have schema and bucket name: %s", first); + checkArgument( + !first.startsWith(URI_SCHEME + ":"), + "GCS FileSystem.getPath() must not have schema and bucket name: %s", + first); return CloudStoragePath.getPath(this, first, more); } - /** Does nothing. - */ + /** + * Does nothing. + */ @Override public void close() {} - /** Returns {@code true}. - */ + /** + * Returns {@code true}. + */ @Override public boolean isOpen() { return true; } - /** Returns {@code false}. - */ + /** + * Returns {@code false}. + */ @Override public boolean isReadOnly() { return false; } - /** Returns {@value UnixPath#SEPARATOR}. + /** + * Returns {@value UnixPath#SEPARATOR}. */ @Override public String getSeparator() { @@ -151,22 +158,26 @@ public Set supportedFileAttributeViews() { return SUPPORTED_VIEWS; } - /** Always throws {@link UnsupportedOperationException}. */ + /** + * Throws {@link UnsupportedOperationException} because this feature hasn't been implemented yet. + */ @Override public PathMatcher getPathMatcher(String syntaxAndPattern) { // TODO: Implement me. throw new UnsupportedOperationException(); } - /** Always throws {@link UnsupportedOperationException}. - */ + /** + * Throws {@link UnsupportedOperationException} because this feature hasn't been implemented yet. + */ @Override public UserPrincipalLookupService getUserPrincipalLookupService() { // TODO: Implement me. throw new UnsupportedOperationException(); } - /** Always throws {@link UnsupportedOperationException}. + /** + * Throws {@link UnsupportedOperationException} because this feature hasn't been implemented yet. */ @Override public WatchService newWatchService() throws IOException { @@ -178,8 +189,8 @@ public WatchService newWatchService() throws IOException { public boolean equals(@Nullable Object other) { return this == other || other instanceof CloudStorageFileSystem - && Objects.equals(config, ((CloudStorageFileSystem) other).config) - && Objects.equals(bucket, ((CloudStorageFileSystem) other).bucket); + && Objects.equals(config, ((CloudStorageFileSystem) other).config) + && Objects.equals(bucket, ((CloudStorageFileSystem) other).bucket); } @Override diff --git a/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStorageFileSystemProvider.java b/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStorageFileSystemProvider.java index 240140cb071f..44e0933bccc0 100644 --- a/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStorageFileSystemProvider.java +++ b/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStorageFileSystemProvider.java @@ -68,7 +68,9 @@ public final class CloudStorageFileSystemProvider extends FileSystemProvider { // used only when we create a new instance of CloudStorageFileSystemProvider. private static StorageOptions storageOptions; - /** Those options are only used by the CloudStorageFileSystemProvider ctor. */ + /** + * Sets options that are only used by the constructor. + */ @VisibleForTesting public static void setGCloudOptions(StorageOptions newStorageOptions) { storageOptions = newStorageOptions; @@ -97,25 +99,34 @@ public String getScheme() { return URI_SCHEME; } - /** Returns cloud storage file system, provided a URI with no path, e.g. {@code gs://bucket} */ + /** + * Returns cloud storage file system, provided a URI with no path, e.g. {@code gs://bucket}. + */ @Override public CloudStorageFileSystem getFileSystem(URI uri) { return newFileSystem(uri, Collections.emptyMap()); } - /** Returns cloud storage file system, provided a URI with no path, e.g. {@code gs://bucket} */ + /** + * Returns cloud storage file system, provided a URI with no path, e.g. {@code gs://bucket}. + */ @Override public CloudStorageFileSystem newFileSystem(URI uri, Map env) { - checkArgument(uri.getScheme().equalsIgnoreCase(URI_SCHEME), - "Cloud Storage URIs must have '%s' scheme: %s", URI_SCHEME, uri); - checkArgument(!isNullOrEmpty(uri.getHost()), - "%s:// URIs must have a host: %s", URI_SCHEME, uri); - checkArgument(uri.getPort() == -1 - && isNullOrEmpty(uri.getPath()) - && isNullOrEmpty(uri.getQuery()) - && isNullOrEmpty(uri.getFragment()) - && isNullOrEmpty(uri.getUserInfo()), - "GCS FileSystem URIs mustn't have: port, userinfo, path, query, or fragment: %s", uri); + checkArgument( + uri.getScheme().equalsIgnoreCase(URI_SCHEME), + "Cloud Storage URIs must have '%s' scheme: %s", + URI_SCHEME, + uri); + checkArgument( + !isNullOrEmpty(uri.getHost()), "%s:// URIs must have a host: %s", URI_SCHEME, uri); + checkArgument( + uri.getPort() == -1 + && isNullOrEmpty(uri.getPath()) + && isNullOrEmpty(uri.getQuery()) + && isNullOrEmpty(uri.getFragment()) + && isNullOrEmpty(uri.getUserInfo()), + "GCS FileSystem URIs mustn't have: port, userinfo, path, query, or fragment: %s", + uri); checkBucket(uri.getHost()); return new CloudStorageFileSystem(this, uri.getHost(), CloudStorageConfiguration.fromMap(env)); } @@ -138,8 +149,8 @@ public SeekableByteChannel newByteChannel( } } - private SeekableByteChannel newReadChannel( - Path path, Set options) throws IOException { + private SeekableByteChannel newReadChannel(Path path, Set options) + throws IOException { for (OpenOption option : options) { if (option instanceof StandardOpenOption) { switch ((StandardOpenOption) option) { @@ -172,8 +183,8 @@ private SeekableByteChannel newReadChannel( return CloudStorageReadChannel.create(storage, cloudPath.getBlobId(), 0); } - private SeekableByteChannel newWriteChannel( - Path path, Set options) throws IOException { + private SeekableByteChannel newWriteChannel(Path path, Set options) + throws IOException { CloudStoragePath cloudPath = checkPath(path); if (cloudPath.seemsLikeADirectoryAndUsePseudoDirectories()) { @@ -184,7 +195,6 @@ private SeekableByteChannel newWriteChannel( List writeOptions = new ArrayList<>(); List acls = new ArrayList<>(); - HashMap metas = new HashMap<>(); for (OpenOption option : options) { if (option instanceof OptionMimeType) { @@ -239,8 +249,9 @@ private SeekableByteChannel newWriteChannel( } try { - return new CloudStorageWriteChannel(storage.writer(infoBuilder.build(), - writeOptions.toArray(new Storage.BlobWriteOption[0]))); + return new CloudStorageWriteChannel( + storage.writer( + infoBuilder.build(), writeOptions.toArray(new Storage.BlobWriteOption[0]))); } catch (StorageException oops) { throw asIOException(oops); } @@ -280,7 +291,9 @@ public void delete(Path path) throws IOException { public void move(Path source, Path target, CopyOption... options) throws IOException { for (CopyOption option : options) { if (option == StandardCopyOption.ATOMIC_MOVE) { - throw new AtomicMoveNotSupportedException(source.toString(), target.toString(), + throw new AtomicMoveNotSupportedException( + source.toString(), + target.toString(), "Google Cloud Storage does not support atomic move operations."); } } @@ -327,8 +340,8 @@ public void copy(Path source, Path target, CopyOption... options) throws IOExcep tgtInfoBuilder.contentEncoding(((OptionContentEncoding) option).contentEncoding()); setContentEncoding = true; } else if (option instanceof OptionContentDisposition) { - tgtInfoBuilder.contentDisposition(((OptionContentDisposition) option) - .contentDisposition()); + tgtInfoBuilder.contentDisposition( + ((OptionContentDisposition) option).contentDisposition()); setContentDisposition = true; } else { throw new UnsupportedOperationException(option.toString()); @@ -340,9 +353,12 @@ public void copy(Path source, Path target, CopyOption... options) throws IOExcep CloudStoragePath fromPath = checkPath(source); - blockSize = blockSize != -1 ? blockSize - : Ints.max(fromPath.getFileSystem().config().blockSize(), - toPath.getFileSystem().config().blockSize()); + blockSize = + blockSize != -1 + ? blockSize + : Ints.max( + fromPath.getFileSystem().config().blockSize(), + toPath.getFileSystem().config().blockSize()); // TODO: actually use blockSize if (fromPath.seemsLikeADirectory() && toPath.seemsLikeADirectory()) { @@ -351,8 +367,9 @@ public void copy(Path source, Path target, CopyOption... options) throws IOExcep // NOOP: This would normally create an empty directory. return; } else { - checkArgument(!fromPath.getFileSystem().config().usePseudoDirectories() - && !toPath.getFileSystem().config().usePseudoDirectories(), + checkArgument( + !fromPath.getFileSystem().config().usePseudoDirectories() + && !toPath.getFileSystem().config().usePseudoDirectories(), "File systems associated with paths don't agree on pseudo-directories."); } } @@ -364,8 +381,6 @@ public void copy(Path source, Path target, CopyOption... options) throws IOExcep } try { - - if (wantCopyAttributes) { BlobInfo blobInfo = storage.get(fromPath.getBlobId()); if (null == blobInfo) { @@ -388,8 +403,8 @@ public void copy(Path source, Path target, CopyOption... options) throws IOExcep } BlobInfo tgtInfo = tgtInfoBuilder.build(); - Storage.CopyRequest.Builder copyReqBuilder = Storage.CopyRequest.builder() - .source(fromPath.getBlobId()); + Storage.CopyRequest.Builder copyReqBuilder = + Storage.CopyRequest.builder().source(fromPath.getBlobId()); if (wantReplaceExisting) { copyReqBuilder = copyReqBuilder.target(tgtInfo); } else { @@ -402,13 +417,13 @@ public void copy(Path source, Path target, CopyOption... options) throws IOExcep } } - @Override public boolean isSameFile(Path path, Path path2) { return checkPath(path).equals(checkPath(path2)); } - /** Returns {@code false}. + /** + * Always returns {@code false}, because GCS doesn't support hidden files. */ @Override public boolean isHidden(Path path) { @@ -487,7 +502,8 @@ public V getFileAttributeView( return result; } - /** Does nothing since GCS uses fake directories. + /** + * Does nothing since GCS uses fake directories. */ @Override public void createDirectory(Path dir, FileAttribute... attrs) { @@ -495,7 +511,8 @@ public void createDirectory(Path dir, FileAttribute... attrs) { checkNotNullArray(attrs); } - /** Always @throws UnsupportedOperationException. + /** + * Throws {@link UnsupportedOperationException} because this feature hasn't been implemented yet. */ @Override public DirectoryStream newDirectoryStream(Path dir, Filter filter) { @@ -504,8 +521,7 @@ public DirectoryStream newDirectoryStream(Path dir, Filter f } /** - * This feature is not supported, since Cloud Storage objects are immutable. - * Always @throws UnsupportedOperationException. + * Throws {@link UnsupportedOperationException} because Cloud Storage objects are immutable. */ @Override public void setAttribute(Path path, String attribute, Object value, LinkOption... options) { @@ -513,8 +529,7 @@ public void setAttribute(Path path, String attribute, Object value, LinkOption.. } /** - * This feature is not supported. - * Always @throws UnsupportedOperationException. + * Throws {@link UnsupportedOperationException} because this feature hasn't been implemented yet. */ @Override public FileStore getFileStore(Path path) { @@ -525,7 +540,7 @@ public FileStore getFileStore(Path path) { public boolean equals(@Nullable Object other) { return this == other || other instanceof CloudStorageFileSystemProvider - && Objects.equals(storage, ((CloudStorageFileSystemProvider) other).storage); + && Objects.equals(storage, ((CloudStorageFileSystemProvider) other).storage); } @Override @@ -535,13 +550,9 @@ public int hashCode() { @Override public String toString() { - return MoreObjects.toStringHelper(this) - .add("storage", storage) - .toString(); + return MoreObjects.toStringHelper(this).add("storage", storage).toString(); } - - private IOException asIOException(StorageException oops) { if (oops.code() == 404) { return new NoSuchFileException(oops.reason()); @@ -562,5 +573,4 @@ private IOException asIOException(StorageException oops) { } return new IOException(oops.getMessage(), oops); } - } diff --git a/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStorageObjectAttributes.java b/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStorageObjectAttributes.java index 987f889a1850..f01ac387928a 100644 --- a/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStorageObjectAttributes.java +++ b/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStorageObjectAttributes.java @@ -23,8 +23,7 @@ @Immutable final class CloudStorageObjectAttributes implements CloudStorageFileAttributes { - @Nonnull - private final BlobInfo info; + @Nonnull private final BlobInfo info; CloudStorageObjectAttributes(BlobInfo info) { this.info = checkNotNull(info); @@ -151,7 +150,7 @@ public Object fileKey() { public boolean equals(@Nullable Object other) { return this == other || other instanceof CloudStorageObjectAttributes - && Objects.equals(info, ((CloudStorageObjectAttributes) other).info); + && Objects.equals(info, ((CloudStorageObjectAttributes) other).info); } @Override @@ -161,8 +160,6 @@ public int hashCode() { @Override public String toString() { - return MoreObjects.toStringHelper(this) - .add("info", info) - .toString(); + return MoreObjects.toStringHelper(this).add("info", info).toString(); } } diff --git a/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStorageObjectImmutableException.java b/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStorageObjectImmutableException.java index 669f1c9ae91b..e3b68aca9aec 100644 --- a/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStorageObjectImmutableException.java +++ b/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStorageObjectImmutableException.java @@ -1,7 +1,10 @@ package com.google.gcloud.storage.contrib.nio; -/** Exception thrown to indicate we don't support a mutation of a cloud storage object. */ +/** + * Exception thrown to indicate we don't support a mutation of a cloud storage object. + */ public final class CloudStorageObjectImmutableException extends UnsupportedOperationException { + CloudStorageObjectImmutableException() { super("Cloud Storage objects are immutable."); } diff --git a/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStorageOption.java b/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStorageOption.java index d7964628d61b..f662561f0276 100644 --- a/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStorageOption.java +++ b/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStorageOption.java @@ -3,15 +3,23 @@ import java.nio.file.CopyOption; import java.nio.file.OpenOption; -/** Master interface for file operation option classes related to Google Cloud Storage. */ +/** + * Master interface for file operation option classes related to Google Cloud Storage. + */ public interface CloudStorageOption { - /** Interface for GCS options that can be specified when opening files. */ + /** + * Interface for GCS options that can be specified when opening files. + */ interface Open extends CloudStorageOption, OpenOption {} - /** Interface for GCS options that can be specified when copying files. */ + /** + * Interface for GCS options that can be specified when copying files. + */ interface Copy extends CloudStorageOption, CopyOption {} - /** Interface for GCS options that can be specified when opening or copying files. */ + /** + * Interface for GCS options that can be specified when opening or copying files. + */ interface OpenCopy extends Open, Copy {} } diff --git a/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStorageOptions.java b/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStorageOptions.java index d852c0c098c3..7417dcb1467c 100644 --- a/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStorageOptions.java +++ b/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStorageOptions.java @@ -2,15 +2,21 @@ import com.google.gcloud.storage.Acl; -/** Helper class for specifying options when opening and copying Cloud Storage files. */ +/** + * Helper class for specifying options when opening and copying Cloud Storage files. + */ public final class CloudStorageOptions { - /** Sets the mime type header on an object, e.g. {@code "text/plain"}. */ + /** + * Sets the mime type header on an object, e.g. {@code "text/plain"}. + */ public static CloudStorageOption.OpenCopy withMimeType(String mimeType) { return OptionMimeType.create(mimeType); } - /** Disables caching on an object. Same as: {@code withCacheControl("no-cache")}. */ + /** + * Disables caching on an object. Same as: {@code withCacheControl("no-cache")}. + */ public static CloudStorageOption.OpenCopy withoutCaching() { return withCacheControl("no-cache"); } diff --git a/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStoragePath.java b/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStoragePath.java index 1107dd2c5c7a..7a47e3c6b230 100644 --- a/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStoragePath.java +++ b/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStoragePath.java @@ -45,19 +45,20 @@ private CloudStoragePath(CloudStorageFileSystem fileSystem, UnixPath path) { this.path = path; } - static CloudStoragePath getPath( - CloudStorageFileSystem fileSystem, String path, String... more) { + static CloudStoragePath getPath(CloudStorageFileSystem fileSystem, String path, String... more) { return new CloudStoragePath( fileSystem, UnixPath.getPath(fileSystem.config().permitEmptyPathComponents(), path, more)); } - /** Returns the Cloud Storage bucket name being served by this file system. + /** + * Returns the Cloud Storage bucket name being served by this file system. */ public String bucket() { return fileSystem.bucket(); } - /** Returns path converted to a {@link BlobId} so I/O can be performed. + /** + * Returns path converted to a {@link BlobId} so I/O can be performed. */ BlobId getBlobId() { return BlobId.of(bucket(), toRealPath().path.toString()); @@ -88,8 +89,8 @@ public boolean isAbsolute() { } /** - * Changes relative path to absolute, using - * {@link CloudStorageConfiguration#workingDirectory() workingDirectory} as the current dir. + * Changes relative path to be absolute, using + * {@link CloudStorageConfiguration#workingDirectory() workingDirectory} as current dir. */ @Override public CloudStoragePath toAbsolutePath() { @@ -116,15 +117,16 @@ public CloudStoragePath toRealPath(LinkOption... options) { private UnixPath toRealPathInternal(boolean errorCheck) { UnixPath objectName = path.toAbsolutePath(getWorkingDirectory()); if (errorCheck && !fileSystem.config().permitEmptyPathComponents()) { - checkArgument(!EXTRA_SLASHES_OR_DOT_DIRS_PATTERN.matcher(objectName).find(), + checkArgument( + !EXTRA_SLASHES_OR_DOT_DIRS_PATTERN.matcher(objectName).find(), "I/O not allowed on dot-dirs or extra slashes when !permitEmptyPathComponents: %s", objectName); } if (fileSystem.config().stripPrefixSlash()) { objectName = objectName.removeBeginningSeparator(); } - checkArgument(!errorCheck || !objectName.isEmpty(), - "I/O not allowed on empty GCS object names."); + checkArgument( + !errorCheck || !objectName.isEmpty(), "I/O not allowed on empty GCS object names."); return objectName; } @@ -222,7 +224,8 @@ public boolean endsWith(String other) { return path.endsWith(getUnixPath(other)); } - /** Always @throws UnsupportedOperationException. + /** + * Throws {@link UnsupportedOperationException} because this feature hasn't been implemented yet. */ @Override public WatchKey register(WatchService watcher, Kind[] events, Modifier... modifiers) { @@ -230,7 +233,8 @@ public WatchKey register(WatchService watcher, Kind[] events, Modifier... mod throw new UnsupportedOperationException(); } - /** Always @throws UnsupportedOperationException. + /** + * Throws {@link UnsupportedOperationException} because this feature hasn't been implemented yet. */ @Override public WatchKey register(WatchService watcher, Kind... events) { @@ -239,8 +243,8 @@ public WatchKey register(WatchService watcher, Kind... events) { } /** - * This operation is not supported, since GCS files aren't backed by the local file system. - * Always @throws UnsupportedOperationException. + * Throws {@link UnsupportedOperationException} because GCS files are not backed by the local file + * system. */ @Override public File toFile() { @@ -273,9 +277,9 @@ public int compareTo(Path other) { public boolean equals(@Nullable Object other) { return this == other || other instanceof CloudStoragePath - && Objects.equals(bucket(), ((CloudStoragePath) other).bucket()) - && Objects.equals(toRealPathInternal(false), - ((CloudStoragePath) other).toRealPathInternal(false)); + && Objects.equals(bucket(), ((CloudStoragePath) other).bucket()) + && Objects.equals( + toRealPathInternal(false), ((CloudStoragePath) other).toRealPathInternal(false)); } @Override @@ -299,7 +303,7 @@ public URI toUri() { @Nullable private CloudStoragePath newPath(@Nullable UnixPath newPath) { - if (newPath == path) { // Nonuse of equals is intentional. + if (newPath == path) { // Nonuse of equals is intentional. return this; } else if (newPath != null) { return new CloudStoragePath(fileSystem, newPath); @@ -316,7 +320,9 @@ private UnixPath getWorkingDirectory() { return getUnixPath(fileSystem.config().workingDirectory()); } - /** Transform iterator providing a slight performance boost over {@code FluentIterable}. */ + /** + * Transform iterator providing a slight performance boost over {@code FluentIterable}. + */ private final class PathIterator extends UnmodifiableIterator { private final Iterator delegate = path.split(); diff --git a/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStoragePseudoDirectoryAttributes.java b/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStoragePseudoDirectoryAttributes.java index b3874be99f54..acb69710d346 100644 --- a/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStoragePseudoDirectoryAttributes.java +++ b/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStoragePseudoDirectoryAttributes.java @@ -9,7 +9,9 @@ import java.nio.file.attribute.FileTime; import java.util.List; -/** Metadata for a cloud storage pseudo-directory. */ +/** + * Metadata for a cloud storage pseudo-directory. + */ final class CloudStoragePseudoDirectoryAttributes implements CloudStorageFileAttributes { private final String id; @@ -45,7 +47,7 @@ public Object fileKey() { @Override public long size() { - return 1; // Allow I/O to happen before we fail. + return 1; // Allow I/O to happen before we fail. } @Override diff --git a/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStoragePseudoDirectoryException.java b/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStoragePseudoDirectoryException.java index d4ebbdad6e20..281b7257a1a6 100644 --- a/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStoragePseudoDirectoryException.java +++ b/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStoragePseudoDirectoryException.java @@ -2,8 +2,11 @@ import java.nio.file.InvalidPathException; -/** Exception thrown when erroneously trying to operate on a path with a trailing slash. */ +/** + * Exception thrown when erroneously trying to operate on a path with a trailing slash. + */ public final class CloudStoragePseudoDirectoryException extends InvalidPathException { + CloudStoragePseudoDirectoryException(CloudStoragePath path) { super(path.toString(), "Can't perform I/O on pseudo-directories (trailing slash)"); } diff --git a/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStorageReadChannel.java b/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStorageReadChannel.java index 47e31afd8f71..544f7c89d7f2 100644 --- a/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStorageReadChannel.java +++ b/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStorageReadChannel.java @@ -13,8 +13,9 @@ import java.nio.channels.NonWritableChannelException; import java.nio.channels.SeekableByteChannel; import java.nio.file.NoSuchFileException; -import javax.annotation.concurrent.ThreadSafe; +import javax.annotation.CheckReturnValue; +import javax.annotation.concurrent.ThreadSafe; /** * Cloud Storage read channel. @@ -24,8 +25,10 @@ @ThreadSafe final class CloudStorageReadChannel implements SeekableByteChannel { - static CloudStorageReadChannel create( - Storage gcsStorage, BlobId file, long position) throws IOException { + @CheckReturnValue + @SuppressWarnings("resource") + static CloudStorageReadChannel create(Storage gcsStorage, BlobId file, long position) + throws IOException { // XXX: Reading size and opening file should be atomic. long size = fetchSize(gcsStorage, file); ReadChannel channel = gcsStorage.reader(file); @@ -45,7 +48,6 @@ private CloudStorageReadChannel(long position, long size, ReadChannel channel) { this.channel = channel; } - @Override public boolean isOpen() { synchronized (this) { @@ -125,8 +127,7 @@ private void checkOpen() throws ClosedChannelException { private static long fetchSize(Storage gcsStorage, BlobId file) throws IOException { BlobInfo blobInfo = gcsStorage.get(file); if (blobInfo == null) { - throw new NoSuchFileException( - String.format("gs://%s/%s", file.bucket(), file.name())); + throw new NoSuchFileException(String.format("gs://%s/%s", file.bucket(), file.name())); } return blobInfo.size(); } diff --git a/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStorageUtil.java b/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStorageUtil.java index 9a33d7801566..136506a4c861 100644 --- a/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStorageUtil.java +++ b/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStorageUtil.java @@ -15,17 +15,22 @@ final class CloudStorageUtil { static void checkBucket(String bucket) { // TODO: The true check is actually more complicated. Consider implementing it. - checkArgument(BUCKET_PATTERN.matcher(bucket).matches(), "" - + "Invalid bucket name: '" + bucket + "'. " - + "GCS bucket names must contain only lowercase letters, numbers, dashes (-), " - + "underscores (_), and dots (.). Bucket names must start and end with a number or letter. " - + "See https://developers.google.com/storage/docs/bucketnaming for more details."); + checkArgument( + BUCKET_PATTERN.matcher(bucket).matches(), + "Invalid bucket name: '" + + bucket + + "'. " + + "GCS bucket names must contain only lowercase letters, numbers, dashes (-), " + + "underscores (_), and dots (.). Bucket names must start and end with a number or a " + + "letter. See the following page for more details: " + + "https://developers.google.com/storage/docs/bucketnaming"); } static CloudStoragePath checkPath(Path path) { if (!(checkNotNull(path) instanceof CloudStoragePath)) { - throw new ProviderMismatchException(String.format( - "Not a cloud storage path: %s (%s)", path, path.getClass().getSimpleName())); + throw new ProviderMismatchException( + String.format( + "Not a cloud storage path: %s (%s)", path, path.getClass().getSimpleName())); } return (CloudStoragePath) path; } @@ -45,7 +50,9 @@ static URI stripPathFromUri(URI uri) { } } - /** Makes NullPointerTester happy. */ + /** + * Makes {@code NullPointerTester} happy. + */ @SafeVarargs static void checkNotNullArray(T... values) { for (T value : values) { diff --git a/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/UnixPath.java b/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/UnixPath.java index 2536aa8d3d7c..7449a6956158 100644 --- a/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/UnixPath.java +++ b/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/UnixPath.java @@ -28,7 +28,7 @@ * preserve trailing backslashes, in order to ensure the path will continue to be recognized as a * directory. * - *

NOTE: This code might not play nice with + *

Note: This code might not play nice with * Supplementary * Characters as Surrogates. */ @@ -57,7 +57,9 @@ private UnixPath(boolean permitEmptyComponents, String path) { this.permitEmptyComponents = permitEmptyComponents; } - /** Returns new UnixPath of {@code first}. */ + /** + * Returns new UnixPath of {@code first}. + */ public static UnixPath getPath(boolean permitEmptyComponents, String path) { if (path.isEmpty()) { return EMPTY_PATH; @@ -99,7 +101,9 @@ public static UnixPath getPath(boolean permitEmptyComponents, String first, Stri return new UnixPath(permitEmptyComponents, builder.toString()); } - /** Returns {@code true} consists only of {@code separator}. */ + /** + * Returns {@code true} consists only of {@code separator}. + */ public boolean isRoot() { return isRootInternal(path); } @@ -108,7 +112,9 @@ private static boolean isRootInternal(String path) { return path.length() == 1 && path.charAt(0) == SEPARATOR; } - /** Returns {@code true} if path starts with {@code separator}. */ + /** + * Returns {@code true} if path starts with {@code separator}. + */ public boolean isAbsolute() { return isAbsoluteInternal(path); } @@ -117,7 +123,9 @@ private static boolean isAbsoluteInternal(String path) { return !path.isEmpty() && path.charAt(0) == SEPARATOR; } - /** Returns {@code true} if path ends with {@code separator}. */ + /** + * Returns {@code true} if path ends with {@code separator}. + */ public boolean hasTrailingSeparator() { return hasTrailingSeparatorInternal(path); } @@ -126,7 +134,9 @@ private static boolean hasTrailingSeparatorInternal(CharSequence path) { return path.length() != 0 && path.charAt(path.length() - 1) == SEPARATOR; } - /** Returns {@code true} if path ends with a trailing slash, or would after normalization. */ + /** + * Returns {@code true} if path ends with a trailing slash, or would after normalization. + */ public boolean seemsLikeADirectory() { int length = path.length(); return path.isEmpty() @@ -150,7 +160,8 @@ public UnixPath getFileName() { List parts = getParts(); String last = parts.get(parts.size() - 1); return parts.size() == 1 && path.equals(last) - ? this : new UnixPath(permitEmptyComponents, last); + ? this + : new UnixPath(permitEmptyComponents, last); } } @@ -164,9 +175,10 @@ public UnixPath getParent() { if (path.isEmpty() || isRoot()) { return null; } - int index = hasTrailingSeparator() - ? path.lastIndexOf(SEPARATOR, path.length() - 2) - : path.lastIndexOf(SEPARATOR); + int index = + hasTrailingSeparator() + ? path.lastIndexOf(SEPARATOR, path.length() - 2) + : path.lastIndexOf(SEPARATOR); if (index == -1) { return isAbsolute() ? ROOT_PATH : null; } else { @@ -397,28 +409,38 @@ public int compareTo(UnixPath other) { return ORDERING.compare(getParts(), other.getParts()); } - /** Converts relative path to an absolute path. */ + /** + * Converts relative path to an absolute path. + */ public UnixPath toAbsolutePath(UnixPath currentWorkingDirectory) { checkArgument(currentWorkingDirectory.isAbsolute()); return isAbsolute() ? this : currentWorkingDirectory.resolve(this); } - /** Returns {@code toAbsolutePath(ROOT_PATH)}. */ + /** + * Returns {@code toAbsolutePath(ROOT_PATH)}. + */ public UnixPath toAbsolutePath() { return toAbsolutePath(ROOT_PATH); } - /** Removes beginning separator from path, if an absolute path. */ + /** + * Removes beginning separator from path, if an absolute path. + */ public UnixPath removeBeginningSeparator() { return isAbsolute() ? new UnixPath(permitEmptyComponents, path.substring(1)) : this; } - /** Adds trailing separator to path, if it isn't present. */ + /** + * Adds trailing separator to path, if it isn't present. + */ public UnixPath addTrailingSeparator() { return hasTrailingSeparator() ? this : new UnixPath(permitEmptyComponents, path + SEPARATOR); } - /** Removes trailing separator from path, unless it's root. */ + /** + * Removes trailing separator from path, unless it's root. + */ public UnixPath removeTrailingSeparator() { if (!isRoot() && hasTrailingSeparator()) { return new UnixPath(permitEmptyComponents, path.substring(0, path.length() - 1)); @@ -427,21 +449,23 @@ public UnixPath removeTrailingSeparator() { } } - /** Splits path into components, excluding separators and empty strings. */ + /** + * Splits path into components, excluding separators and empty strings. + */ public Iterator split() { return getParts().iterator(); } - /** Splits path into components in reverse, excluding separators and empty strings. */ + /** + * Splits path into components in reverse, excluding separators and empty strings. + */ public Iterator splitReverse() { return Lists.reverse(getParts()).iterator(); } @Override public boolean equals(@Nullable Object other) { - return this == other - || other instanceof UnixPath - && path.equals(((UnixPath) other).path); + return this == other || other instanceof UnixPath && path.equals(((UnixPath) other).path); } @Override @@ -449,7 +473,9 @@ public int hashCode() { return path.hashCode(); } - /** Returns path as a string. */ + /** + * Returns path as a string. + */ @Override public String toString() { return path; @@ -470,23 +496,28 @@ public CharSequence subSequence(int start, int end) { return path.subSequence(start, end); } - /** Returns {@code true} if this path is an empty string. */ + /** + * Returns {@code true} if this path is an empty string. + */ public boolean isEmpty() { return path.isEmpty(); } - /** Returns list of path components, excluding slashes. */ + /** + * Returns list of path components, excluding slashes. + */ private List getParts() { List result = lazyStringParts; return result != null - ? result : (lazyStringParts = path.isEmpty() || isRoot() - ? Collections.emptyList() : createParts()); + ? result + : (lazyStringParts = + path.isEmpty() || isRoot() ? Collections.emptyList() : createParts()); } private List createParts() { if (permitEmptyComponents) { - return SPLITTER_PERMIT_EMPTY_COMPONENTS - .splitToList(path.charAt(0) == SEPARATOR ? path.substring(1) : path); + return SPLITTER_PERMIT_EMPTY_COMPONENTS.splitToList( + path.charAt(0) == SEPARATOR ? path.substring(1) : path); } else { return SPLITTER.splitToList(path); } diff --git a/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/package-info.java b/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/package-info.java index e07c960b5512..78980d92dbe2 100644 --- a/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/package-info.java +++ b/gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/package-info.java @@ -18,7 +18,7 @@ * static String bucket = System.getProperty(...); * static FileSystem fs = FileSystems.getFileSystem(URI.create("gs://" + bucket)); * void bar() { - * byte[] data = "hello kitty".getBytes(StandardCharsets.UTF_8); + * byte[] data = "hello world".getBytes(StandardCharsets.UTF_8); * Path path = fs.getPath("/object"); * Files.write(path, data); * data = Files.readBytes(path); @@ -73,7 +73,7 @@ * Google Auto, you can instantiate this file system directly as follows:

   {@code
  *
  *   CloudStorageFileSystem fs = CloudStorageFileSystemProvider.forBucket("bucket");
- *   byte[] data = "hello kitty".getBytes(StandardCharsets.UTF_8);
+ *   byte[] data = "hello world".getBytes(StandardCharsets.UTF_8);
  *   Path path = fs.getPath("/object");
  *   Files.write(path, data);
  *   data = Files.readBytes(path);}
diff --git a/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/gcloud/storage/contrib/nio/CloudStorageConfigurationTest.java b/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/gcloud/storage/contrib/nio/CloudStorageConfigurationTest.java index 9bb987e86707..66963b18ddb9 100644 --- a/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/gcloud/storage/contrib/nio/CloudStorageConfigurationTest.java +++ b/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/gcloud/storage/contrib/nio/CloudStorageConfigurationTest.java @@ -10,22 +10,24 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -/** Unit tests for {@link CloudStorageConfiguration}. */ +/** + * Unit tests for {@link CloudStorageConfiguration}. + */ @RunWith(JUnit4.class) public class CloudStorageConfigurationTest { - @Rule - public final ExpectedException thrown = ExpectedException.none(); + @Rule public final ExpectedException thrown = ExpectedException.none(); @Test public void testBuilder() { - CloudStorageConfiguration config = CloudStorageConfiguration.builder() - .workingDirectory("/omg") - .permitEmptyPathComponents(true) - .stripPrefixSlash(false) - .usePseudoDirectories(false) - .blockSize(666) - .build(); + CloudStorageConfiguration config = + CloudStorageConfiguration.builder() + .workingDirectory("/omg") + .permitEmptyPathComponents(true) + .stripPrefixSlash(false) + .usePseudoDirectories(false) + .blockSize(666) + .build(); assertThat(config.workingDirectory()).isEqualTo("/omg"); assertThat(config.permitEmptyPathComponents()).isTrue(); assertThat(config.stripPrefixSlash()).isFalse(); @@ -35,14 +37,15 @@ public void testBuilder() { @Test public void testFromMap() { - CloudStorageConfiguration config = CloudStorageConfiguration.fromMap( - new ImmutableMap.Builder() - .put("workingDirectory", "/omg") - .put("permitEmptyPathComponents", true) - .put("stripPrefixSlash", false) - .put("usePseudoDirectories", false) - .put("blockSize", 666) - .build()); + CloudStorageConfiguration config = + CloudStorageConfiguration.fromMap( + new ImmutableMap.Builder() + .put("workingDirectory", "/omg") + .put("permitEmptyPathComponents", true) + .put("stripPrefixSlash", false) + .put("usePseudoDirectories", false) + .put("blockSize", 666) + .build()); assertThat(config.workingDirectory()).isEqualTo("/omg"); assertThat(config.permitEmptyPathComponents()).isTrue(); assertThat(config.stripPrefixSlash()).isFalse(); diff --git a/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/gcloud/storage/contrib/nio/CloudStorageFileAttributeViewTest.java b/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/gcloud/storage/contrib/nio/CloudStorageFileAttributeViewTest.java index 7ad64388c3e0..ce9f34cf94d3 100644 --- a/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/gcloud/storage/contrib/nio/CloudStorageFileAttributeViewTest.java +++ b/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/gcloud/storage/contrib/nio/CloudStorageFileAttributeViewTest.java @@ -22,14 +22,15 @@ import java.nio.file.Paths; import java.nio.file.attribute.FileTime; -/** Unit tests for {@link CloudStorageFileAttributeView}. */ +/** + * Unit tests for {@link CloudStorageFileAttributeView}. + */ @RunWith(JUnit4.class) public class CloudStorageFileAttributeViewTest { private static final byte[] HAPPY = "(✿◕ ‿◕ )ノ".getBytes(UTF_8); - @Rule - public final ExpectedException thrown = ExpectedException.none(); + @Rule public final ExpectedException thrown = ExpectedException.none(); private Path path; @@ -77,15 +78,12 @@ public void testEquals_equalsTester() throws Exception { new EqualsTester() .addEqualityGroup( Files.getFileAttributeView( - Paths.get(URI.create("gs://red/rum")), - CloudStorageFileAttributeView.class), + Paths.get(URI.create("gs://red/rum")), CloudStorageFileAttributeView.class), Files.getFileAttributeView( - Paths.get(URI.create("gs://red/rum")), - CloudStorageFileAttributeView.class)) + Paths.get(URI.create("gs://red/rum")), CloudStorageFileAttributeView.class)) .addEqualityGroup( Files.getFileAttributeView( - Paths.get(URI.create("gs://red/lol/dog")), - CloudStorageFileAttributeView.class)) + Paths.get(URI.create("gs://red/lol/dog")), CloudStorageFileAttributeView.class)) .testEquals(); } diff --git a/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/gcloud/storage/contrib/nio/CloudStorageFileAttributesTest.java b/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/gcloud/storage/contrib/nio/CloudStorageFileAttributesTest.java index 810f67ceb1df..8ffeec985f6e 100644 --- a/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/gcloud/storage/contrib/nio/CloudStorageFileAttributesTest.java +++ b/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/gcloud/storage/contrib/nio/CloudStorageFileAttributesTest.java @@ -24,19 +24,20 @@ import java.nio.file.Path; import java.nio.file.Paths; -/** Unit tests for {@link CloudStorageFileAttributes}. */ +/** + * Unit tests for {@link CloudStorageFileAttributes}. + */ @RunWith(JUnit4.class) public class CloudStorageFileAttributesTest { private static final byte[] HAPPY = "(✿◕ ‿◕ )ノ".getBytes(UTF_8); - private Path path; private Path dir; /** empty test storage and make sure we use it instead of the real GCS. Create a few paths. **/ @Before - public void before() { + public void before() { CloudStorageFileSystemProvider.setGCloudOptions(LocalGcsHelper.options()); path = Paths.get(URI.create("gs://bucket/randompath")); dir = Paths.get(URI.create("gs://bucket/randompath/")); @@ -68,8 +69,8 @@ public void testAcl() throws Exception { public void testContentDisposition() throws Exception { Files.write(path, HAPPY, withContentDisposition("crash call")); assertThat( - Files.readAttributes(path, CloudStorageFileAttributes.class).contentDisposition().get()) - .isEqualTo("crash call"); + Files.readAttributes(path, CloudStorageFileAttributes.class).contentDisposition().get()) + .isEqualTo("crash call"); } @Test @@ -83,8 +84,10 @@ public void testContentEncoding() throws Exception { public void testUserMetadata() throws Exception { Files.write(path, HAPPY, withUserMetadata("green", "bean")); assertThat( - Files.readAttributes(path, CloudStorageFileAttributes.class).userMetadata().get("green")) - .isEqualTo("bean"); + Files.readAttributes(path, CloudStorageFileAttributes.class) + .userMetadata() + .get("green")) + .isEqualTo("bean"); } @Test @@ -144,8 +147,9 @@ public void testFilekey() throws Exception { // same for directories CloudStorageFileAttributes b1 = Files.readAttributes(dir, CloudStorageFileAttributes.class); - CloudStorageFileAttributes b2 = Files.readAttributes( - Paths.get(URI.create("gs://bucket/jacket/")), CloudStorageFileAttributes.class); + CloudStorageFileAttributes b2 = + Files.readAttributes( + Paths.get(URI.create("gs://bucket/jacket/")), CloudStorageFileAttributes.class); assertThat(a1.fileKey()).isNotEqualTo(b1.fileKey()); assertThat(b1.fileKey()).isNotEqualTo(b2.fileKey()); } diff --git a/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/gcloud/storage/contrib/nio/CloudStorageFileSystemProviderTest.java b/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/gcloud/storage/contrib/nio/CloudStorageFileSystemProviderTest.java index 9f07505acb70..f85bb087acb8 100644 --- a/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/gcloud/storage/contrib/nio/CloudStorageFileSystemProviderTest.java +++ b/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/gcloud/storage/contrib/nio/CloudStorageFileSystemProviderTest.java @@ -46,25 +46,36 @@ import java.nio.file.StandardOpenOption; import java.util.List; -/** Unit tests for {@link CloudStorageFileSystemProvider}. */ +/** + * Unit tests for {@link CloudStorageFileSystemProvider}. + */ @RunWith(JUnit4.class) -@SuppressWarnings("resource") public class CloudStorageFileSystemProviderTest { - private static final List FILE_CONTENTS = ImmutableList.of( - "To be, or not to be, that is the question—", - "Whether 'tis Nobler in the mind to suffer", - "The Slings and Arrows of outrageous Fortune,", - "Or to take Arms against a Sea of troubles,", - "And by opposing, end them? To die, to sleep—", - "No more; and by a sleep, to say we end", - "The Heart-ache, and the thousand Natural shocks", - "That Flesh is heir to? 'Tis a consummation"); + private static final List FILE_CONTENTS = + ImmutableList.of( + "Fanatics have their dreams, wherewith they weave", + "A paradise for a sect; the savage too", + "From forth the loftiest fashion of his sleep", + "Guesses at Heaven; pity these have not", + "Trac'd upon vellum or wild Indian leaf", + "The shadows of melodious utterance.", + "But bare of laurel they live, dream, and die;", + "For Poesy alone can tell her dreams,", + "With the fine spell of words alone can save", + "Imagination from the sable charm", + "And dumb enchantment. Who alive can say,", + "'Thou art no Poet may'st not tell thy dreams?'", + "Since every man whose soul is not a clod", + "Hath visions, and would speak, if he had loved", + "And been well nurtured in his mother tongue.", + "Whether the dream now purpos'd to rehearse", + "Be poet's or fanatic's will be known", + "When this warm scribe my hand is in the grave."); private static final String SINGULARITY = "A string"; - @Rule - public final ExpectedException thrown = ExpectedException.none(); + @Rule public final ExpectedException thrown = ExpectedException.none(); @Before public void before() { @@ -307,10 +318,8 @@ public void testWrite_absoluteObjectName_prefixSlashGetsRemoved() throws Excepti @Test public void testWrite_absoluteObjectName_disableStrip_slashGetsPreserved() throws Exception { try (CloudStorageFileSystem fs = - forBucket("greenbean", - CloudStorageConfiguration.builder() - .stripPrefixSlash(false) - .build())) { + forBucket( + "greenbean", CloudStorageConfiguration.builder().stripPrefixSlash(false).build())) { Path path = fs.getPath("/adipose/yep"); Files.write(path, FILE_CONTENTS, UTF_8); assertThat(Files.readAllLines(path, UTF_8)).isEqualTo(FILE_CONTENTS); @@ -536,7 +545,9 @@ public void testIsDirectory_trailingSlash_pseudoDirectoriesDisabled_false() thro public void testCopy_withCopyAttributes_preservesAttributes() throws Exception { Path source = Paths.get(URI.create("gs://military/fashion.show")); Path target = Paths.get(URI.create("gs://greenbean/adipose")); - Files.write(source, "(✿◕ ‿◕ )ノ".getBytes(UTF_8), + Files.write( + source, + "(✿◕ ‿◕ )ノ".getBytes(UTF_8), withMimeType("text/lolcat"), withCacheControl("public; max-age=666"), withContentEncoding("foobar"), @@ -558,7 +569,9 @@ public void testCopy_withCopyAttributes_preservesAttributes() throws Exception { public void testCopy_withoutOptions_doesntPreservesAttributes() throws Exception { Path source = Paths.get(URI.create("gs://military/fashion.show")); Path target = Paths.get(URI.create("gs://greenbean/adipose")); - Files.write(source, "(✿◕ ‿◕ )ノ".getBytes(UTF_8), + Files.write( + source, + "(✿◕ ‿◕ )ノ".getBytes(UTF_8), withMimeType("text/lolcat"), withCacheControl("public; max-age=666"), withUserMetadata("answer", "42")); @@ -578,12 +591,13 @@ public void testCopy_overwriteAttributes() throws Exception { Path source = Paths.get(URI.create("gs://military/fashion.show")); Path target1 = Paths.get(URI.create("gs://greenbean/adipose")); Path target2 = Paths.get(URI.create("gs://greenbean/round")); - Files.write(source, "(✿◕ ‿◕ )ノ".getBytes(UTF_8), + Files.write( + source, + "(✿◕ ‿◕ )ノ".getBytes(UTF_8), withMimeType("text/lolcat"), withCacheControl("public; max-age=666")); Files.copy(source, target1, COPY_ATTRIBUTES); - Files.copy(source, target2, COPY_ATTRIBUTES, - withMimeType("text/palfun")); + Files.copy(source, target2, COPY_ATTRIBUTES, withMimeType("text/palfun")); CloudStorageFileAttributes attributes = Files.readAttributes(target1, CloudStorageFileAttributes.class); @@ -598,14 +612,15 @@ public void testCopy_overwriteAttributes() throws Exception { @Test public void testNullness() throws Exception { try (FileSystem fs = FileSystems.getFileSystem(URI.create("gs://blood"))) { - NullPointerTester tester = new NullPointerTester() - .setDefault(URI.class, URI.create("gs://blood")) - .setDefault(Path.class, fs.getPath("and/one")) - .setDefault(OpenOption.class, StandardOpenOption.CREATE) - .setDefault(CopyOption.class, StandardCopyOption.COPY_ATTRIBUTES); + NullPointerTester tester = + new NullPointerTester() + .setDefault(URI.class, URI.create("gs://blood")) + .setDefault(Path.class, fs.getPath("and/one")) + .setDefault(OpenOption.class, StandardOpenOption.CREATE) + .setDefault(CopyOption.class, StandardCopyOption.COPY_ATTRIBUTES); // can't do that, setGCloudOptions accepts a null argument. // TODO(jart): Figure out how to re-enable this. - //tester.testAllPublicStaticMethods(CloudStorageFileSystemProvider.class); + // tester.testAllPublicStaticMethods(CloudStorageFileSystemProvider.class); tester.testAllPublicInstanceMethods(new CloudStorageFileSystemProvider()); } } @@ -620,14 +635,10 @@ public void testProviderEquals() throws Exception { } private static CloudStorageConfiguration permitEmptyPathComponents(boolean value) { - return CloudStorageConfiguration.builder() - .permitEmptyPathComponents(value) - .build(); + return CloudStorageConfiguration.builder().permitEmptyPathComponents(value).build(); } private static CloudStorageConfiguration usePseudoDirectories(boolean value) { - return CloudStorageConfiguration.builder() - .usePseudoDirectories(value) - .build(); + return CloudStorageConfiguration.builder().usePseudoDirectories(value).build(); } } diff --git a/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/gcloud/storage/contrib/nio/CloudStorageFileSystemTest.java b/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/gcloud/storage/contrib/nio/CloudStorageFileSystemTest.java index fbdfbca88350..0e019870c07d 100644 --- a/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/gcloud/storage/contrib/nio/CloudStorageFileSystemTest.java +++ b/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/gcloud/storage/contrib/nio/CloudStorageFileSystemTest.java @@ -18,20 +18,21 @@ import java.nio.file.Files; import java.nio.file.Paths; -/** Unit tests for {@link CloudStorageFileSystem}. */ +/** + * Unit tests for {@link CloudStorageFileSystem}. + */ @RunWith(JUnit4.class) public class CloudStorageFileSystemTest { - private static final String ALONE = "" - + "To be, or not to be, that is the question—\n" - + "Whether 'tis Nobler in the mind to suffer\n" - + "The Slings and Arrows of outrageous Fortune,\n" - + "Or to take Arms against a Sea of troubles,\n" - + "And by opposing, end them? To die, to sleep—\n" - + "No more; and by a sleep, to say we end\n" - + "The Heart-ache, and the thousand Natural shocks\n" - + "That Flesh is heir to? 'Tis a consummation\n"; - + private static final String ALONE = + "To be, or not to be, that is the question—\n" + + "Whether 'tis Nobler in the mind to suffer\n" + + "The Slings and Arrows of outrageous Fortune,\n" + + "Or to take Arms against a Sea of troubles,\n" + + "And by opposing, end them? To die, to sleep—\n" + + "No more; and by a sleep, to say we end\n" + + "The Heart-ache, and the thousand Natural shocks\n" + + "That Flesh is heir to? 'Tis a consummation\n"; @Before public void before() { @@ -106,8 +107,9 @@ public void testEquals() throws Exception { @Test public void testNullness() throws Exception { try (FileSystem fs = FileSystems.getFileSystem(URI.create("gs://bucket"))) { - NullPointerTester tester = new NullPointerTester() - .setDefault(CloudStorageConfiguration.class, CloudStorageConfiguration.DEFAULT); + NullPointerTester tester = + new NullPointerTester() + .setDefault(CloudStorageConfiguration.class, CloudStorageConfiguration.DEFAULT); tester.testAllPublicStaticMethods(CloudStorageFileSystem.class); tester.testAllPublicInstanceMethods(fs); } diff --git a/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/gcloud/storage/contrib/nio/CloudStorageOptionsTest.java b/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/gcloud/storage/contrib/nio/CloudStorageOptionsTest.java index 5620896761e0..5059eaa7e973 100644 --- a/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/gcloud/storage/contrib/nio/CloudStorageOptionsTest.java +++ b/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/gcloud/storage/contrib/nio/CloudStorageOptionsTest.java @@ -24,7 +24,9 @@ import java.nio.file.Path; import java.nio.file.Paths; -/** Unit tests for {@link CloudStorageOptions}. */ +/** + * Unit tests for {@link CloudStorageOptions}. + */ @RunWith(JUnit4.class) public class CloudStorageOptionsTest { @@ -36,8 +38,7 @@ public void before() { @Test public void testWithoutCaching() throws Exception { Path path = Paths.get(URI.create("gs://bucket/path")); - Files.write(path, "(✿◕ ‿◕ )ノ".getBytes(UTF_8), - withoutCaching()); + Files.write(path, "(✿◕ ‿◕ )ノ".getBytes(UTF_8), withoutCaching()); assertThat(Files.readAttributes(path, CloudStorageFileAttributes.class).cacheControl().get()) .isEqualTo("no-cache"); } @@ -45,8 +46,7 @@ public void testWithoutCaching() throws Exception { @Test public void testCacheControl() throws Exception { Path path = Paths.get(URI.create("gs://bucket/path")); - Files.write(path, "(✿◕ ‿◕ )ノ".getBytes(UTF_8), - withCacheControl("potato")); + Files.write(path, "(✿◕ ‿◕ )ノ".getBytes(UTF_8), withCacheControl("potato")); assertThat(Files.readAttributes(path, CloudStorageFileAttributes.class).cacheControl().get()) .isEqualTo("potato"); } @@ -55,8 +55,7 @@ public void testCacheControl() throws Exception { public void testWithAcl() throws Exception { Path path = Paths.get(URI.create("gs://bucket/path")); Acl acl = Acl.of(new Acl.User("king@example.com"), Acl.Role.OWNER); - Files.write(path, "(✿◕ ‿◕ )ノ".getBytes(UTF_8), - withAcl(acl)); + Files.write(path, "(✿◕ ‿◕ )ノ".getBytes(UTF_8), withAcl(acl)); assertThat(Files.readAttributes(path, CloudStorageFileAttributes.class).acl().get()) .contains(acl); } @@ -64,18 +63,16 @@ public void testWithAcl() throws Exception { @Test public void testWithContentDisposition() throws Exception { Path path = Paths.get(URI.create("gs://bucket/path")); - Files.write(path, "(✿◕ ‿◕ )ノ".getBytes(UTF_8), - withContentDisposition("bubbly fun")); + Files.write(path, "(✿◕ ‿◕ )ノ".getBytes(UTF_8), withContentDisposition("bubbly fun")); assertThat( - Files.readAttributes(path, CloudStorageFileAttributes.class).contentDisposition().get()) + Files.readAttributes(path, CloudStorageFileAttributes.class).contentDisposition().get()) .isEqualTo("bubbly fun"); } @Test public void testWithContentEncoding() throws Exception { Path path = Paths.get(URI.create("gs://bucket/path")); - Files.write(path, "(✿◕ ‿◕ )ノ".getBytes(UTF_8), - withContentEncoding("gzip")); + Files.write(path, "(✿◕ ‿◕ )ノ".getBytes(UTF_8), withContentEncoding("gzip")); assertThat(Files.readAttributes(path, CloudStorageFileAttributes.class).contentEncoding().get()) .isEqualTo("gzip"); } @@ -83,24 +80,25 @@ public void testWithContentEncoding() throws Exception { @Test public void testWithUserMetadata() throws Exception { Path path = Paths.get(URI.create("gs://bucket/path")); - Files.write(path, "(✿◕ ‿◕ )ノ".getBytes(UTF_8), + Files.write( + path, + "(✿◕ ‿◕ )ノ".getBytes(UTF_8), withUserMetadata("nolo", "contendere"), withUserMetadata("eternal", "sadness")); assertThat( - Files.readAttributes(path, CloudStorageFileAttributes.class) - .userMetadata().get("nolo")) + Files.readAttributes(path, CloudStorageFileAttributes.class).userMetadata().get("nolo")) .isEqualTo("contendere"); assertThat( Files.readAttributes(path, CloudStorageFileAttributes.class) - .userMetadata().get("eternal")) + .userMetadata() + .get("eternal")) .isEqualTo("sadness"); } @Test public void testWithMimeType_string() throws Exception { Path path = Paths.get(URI.create("gs://bucket/path")); - Files.write(path, "(✿◕ ‿◕ )ノ".getBytes(UTF_8), - withMimeType("text/plain")); + Files.write(path, "(✿◕ ‿◕ )ノ".getBytes(UTF_8), withMimeType("text/plain")); assertThat(Files.readAttributes(path, CloudStorageFileAttributes.class).mimeType().get()) .isEqualTo("text/plain"); } diff --git a/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/gcloud/storage/contrib/nio/CloudStoragePathTest.java b/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/gcloud/storage/contrib/nio/CloudStoragePathTest.java index 617a0c0a9c4e..d8e964fbb11a 100644 --- a/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/gcloud/storage/contrib/nio/CloudStoragePathTest.java +++ b/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/gcloud/storage/contrib/nio/CloudStoragePathTest.java @@ -22,12 +22,13 @@ import java.nio.file.Paths; import java.nio.file.ProviderMismatchException; -/** Unit tests for {@link CloudStoragePath}. */ +/** + * Unit tests for {@link CloudStoragePath}. + */ @RunWith(JUnit4.class) public class CloudStoragePathTest { - @Rule - public final ExpectedException thrown = ExpectedException.none(); + @Rule public final ExpectedException thrown = ExpectedException.none(); @Before public void before() { @@ -292,9 +293,9 @@ public void testGetRoot() { @Test public void testRelativize() { try (CloudStorageFileSystem fs = forBucket("doodle")) { - assertThat(fs.getPath("/foo/bar/lol/cat") - .relativize(fs.getPath("/foo/a/b/../../c")).toString()) - .isEqualTo("../../../a/b/../../c"); + assertThat( + fs.getPath("/foo/bar/lol/cat").relativize(fs.getPath("/foo/a/b/../../c")).toString()) + .isEqualTo("../../../a/b/../../c"); } } @@ -307,7 +308,7 @@ public void testRelativize_providerMismatch() { } @Test - @SuppressWarnings("ReturnValueIgnored") // testing that an Exception is thrown + @SuppressWarnings("ReturnValueIgnored") // testing that an Exception is thrown public void testRelativize_providerMismatch2() { try (CloudStorageFileSystem fs = forBucket("doodle")) { thrown.expect(ProviderMismatchException.class); @@ -466,28 +467,21 @@ public void testEquals_currentDirectoryIsTakenIntoConsideration() { @Test public void testNullness() { try (CloudStorageFileSystem fs = forBucket("doodle")) { - NullPointerTester tester = new NullPointerTester() - .setDefault(Path.class, fs.getPath("sup")); + NullPointerTester tester = new NullPointerTester().setDefault(Path.class, fs.getPath("sup")); tester.testAllPublicStaticMethods(CloudStoragePath.class); tester.testAllPublicInstanceMethods(fs.getPath("sup")); } } private static CloudStorageConfiguration stripPrefixSlash(boolean value) { - return CloudStorageConfiguration.builder() - .stripPrefixSlash(value) - .build(); + return CloudStorageConfiguration.builder().stripPrefixSlash(value).build(); } private static CloudStorageConfiguration permitEmptyPathComponents(boolean value) { - return CloudStorageConfiguration.builder() - .permitEmptyPathComponents(value) - .build(); + return CloudStorageConfiguration.builder().permitEmptyPathComponents(value).build(); } private static CloudStorageConfiguration workingDirectory(String value) { - return CloudStorageConfiguration.builder() - .workingDirectory(value) - .build(); + return CloudStorageConfiguration.builder().workingDirectory(value).build(); } } diff --git a/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/gcloud/storage/contrib/nio/CloudStorageReadChannelTest.java b/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/gcloud/storage/contrib/nio/CloudStorageReadChannelTest.java index 4b355d076552..49df66ef71eb 100644 --- a/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/gcloud/storage/contrib/nio/CloudStorageReadChannelTest.java +++ b/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/gcloud/storage/contrib/nio/CloudStorageReadChannelTest.java @@ -26,21 +26,21 @@ import java.nio.channels.ClosedChannelException; import java.nio.channels.NonWritableChannelException; -/** Unit tests for {@link CloudStorageReadChannel}. */ +/** + * Unit tests for {@link CloudStorageReadChannel}. + */ @RunWith(JUnit4.class) public class CloudStorageReadChannelTest { - @Rule - public final ExpectedException thrown = ExpectedException.none(); + @Rule public final ExpectedException thrown = ExpectedException.none(); private CloudStorageReadChannel chan; private final Storage gcsStorage = mock(Storage.class); - private final BlobId file = BlobId.of("enya", "rocks"); + private final BlobId file = BlobId.of("blob", "attack"); private final BlobInfo metadata = BlobInfo.builder(file).size(42L).build(); private final ReadChannel gcsChannel = mock(ReadChannel.class); - /** Set up the mocks. **/ @Before public void before() throws Exception { when(gcsStorage.get(file)).thenReturn(metadata); @@ -140,5 +140,4 @@ public void testSetPosition() throws Exception { verify(gcsChannel, times(5)).isOpen(); verifyNoMoreInteractions(gcsStorage, gcsChannel); } - } diff --git a/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/gcloud/storage/contrib/nio/CloudStorageWriteChannelTest.java b/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/gcloud/storage/contrib/nio/CloudStorageWriteChannelTest.java index 4a8d321e495f..837886a2e649 100644 --- a/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/gcloud/storage/contrib/nio/CloudStorageWriteChannelTest.java +++ b/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/gcloud/storage/contrib/nio/CloudStorageWriteChannelTest.java @@ -23,12 +23,13 @@ import java.nio.channels.ClosedChannelException; import java.nio.channels.NonReadableChannelException; -/** Unit tests for {@link CloudStorageWriteChannel}. */ +/** + * Unit tests for {@link CloudStorageWriteChannel}. + */ @RunWith(JUnit4.class) public class CloudStorageWriteChannelTest { - @Rule - public final ExpectedException thrown = ExpectedException.none(); + @Rule public final ExpectedException thrown = ExpectedException.none(); private final WriteChannel gcsChannel = mock(WriteChannel.class); private CloudStorageWriteChannel chan = new CloudStorageWriteChannel(gcsChannel); diff --git a/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/gcloud/storage/contrib/nio/UnixPathTest.java b/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/gcloud/storage/contrib/nio/UnixPathTest.java index e6417fc75c8c..8fc76455935a 100644 --- a/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/gcloud/storage/contrib/nio/UnixPathTest.java +++ b/gcloud-java-contrib/gcloud-java-nio/src/test/java/com/google/gcloud/storage/contrib/nio/UnixPathTest.java @@ -12,12 +12,13 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -/** Unit tests for {@link UnixPath}. */ +/** + * Unit tests for {@link UnixPath}. + */ @RunWith(JUnit4.class) public class UnixPathTest { - @Rule - public final ExpectedException thrown = ExpectedException.none(); + @Rule public final ExpectedException thrown = ExpectedException.none(); @Test public void testNormalize() { @@ -90,8 +91,7 @@ public void testGetPath() { assertThat(UnixPath.getPath(false, "hello")).isEqualTo(p("hello")); assertThat(UnixPath.getPath(false, "hello", "cat")).isEqualTo(p("hello/cat")); assertThat(UnixPath.getPath(false, "/hello", "cat")).isEqualTo(p("/hello/cat")); - assertThat(UnixPath.getPath(false, "/hello", "cat", "inc.")) - .isEqualTo(p("/hello/cat/inc.")); + assertThat(UnixPath.getPath(false, "/hello", "cat", "inc.")).isEqualTo(p("/hello/cat/inc.")); assertThat(UnixPath.getPath(false, "hello/", "/hi/there")).isEqualTo(p("/hi/there")); } @@ -111,12 +111,10 @@ public void testResolveSibling_preservesTrailingSlash() { public void testRelativize() { assertThat(p("/foo/bar/hop/dog").relativize(p("/foo/mop/top"))) .isEqualTo(p("../../../mop/top")); - assertThat(p("/foo/bar/dog").relativize(p("/foo/mop/top"))) - .isEqualTo(p("../../mop/top")); + assertThat(p("/foo/bar/dog").relativize(p("/foo/mop/top"))).isEqualTo(p("../../mop/top")); assertThat(p("/foo/bar/hop/dog").relativize(p("/foo/mop/top/../../mog"))) .isEqualTo(p("../../../mop/top/../../mog")); - assertThat(p("/foo/bar/hop/dog").relativize(p("/foo/../mog"))) - .isEqualTo(p("../../../../mog")); + assertThat(p("/foo/bar/hop/dog").relativize(p("/foo/../mog"))).isEqualTo(p("../../../../mog")); assertThat(p("").relativize(p("foo/mop/top/"))).isEqualTo(p("foo/mop/top/")); }