Skip to content

Commit 92689ab

Browse files
test: test that Java picks up the NIO provider (#284)
* test: test that Java picks up the NIO provider * style: formatting
1 parent 6d5295f commit 92689ab

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

  • java-storage-nio/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2020 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.cloud.storage.contrib.nio;
18+
19+
import static com.google.common.truth.Truth.assertThat;
20+
21+
import java.net.URI;
22+
import java.nio.file.Path;
23+
import java.nio.file.Paths;
24+
import org.junit.Before;
25+
import org.junit.Test;
26+
import org.junit.runner.RunWith;
27+
import org.junit.runners.JUnit4;
28+
29+
/**
30+
* Unit tests for {@link CloudStorageFileSystemProvider}. Makes sure the NIO system picks it up
31+
* properly.
32+
*/
33+
@RunWith(JUnit4.class)
34+
public class NIOTest {
35+
36+
private URI uriToCloudStorage;
37+
38+
@Before
39+
public void setUp() {
40+
uriToCloudStorage = URI.create("gs://bucket/file.txt");
41+
}
42+
43+
/** We can create a Path object from a gs:// URI. * */
44+
@Test
45+
public void testCreatePath() {
46+
// Return value ignored on purpose, we just want to check
47+
// no exception is thrown.
48+
Path path = Paths.get(uriToCloudStorage);
49+
// Truth bug workaround, see https://github.com/google/truth/issues/285
50+
assertThat((Object) path).isNotNull();
51+
}
52+
53+
/** The created Path object has the correct scheme. * */
54+
@Test
55+
public void testCreatedPathIsGS() {
56+
Path path = Paths.get(uriToCloudStorage);
57+
assertThat(path.getFileSystem().provider().getScheme()).isEqualTo("gs");
58+
}
59+
}

0 commit comments

Comments
 (0)