Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correct more style issues and remove warnings
Browse files Browse the repository at this point in the history
This change is a follow-up to post-merge comments in googleapis#706 made by
@ajkannan and @aozarov. The following changes have been made:

- Don't use @nullable on equals() methods
- Don't `throws Exception` in test methods unless needed
- Use incomplete sentences in JavaDoc summary fragment
- Capitalize Cloud Storage
- Get rid of some one-line JavaDocs
- Use @code formatting when appropriate
- Remove Paths.get() usages which is deprecated in Java 8
- Remove @SuppressWarnings("null") which no one uses
jart authored and mziccard committed Jun 29, 2016
1 parent d51f838 commit 20b01d3
Showing 19 changed files with 179 additions and 197 deletions.
Original file line number Diff line number Diff line change
@@ -7,13 +7,13 @@
import java.util.Map;

/**
* Configuration for a {@link CloudStorageFileSystem} instance.
* Configuration for {@link CloudStorageFileSystem} instances.
*/
@AutoValue
public abstract class CloudStorageConfiguration {

/**
* Returns path of the current working directory. This defaults to the root directory.
* Returns path of current working directory. This defaults to the root directory.
*/
public abstract String workingDirectory();

@@ -31,10 +31,14 @@ public abstract class CloudStorageConfiguration {
*/
public abstract boolean stripPrefixSlash();

/** Return {@code true} if paths with a trailing slash should be treated as fake directories. */
/**
* Returns {@code true} if paths with a trailing slash should be treated as fake directories.
*/
public abstract boolean usePseudoDirectories();

/** Returns the block size (in bytes) used when talking to the GCS HTTP server. */
/**
* Returns block size (in bytes) used when talking to the GCS HTTP server.
*/
public abstract int blockSize();

/**
@@ -50,7 +54,8 @@ public static Builder builder() {
return new Builder();
}

/** Builder for {@link CloudStorageConfiguration}.
/**
* Builder for {@link CloudStorageConfiguration}.
*/
public static final class Builder {

@@ -61,8 +66,8 @@ public static final class Builder {
private int blockSize = CloudStorageFileSystem.BLOCK_SIZE_DEFAULT;

/**
* Changes the current working directory for a new filesystem. This cannot be changed once it's
* been set. You'll need to simply create another filesystem object.
* Changes current working directory for new filesystem. This cannot be changed once it's
* been set. You'll need to create another {@link CloudStorageFileSystem} object.
*
* @throws IllegalArgumentException if {@code path} is not absolute.
*/
@@ -92,7 +97,8 @@ public Builder stripPrefixSlash(boolean value) {
return this;
}

/** Configures if paths with a trailing slash should be treated as fake directories.
/**
* Configures if paths with a trailing slash should be treated as fake directories.
*/
public Builder usePseudoDirectories(boolean value) {
usePseudoDirectories = value;
@@ -109,7 +115,8 @@ public Builder blockSize(int value) {
return this;
}

/** Creates a new instance, but does not destroy the builder.
/**
* Creates new instance without destroying builder.
*/
public CloudStorageConfiguration build() {
return new AutoValue_CloudStorageConfiguration(
Original file line number Diff line number Diff line change
@@ -12,7 +12,6 @@
import java.nio.file.attribute.FileTime;
import java.util.Objects;

import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;

/**
@@ -59,7 +58,7 @@ public void setTimes(FileTime lastModifiedTime, FileTime lastAccessTime, FileTim
}

@Override
public boolean equals(@Nullable Object other) {
public boolean equals(Object other) {
return this == other
|| other instanceof CloudStorageFileAttributeView
&& Objects.equals(storage, ((CloudStorageFileAttributeView) other).storage)
Original file line number Diff line number Diff line change
@@ -7,53 +7,55 @@
import java.nio.file.attribute.BasicFileAttributes;
import java.util.List;

/** Interface for attributes on a cloud storage file or pseudo-directory. */
/**
* Interface for attributes on a Cloud Storage file or pseudo-directory.
*/
public interface CloudStorageFileAttributes extends BasicFileAttributes {

/**
* Returns the HTTP etag hash for this object.
* Returns HTTP etag hash of object contents.
*
* @see "https://developers.google.com/storage/docs/hashes-etags"
*/
Optional<String> etag();

/**
* Returns the mime type (e.g. text/plain) if it was set for this object.
* Returns mime type (e.g. text/plain), if set.
*
* @see "http://en.wikipedia.org/wiki/Internet_media_type#List_of_common_media_types"
*/
Optional<String> mimeType();

/**
* Returns the ACL value on this Cloud Storage object.
* Returns access control list.
*
* @see "https://developers.google.com/storage/docs/reference-headers#acl"
*/
Optional<List<Acl>> acl();

/**
* Returns the {@code Cache-Control} HTTP header value, if set on this object.
* Returns {@code Cache-Control} HTTP header value, if set.
*
* @see "https://developers.google.com/storage/docs/reference-headers#cachecontrol"
*/
Optional<String> cacheControl();

/**
* Returns the {@code Content-Encoding} HTTP header value, if set on this object.
* Returns {@code Content-Encoding} HTTP header value, if set.
*
* @see "https://developers.google.com/storage/docs/reference-headers#contentencoding"
*/
Optional<String> contentEncoding();

/**
* Returns the {@code Content-Disposition} HTTP header value, if set on this object.
* Returns {@code Content-Disposition} HTTP header value, if set.
*
* @see "https://developers.google.com/storage/docs/reference-headers#contentdisposition"
*/
Optional<String> contentDisposition();

/**
* Returns user-specified metadata associated with this object.
* Returns user-specified metadata.
*
* @see "https://developers.google.com/storage/docs/reference-headers#contentdisposition"
*/
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@
import javax.annotation.concurrent.Immutable;

/**
* Google Cloud Storage {@link FileSystem}
* Google Cloud Storage {@link FileSystem} implementation.
*
* @see <a href="https://developers.google.com/storage/docs/concepts-techniques#concepts">
* Concepts and Terminology</a>
@@ -35,7 +35,7 @@
public final class CloudStorageFileSystem extends FileSystem {

/**
* Returns Google Cloud Storage {@link FileSystem} object for a given bucket name.
* Returns Google Cloud Storage {@link FileSystem} object for {@code bucket}.
*
* <p><b>NOTE:</b> You may prefer to use Java's standard API instead:<pre> {@code
*
@@ -54,7 +54,7 @@ public static CloudStorageFileSystem forBucket(String bucket) {
}

/**
* Creates a new filesystem for a particular bucket, with customizable settings.
* Creates new file system instance for {@code bucket}, with customizable settings.
*
* @see #forBucket(String)
*/
@@ -113,21 +113,21 @@ public CloudStorageFileSystemProvider provider() {
}

/**
* Returns the Cloud Storage bucket name being served by this file system.
* Returns Cloud Storage bucket name being served by this file system.
*/
public String bucket() {
return bucket;
}

/**
* Returns the configuration object for this filesystem instance.
* Returns configuration object for this file system instance.
*/
public CloudStorageConfiguration config() {
return config;
}

/**
* Converts a cloud storage object name to a {@link Path} object.
* Converts Cloud Storage object name to a {@link Path} object.
*/
@Override
public CloudStoragePath getPath(String first, String... more) {
@@ -211,7 +211,7 @@ public WatchService newWatchService() throws IOException {
}

@Override
public boolean equals(@Nullable Object other) {
public boolean equals(Object other) {
return this == other
|| other instanceof CloudStorageFileSystem
&& Objects.equals(config, ((CloudStorageFileSystem) other).config)
Original file line number Diff line number Diff line change
@@ -56,7 +56,7 @@
import javax.annotation.concurrent.ThreadSafe;

/**
* Google Cloud Storage {@link FileSystemProvider}.
* Google Cloud Storage {@link FileSystemProvider} implementation.
*/
@ThreadSafe
@AutoService(FileSystemProvider.class)
@@ -99,15 +99,15 @@ public String getScheme() {
}

/**
* 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.<String, Object>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<String, ?> env) {
@@ -537,7 +537,7 @@ public FileStore getFileStore(Path path) {
}

@Override
public boolean equals(@Nullable Object other) {
public boolean equals(Object other) {
return this == other
|| other instanceof CloudStorageFileSystemProvider
&& Objects.equals(storage, ((CloudStorageFileSystemProvider) other).storage);
Original file line number Diff line number Diff line change
@@ -13,11 +13,10 @@
import java.util.Objects;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;

/**
* Metadata for a Google Cloud Storage object.
* Metadata for a Google Cloud Storage file.
*/
@Immutable
final class CloudStorageObjectAttributes implements CloudStorageFileAttributes {
@@ -46,67 +45,36 @@ public FileTime lastModifiedTime() {
return creationTime();
}

/**
* Returns the HTTP etag hash for this object.
*/
@Override
public Optional<String> etag() {
return Optional.fromNullable(info.etag());
}

/**
* Returns the mime type (e.g. text/plain) if it was set for this object.
*/
@Override
public Optional<String> mimeType() {
return Optional.fromNullable(info.contentType());
}

/**
* Returns the ACL value on this Cloud Storage object.
*
* @see "https://developers.google.com/storage/docs/reference-headers#acl"
*/
@Override
public Optional<List<Acl>> acl() {
return Optional.fromNullable(info.acl());
}

/**
* Returns the {@code Cache-Control} HTTP header value, if set on this object.
*
* @see "https://developers.google.com/storage/docs/reference-headers#cachecontrol"
*/
@Override
public Optional<String> cacheControl() {
return Optional.fromNullable(info.cacheControl());
}

/**
* Returns the {@code Content-Encoding} HTTP header value, if set on this object.
*
* @see "https://developers.google.com/storage/docs/reference-headers#contentencoding"
*/
@Override
public Optional<String> contentEncoding() {
return Optional.fromNullable(info.contentEncoding());
}

/**
* Returns the {@code Content-Disposition} HTTP header value, if set on this object.
*
* @see "https://developers.google.com/storage/docs/reference-headers#contentdisposition"
*/
@Override
public Optional<String> contentDisposition() {
return Optional.fromNullable(info.contentDisposition());
}

/**
* Returns user-specified metadata associated with this object.
*
* @see "https://developers.google.com/storage/docs/reference-headers#contentdisposition"
*/
@Override
public ImmutableMap<String, String> userMetadata() {
if (null == info.metadata()) {
@@ -146,7 +114,7 @@ public Object fileKey() {
}

@Override
public boolean equals(@Nullable Object other) {
public boolean equals(Object other) {
return this == other
|| other instanceof CloudStorageObjectAttributes
&& Objects.equals(info, ((CloudStorageObjectAttributes) other).info);
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.google.cloud.storage.contrib.nio;

/**
* Exception thrown to indicate we don't support a mutation of a cloud storage object.
* Exception reminding user that Cloud Storage objects can't be mutated.
*/
public final class CloudStorageObjectImmutableException extends UnsupportedOperationException {

Original file line number Diff line number Diff line change
@@ -273,7 +273,7 @@ public int compareTo(Path other) {
}

@Override
public boolean equals(@Nullable Object other) {
public boolean equals(Object other) {
return this == other
|| other instanceof CloudStoragePath
&& Objects.equals(bucket(), ((CloudStoragePath) other).bucket())
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@
import java.util.List;

/**
* Metadata for a cloud storage pseudo-directory.
* Metadata for a Cloud Storage pseudo-directory.
*/
final class CloudStoragePseudoDirectoryAttributes implements CloudStorageFileAttributes {

Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ 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()));
"Not a Cloud Storage path: %s (%s)", path, path.getClass().getSimpleName()));
}
return (CloudStoragePath) path;
}
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@ private UnixPath(boolean permitEmptyComponents, String path) {
}

/**
* Returns new UnixPath of {@code first}.
* Returns new path of {@code first}.
*/
public static UnixPath getPath(boolean permitEmptyComponents, String path) {
if (path.isEmpty()) {
@@ -71,7 +71,7 @@ public static UnixPath getPath(boolean permitEmptyComponents, String path) {
}

/**
* Returns new UnixPath of {@code first} with {@code more} components resolved against it.
* Returns new path of {@code first} with {@code more} components resolved against it.
*
* @see #resolve(UnixPath)
* @see java.nio.file.FileSystem#getPath(String, String...)
@@ -464,7 +464,7 @@ public Iterator<String> splitReverse() {
}

@Override
public boolean equals(@Nullable Object other) {
public boolean equals(Object other) {
return this == other || other instanceof UnixPath && path.equals(((UnixPath) other).path);
}

Original file line number Diff line number Diff line change
@@ -3,9 +3,9 @@
import static com.google.common.truth.Truth.assertThat;
import static java.nio.charset.StandardCharsets.UTF_8;

import com.google.cloud.storage.testing.LocalGcsHelper;
import com.google.common.testing.EqualsTester;
import com.google.common.testing.NullPointerTester;
import com.google.cloud.storage.testing.LocalGcsHelper;

import org.junit.Before;
import org.junit.Rule;
@@ -14,6 +14,7 @@
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import java.io.IOException;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
@@ -40,23 +41,23 @@ public void before() {
}

@Test
public void testReadAttributes() throws Exception {
public void testReadAttributes() throws IOException {
Files.write(path, HAPPY, CloudStorageOptions.withCacheControl("potato"));
CloudStorageFileAttributeView lazyAttributes =
Files.getFileAttributeView(path, CloudStorageFileAttributeView.class);
assertThat(lazyAttributes.readAttributes().cacheControl().get()).isEqualTo("potato");
}

@Test
public void testReadAttributes_notFound_throwsNoSuchFileException() throws Exception {
public void testReadAttributes_notFound_throwsNoSuchFileException() throws IOException {
CloudStorageFileAttributeView lazyAttributes =
Files.getFileAttributeView(path, CloudStorageFileAttributeView.class);
thrown.expect(NoSuchFileException.class);
lazyAttributes.readAttributes();
}

@Test
public void testReadAttributes_pseudoDirectory() throws Exception {
public void testReadAttributes_pseudoDirectory() throws IOException {
Path dir = Paths.get(URI.create("gs://red/rum/"));
CloudStorageFileAttributeView lazyAttributes =
Files.getFileAttributeView(dir, CloudStorageFileAttributeView.class);
@@ -65,15 +66,15 @@ public void testReadAttributes_pseudoDirectory() throws Exception {
}

@Test
public void testName() throws Exception {
public void testName() throws IOException {
Files.write(path, HAPPY, CloudStorageOptions.withCacheControl("potato"));
CloudStorageFileAttributeView lazyAttributes =
Files.getFileAttributeView(path, CloudStorageFileAttributeView.class);
assertThat(lazyAttributes.name()).isEqualTo("gcs");
}

@Test
public void testEquals_equalsTester() throws Exception {
public void testEquals_equalsTester() {
new EqualsTester()
.addEqualityGroup(
Files.getFileAttributeView(
@@ -87,8 +88,9 @@ public void testEquals_equalsTester() throws Exception {
}

@Test
public void testNullness() throws Exception {
public void testNullness() throws NoSuchMethodException, SecurityException {
new NullPointerTester()
.ignore(CloudStorageFileAttributeView.class.getMethod("equals", Object.class))
.setDefault(FileTime.class, FileTime.fromMillis(0))
.testAllPublicInstanceMethods(
Files.getFileAttributeView(path, CloudStorageFileAttributeView.class));
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import java.io.IOException;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -35,7 +36,6 @@ public class CloudStorageFileAttributesTest {
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() {
CloudStorageFileSystemProvider.setGCloudOptions(LocalGcsHelper.options());
@@ -44,44 +44,44 @@ public void before() {
}

@Test
public void testCacheControl() throws Exception {
public void testCacheControl() throws IOException {
Files.write(path, HAPPY, withCacheControl("potato"));
assertThat(Files.readAttributes(path, CloudStorageFileAttributes.class).cacheControl().get())
.isEqualTo("potato");
}

@Test
public void testMimeType() throws Exception {
public void testMimeType() throws IOException {
Files.write(path, HAPPY, withMimeType("text/potato"));
assertThat(Files.readAttributes(path, CloudStorageFileAttributes.class).mimeType().get())
.isEqualTo("text/potato");
}

@Test
public void testAcl() throws Exception {
public void testAcl() throws IOException {
Acl acl = Acl.of(new Acl.User("serf@example.com"), Acl.Role.READER);
Files.write(path, HAPPY, withAcl(acl));
assertThat(Files.readAttributes(path, CloudStorageFileAttributes.class).acl().get())
.contains(acl);
}

@Test
public void testContentDisposition() throws Exception {
public void testContentDisposition() throws IOException {
Files.write(path, HAPPY, withContentDisposition("crash call"));
assertThat(
Files.readAttributes(path, CloudStorageFileAttributes.class).contentDisposition().get())
.isEqualTo("crash call");
}

@Test
public void testContentEncoding() throws Exception {
public void testContentEncoding() throws IOException {
Files.write(path, HAPPY, withContentEncoding("my content encoding"));
assertThat(Files.readAttributes(path, CloudStorageFileAttributes.class).contentEncoding().get())
.isEqualTo("my content encoding");
}

@Test
public void testUserMetadata() throws Exception {
public void testUserMetadata() throws IOException {
Files.write(path, HAPPY, withUserMetadata("green", "bean"));
assertThat(
Files.readAttributes(path, CloudStorageFileAttributes.class)
@@ -91,15 +91,15 @@ public void testUserMetadata() throws Exception {
}

@Test
public void testIsDirectory() throws Exception {
public void testIsDirectory() throws IOException {
Files.write(path, HAPPY);
assertThat(Files.readAttributes(path, CloudStorageFileAttributes.class).isDirectory())
.isFalse();
assertThat(Files.readAttributes(dir, CloudStorageFileAttributes.class).isDirectory()).isTrue();
}

@Test
public void testIsRegularFile() throws Exception {
public void testIsRegularFile() throws IOException {
Files.write(path, HAPPY);
assertThat(Files.readAttributes(path, CloudStorageFileAttributes.class).isRegularFile())
.isTrue();
@@ -108,14 +108,14 @@ public void testIsRegularFile() throws Exception {
}

@Test
public void testIsOther() throws Exception {
public void testIsOther() throws IOException {
Files.write(path, HAPPY);
assertThat(Files.readAttributes(path, CloudStorageFileAttributes.class).isOther()).isFalse();
assertThat(Files.readAttributes(dir, CloudStorageFileAttributes.class).isOther()).isFalse();
}

@Test
public void testIsSymbolicLink() throws Exception {
public void testIsSymbolicLink() throws IOException {
Files.write(path, HAPPY);
assertThat(Files.readAttributes(path, CloudStorageFileAttributes.class).isSymbolicLink())
.isFalse();
@@ -124,7 +124,7 @@ public void testIsSymbolicLink() throws Exception {
}

@Test
public void testEquals_equalsTester() throws Exception {
public void testEquals_equalsTester() throws IOException {
Files.write(path, HAPPY, withMimeType("text/plain"));
CloudStorageFileAttributes a1 = Files.readAttributes(path, CloudStorageFileAttributes.class);
CloudStorageFileAttributes a2 = Files.readAttributes(path, CloudStorageFileAttributes.class);
@@ -135,7 +135,7 @@ public void testEquals_equalsTester() throws Exception {
}

@Test
public void testFilekey() throws Exception {
public void testFilekey() throws IOException {
Files.write(path, HAPPY, withMimeType("text/plain"));
Path path2 = Paths.get(URI.create("gs://bucket/anotherrandompath"));
Files.write(path2, HAPPY, withMimeType("text/plain"));
@@ -155,13 +155,14 @@ public void testFilekey() throws Exception {
}

@Test
public void testNullness() throws Exception {
public void testNullness() throws IOException, NoSuchMethodException, SecurityException {
Files.write(path, HAPPY);
CloudStorageFileAttributes pathAttributes =
Files.readAttributes(path, CloudStorageFileAttributes.class);
CloudStorageFileAttributes dirAttributes =
Files.readAttributes(dir, CloudStorageFileAttributes.class);
NullPointerTester tester = new NullPointerTester();
tester.ignore(CloudStorageObjectAttributes.class.getMethod("equals", Object.class));
tester.testAllPublicInstanceMethods(pathAttributes);
tester.testAllPublicInstanceMethods(dirAttributes);
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import java.io.IOException;
import java.net.URI;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
@@ -40,15 +41,15 @@ public void before() {
}

@Test
public void testGetPath() throws Exception {
public void testGetPath() throws IOException {
try (FileSystem fs = CloudStorageFileSystem.forBucket("bucket")) {
assertThat(fs.getPath("/angel").toString()).isEqualTo("/angel");
assertThat(fs.getPath("/angel").toUri().toString()).isEqualTo("gs://bucket/angel");
}
}

@Test
public void testWrite() throws Exception {
public void testWrite() throws IOException {
try (FileSystem fs = CloudStorageFileSystem.forBucket("bucket")) {
Files.write(fs.getPath("/angel"), ALONE.getBytes(UTF_8));
}
@@ -57,30 +58,30 @@ public void testWrite() throws Exception {
}

@Test
public void testRead() throws Exception {
public void testRead() throws IOException {
Files.write(Paths.get(URI.create("gs://bucket/angel")), ALONE.getBytes(UTF_8));
try (FileSystem fs = CloudStorageFileSystem.forBucket("bucket")) {
assertThat(new String(Files.readAllBytes(fs.getPath("/angel")), UTF_8)).isEqualTo(ALONE);
}
}

@Test
public void testExists_false() throws Exception {
public void testExists_false() throws IOException {
try (FileSystem fs = FileSystems.getFileSystem(URI.create("gs://bucket"))) {
assertThat(Files.exists(fs.getPath("/angel"))).isFalse();
}
}

@Test
public void testExists_true() throws Exception {
public void testExists_true() throws IOException {
Files.write(Paths.get(URI.create("gs://bucket/angel")), ALONE.getBytes(UTF_8));
try (FileSystem fs = CloudStorageFileSystem.forBucket("bucket")) {
assertThat(Files.exists(fs.getPath("/angel"))).isTrue();
}
}

@Test
public void testGetters() throws Exception {
public void testGetters() throws IOException {
try (FileSystem fs = CloudStorageFileSystem.forBucket("bucket")) {
assertThat(fs.isOpen()).isTrue();
assertThat(fs.isReadOnly()).isFalse();
@@ -92,7 +93,7 @@ public void testGetters() throws Exception {
}

@Test
public void testEquals() throws Exception {
public void testEquals() throws IOException {
try (FileSystem bucket1 = CloudStorageFileSystem.forBucket("bucket");
FileSystem bucket2 = FileSystems.getFileSystem(URI.create("gs://bucket"));
FileSystem doge1 = CloudStorageFileSystem.forBucket("doge");
@@ -105,10 +106,11 @@ public void testEquals() throws Exception {
}

@Test
public void testNullness() throws Exception {
public void testNullness() throws IOException, NoSuchMethodException, SecurityException {
try (FileSystem fs = FileSystems.getFileSystem(URI.create("gs://bucket"))) {
NullPointerTester tester =
new NullPointerTester()
.ignore(CloudStorageFileSystem.class.getMethod("equals", Object.class))
.setDefault(CloudStorageConfiguration.class, CloudStorageConfiguration.DEFAULT);
tester.testAllPublicStaticMethods(CloudStorageFileSystem.class);
tester.testAllPublicInstanceMethods(fs);
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import java.io.IOException;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -36,23 +37,23 @@ public void before() {
}

@Test
public void testWithoutCaching() throws Exception {
public void testWithoutCaching() throws IOException {
Path path = Paths.get(URI.create("gs://bucket/path"));
Files.write(path, "(✿◕ ‿◕ )ノ".getBytes(UTF_8), withoutCaching());
assertThat(Files.readAttributes(path, CloudStorageFileAttributes.class).cacheControl().get())
.isEqualTo("no-cache");
}

@Test
public void testCacheControl() throws Exception {
public void testCacheControl() throws IOException {
Path path = Paths.get(URI.create("gs://bucket/path"));
Files.write(path, "(✿◕ ‿◕ )ノ".getBytes(UTF_8), withCacheControl("potato"));
assertThat(Files.readAttributes(path, CloudStorageFileAttributes.class).cacheControl().get())
.isEqualTo("potato");
}

@Test
public void testWithAcl() throws Exception {
public void testWithAcl() throws IOException {
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));
@@ -61,7 +62,7 @@ public void testWithAcl() throws Exception {
}

@Test
public void testWithContentDisposition() throws Exception {
public void testWithContentDisposition() throws IOException {
Path path = Paths.get(URI.create("gs://bucket/path"));
Files.write(path, "(✿◕ ‿◕ )ノ".getBytes(UTF_8), withContentDisposition("bubbly fun"));
assertThat(
@@ -70,15 +71,15 @@ public void testWithContentDisposition() throws Exception {
}

@Test
public void testWithContentEncoding() throws Exception {
public void testWithContentEncoding() throws IOException {
Path path = Paths.get(URI.create("gs://bucket/path"));
Files.write(path, "(✿◕ ‿◕ )ノ".getBytes(UTF_8), withContentEncoding("gzip"));
assertThat(Files.readAttributes(path, CloudStorageFileAttributes.class).contentEncoding().get())
.isEqualTo("gzip");
}

@Test
public void testWithUserMetadata() throws Exception {
public void testWithUserMetadata() throws IOException {
Path path = Paths.get(URI.create("gs://bucket/path"));
Files.write(
path,
@@ -96,15 +97,15 @@ public void testWithUserMetadata() throws Exception {
}

@Test
public void testWithMimeType_string() throws Exception {
public void testWithMimeType_string() throws IOException {
Path path = Paths.get(URI.create("gs://bucket/path"));
Files.write(path, "(✿◕ ‿◕ )ノ".getBytes(UTF_8), withMimeType("text/plain"));
assertThat(Files.readAttributes(path, CloudStorageFileAttributes.class).mimeType().get())
.isEqualTo("text/plain");
}

@Test
public void testNullness() throws Exception {
public void testNullness() {
NullPointerTester tester = new NullPointerTester();
tester.testAllPublicStaticMethods(CloudStorageOptions.class);
}
Original file line number Diff line number Diff line change
@@ -15,11 +15,11 @@
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import java.io.IOException;
import java.net.URI;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.ProviderMismatchException;

/**
@@ -269,7 +269,6 @@ public void testNormalize_preserveTrailingSlash() {
}

@Test
@SuppressWarnings("null")
public void testGetParent_preserveTrailingSlash() {
try (CloudStorageFileSystem fs = forBucket("doodle")) {
assertThat(fs.getPath("a/b/c").getParent().toString()).isEqualTo("a/b/");
@@ -282,7 +281,6 @@ public void testGetParent_preserveTrailingSlash() {
}

@Test
@SuppressWarnings("null")
public void testGetRoot() {
try (CloudStorageFileSystem fs = forBucket("doodle")) {
assertThat(fs.getPath("/hello").getRoot().toString()).isEqualTo("/");
@@ -301,18 +299,18 @@ public void testRelativize() {

@Test
public void testRelativize_providerMismatch() {
try (CloudStorageFileSystem fs = forBucket("doodle")) {
try (CloudStorageFileSystem gcs = forBucket("doodle")) {
thrown.expect(ProviderMismatchException.class);
fs.getPath("/etc").relativize(Paths.get("/dog"));
gcs.getPath("/etc").relativize(FileSystems.getDefault().getPath("/dog"));
}
}

@Test
@SuppressWarnings("ReturnValueIgnored") // testing that an Exception is thrown
public void testRelativize_providerMismatch2() {
try (CloudStorageFileSystem fs = forBucket("doodle")) {
try (CloudStorageFileSystem gcs = forBucket("doodle")) {
thrown.expect(ProviderMismatchException.class);
Paths.get("/dog").relativize(fs.getPath("/etc"));
gcs.getPath("/dog").relativize(FileSystems.getDefault().getPath("/etc"));
}
}

@@ -326,9 +324,9 @@ public void testResolve() {

@Test
public void testResolve_providerMismatch() {
try (CloudStorageFileSystem fs = forBucket("doodle")) {
try (CloudStorageFileSystem gcs = forBucket("doodle")) {
thrown.expect(ProviderMismatchException.class);
fs.getPath("etc").resolve(Paths.get("/dog"));
gcs.getPath("etc").resolve(FileSystems.getDefault().getPath("/dog"));
}
}

@@ -356,7 +354,6 @@ public void testToAbsolutePath_withWorkingDirectory() {
}

@Test
@SuppressWarnings("null")
public void testGetFileName() {
try (CloudStorageFileSystem fs = forBucket("doodle")) {
assertThat(fs.getPath("/hi/there").getFileName().toString()).isEqualTo("there");
@@ -402,10 +399,9 @@ public void testEndsWith() {
}
}

/** @see "http://stackoverflow.com/a/10068306".
*/
@Test
public void testResolve_willWorkWithRecursiveCopy() throws Exception {
public void testResolve_willWorkWithRecursiveCopy() throws IOException {
// See: http://stackoverflow.com/a/10068306
try (FileSystem fsSource = FileSystems.getFileSystem(URI.create("gs://hello"));
FileSystem fsTarget = FileSystems.getFileSystem(URI.create("gs://cat"))) {
Path targetPath = fsTarget.getPath("/some/folder/");
@@ -415,10 +411,9 @@ public void testResolve_willWorkWithRecursiveCopy() throws Exception {
}
}

/** @see "http://stackoverflow.com/a/10068306".
*/
@Test
public void testRelativize_willWorkWithRecursiveCopy() throws Exception {
public void testRelativize_willWorkWithRecursiveCopy() throws IOException {
// See: http://stackoverflow.com/a/10068306
try (FileSystem fsSource = FileSystems.getFileSystem(URI.create("gs://hello"));
FileSystem fsTarget = FileSystems.getFileSystem(URI.create("gs://cat"))) {
Path targetPath = fsTarget.getPath("/some/folder/");
@@ -465,9 +460,11 @@ public void testEquals_currentDirectoryIsTakenIntoConsideration() {
}

@Test
public void testNullness() {
public void testNullness() throws NoSuchMethodException, SecurityException {
try (CloudStorageFileSystem fs = forBucket("doodle")) {
NullPointerTester tester = new NullPointerTester().setDefault(Path.class, fs.getPath("sup"));
NullPointerTester tester = new NullPointerTester();
tester.ignore(CloudStoragePath.class.getMethod("equals", Object.class));
tester.setDefault(Path.class, fs.getPath("sup"));
tester.testAllPublicStaticMethods(CloudStoragePath.class);
tester.testAllPublicInstanceMethods(fs.getPath("sup"));
}
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.NonReadableChannelException;
@@ -40,13 +41,13 @@ public void before() {
}

@Test
public void testRead_throwsNonReadableChannelException() throws Exception {
public void testRead_throwsNonReadableChannelException() throws IOException {
thrown.expect(NonReadableChannelException.class);
chan.read(ByteBuffer.allocate(1));
}

@Test
public void testWrite() throws Exception {
public void testWrite() throws IOException {
ByteBuffer buffer = ByteBuffer.allocate(1);
buffer.put((byte) 'B');
assertThat(chan.position()).isEqualTo(0L);
@@ -61,14 +62,14 @@ public void testWrite() throws Exception {
}

@Test
public void testWrite_whenClosed_throwsCce() throws Exception {
public void testWrite_whenClosed_throwsCce() throws IOException {
when(gcsChannel.isOpen()).thenReturn(false);
thrown.expect(ClosedChannelException.class);
chan.write(ByteBuffer.allocate(1));
}

@Test
public void testIsOpen() throws Exception {
public void testIsOpen() throws IOException {
when(gcsChannel.isOpen()).thenReturn(true).thenReturn(false);
assertThat(chan.isOpen()).isTrue();
chan.close();
@@ -79,28 +80,28 @@ public void testIsOpen() throws Exception {
}

@Test
public void testSize() throws Exception {
public void testSize() throws IOException {
assertThat(chan.size()).isEqualTo(0L);
verify(gcsChannel).isOpen();
verifyZeroInteractions(gcsChannel);
}

@Test
public void testSize_whenClosed_throwsCce() throws Exception {
public void testSize_whenClosed_throwsCce() throws IOException {
when(gcsChannel.isOpen()).thenReturn(false);
thrown.expect(ClosedChannelException.class);
chan.size();
}

@Test
public void testPosition_whenClosed_throwsCce() throws Exception {
public void testPosition_whenClosed_throwsCce() throws IOException {
when(gcsChannel.isOpen()).thenReturn(false);
thrown.expect(ClosedChannelException.class);
chan.position();
}

@Test
public void testClose_calledMultipleTimes_doesntThrowAnError() throws Exception {
public void testClose_calledMultipleTimes_doesntThrowAnError() throws IOException {
chan.close();
chan.close();
chan.close();
Original file line number Diff line number Diff line change
@@ -360,7 +360,7 @@ public void testSeemsLikeADirectory() {
}

@Test
public void testEquals_equalsTester() throws Exception {
public void testEquals_equalsTester() {
new EqualsTester()
.addEqualityGroup(p("/lol"), p("/lol"))
.addEqualityGroup(p("/lol//"), p("/lol//"))
@@ -369,8 +369,9 @@ public void testEquals_equalsTester() throws Exception {
}

@Test
public void testNullness() {
public void testNullness() throws Exception {
NullPointerTester tester = new NullPointerTester();
tester.ignore(UnixPath.class.getMethod("equals", Object.class));
tester.testAllPublicStaticMethods(UnixPath.class);
tester.testAllPublicInstanceMethods(p("solo"));
}

0 comments on commit 20b01d3

Please sign in to comment.