Skip to content

Commit 0757985

Browse files
reviewer and linter comments
1 parent eccc885 commit 0757985

2 files changed

Lines changed: 12 additions & 18 deletions

File tree

google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystemProviderTest.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import static java.nio.file.StandardOpenOption.WRITE;
2929

3030
import com.google.common.collect.ImmutableList;
31-
import com.google.common.net.UrlEscapers;
3231
import com.google.common.testing.NullPointerTester;
3332

3433
import org.junit.Before;
@@ -655,28 +654,26 @@ public void testNewFileSystem() throws IOException {
655654
}
656655

657656
@Test
658-
public void testFromSpace() throws UnsupportedEncodingException {
657+
public void testFromSpace() throws UnsupportedEncodingException, IOException {
659658
// User should be able to create paths to files whose name contains a space.
660659
// Traditional way 1: manually escape the spaces
661660
Path path1 = Paths.get(URI.create("gs://bucket/with/a%20space"));
662661
CloudStorageFileSystemProvider provider =
663662
(CloudStorageFileSystemProvider)path1.getFileSystem().provider();
664-
// Traditional way 2: use a library to escape the spaces
665-
String escaped = UrlEscapers.urlFragmentEscaper().escape("gs://bucket/with/a space");
666-
Path path2 = Paths.get(URI.create(escaped));
663+
// Traditional way 2: use UrlEscapers.urlFragmentEscaper().escape
664+
// to escape the string for you.
665+
// (Not tested because UrlEscapers isn't the unit under test).
666+
667667
// Non-traditional way: use our convenience method to work around URIs not being allowed to
668668
// contain spaces.
669669
Path path3 = provider.getPath("gs://bucket/with/a space");
670-
// All 3 should be equivalent
671-
assertThat(path1.getFileSystem().provider()).isEqualTo(path2.getFileSystem().provider());
672-
assertThat(path2.getFileSystem().provider()).isEqualTo(path3.getFileSystem().provider());
673-
assertThat(path1.toUri()).isEqualTo(path2.toUri());
674-
assertThat(path2.toUri()).isEqualTo(path3.toUri());
670+
// Both approaches should be equivalent
671+
assertThat(path1.getFileSystem().provider()).isEqualTo(path3.getFileSystem().provider());
672+
assertThat(path1.toUri()).isEqualTo(path3.toUri());
675673

674+
// getPath does not interpret the string at all.
676675
Path path4 = provider.getPath("gs://bucket/with/a%20percent");
677-
String toString = path4.toString();
678-
assertThat(toString).doesNotContain(" ");
679-
assertThat(toString).contains("%");
676+
assertThat(path4.toString()).isEqualTo("/with/a%20percent");
680677
}
681678

682679
private static CloudStorageConfiguration permitEmptyPathComponents(boolean value) {

google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/CloudStoragePathTest.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -489,16 +489,13 @@ public void testNullness() throws IOException, NoSuchMethodException, SecurityEx
489489
public void testSpaces() throws IOException {
490490
try (CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("doodle")) {
491491
Path path = fs.getPath("/with/a space");
492-
String toString = path.toString();
493-
assertThat(toString).contains(" ");
494492
// we can also go via a URI. Decoding should give us the space back.
495493
String toUri = URLDecoder.decode(path.toUri().toString(), "UTF-8");
496-
assertThat(toUri).contains(" ");
494+
assertThat(toUri).isEqualTo("gs://doodle/with/a space");
497495

498496
Path path2 = fs.getPath("/with/a%20percent");
499497
String toUri2 = URLDecoder.decode(path2.toUri().toString(), "UTF-8");
500-
assertThat(toUri2).doesNotContain(" ");
501-
assertThat(toUri2).contains("%");
498+
assertThat(toUri2).isEqualTo("gs://doodle/with/a%20percent");
502499
}
503500
}
504501

0 commit comments

Comments
 (0)