|
28 | 28 | import static java.nio.file.StandardOpenOption.WRITE; |
29 | 29 |
|
30 | 30 | import com.google.common.collect.ImmutableList; |
31 | | -import com.google.common.net.UrlEscapers; |
32 | 31 | import com.google.common.testing.NullPointerTester; |
33 | 32 |
|
34 | 33 | import org.junit.Before; |
@@ -655,28 +654,26 @@ public void testNewFileSystem() throws IOException { |
655 | 654 | } |
656 | 655 |
|
657 | 656 | @Test |
658 | | - public void testFromSpace() throws UnsupportedEncodingException { |
| 657 | + public void testFromSpace() throws UnsupportedEncodingException, IOException { |
659 | 658 | // User should be able to create paths to files whose name contains a space. |
660 | 659 | // Traditional way 1: manually escape the spaces |
661 | 660 | Path path1 = Paths.get(URI.create("gs://bucket/with/a%20space")); |
662 | 661 | CloudStorageFileSystemProvider provider = |
663 | 662 | (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 | + |
667 | 667 | // Non-traditional way: use our convenience method to work around URIs not being allowed to |
668 | 668 | // contain spaces. |
669 | 669 | 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()); |
675 | 673 |
|
| 674 | + // getPath does not interpret the string at all. |
676 | 675 | 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"); |
680 | 677 | } |
681 | 678 |
|
682 | 679 | private static CloudStorageConfiguration permitEmptyPathComponents(boolean value) { |
|
0 commit comments