|
17 | 17 | package com.google.cloud.storage.contrib.nio; |
18 | 18 |
|
19 | 19 | import static com.google.common.truth.Truth.assertThat; |
20 | | -import static com.google.common.truth.Truth.assertWithMessage; |
21 | 20 | import static java.nio.charset.StandardCharsets.UTF_8; |
22 | 21 |
|
23 | 22 | import com.google.cloud.storage.StorageOptions; |
@@ -166,18 +165,23 @@ public void testListFiles() throws IOException { |
166 | 165 | @Test |
167 | 166 | public void testMatcher() throws IOException { |
168 | 167 | try (FileSystem fs = CloudStorageFileSystem.forBucket("bucket")) { |
169 | | - List<String> paths = ImmutableList.of("a.java", "a.text", "folder/c.java", "d"); |
170 | 168 | String pattern1 = "glob:*.java"; |
171 | 169 | PathMatcher matcher1 = fs.getPathMatcher(pattern1); |
172 | | - List<Boolean> matches1 = ImmutableList.of(true, false, true, false); |
173 | 170 | String pattern2 = "glob:*.{java,text}"; |
174 | 171 | PathMatcher matcher2 = fs.getPathMatcher(pattern2); |
175 | | - List<Boolean> matches2 = ImmutableList.of(true, true, true, false); |
176 | | - for (int i=0; i<paths.size(); i++) { |
177 | | - Path input = fs.getPath(paths.get(i)).getFileName(); |
178 | | - assertWithMessage(pattern1 + " on " + paths.get(i)).that(matcher1.matches(input)).isEqualTo(matches1.get(i)); |
179 | | - assertWithMessage(pattern2 + " on " + paths.get(i)).that(matcher2.matches(input)).isEqualTo(matches2.get(i)); |
180 | | - } |
| 172 | + |
| 173 | + assertMatches(fs, matcher1, "a.java", true); |
| 174 | + assertMatches(fs, matcher1, "a.text", false); |
| 175 | + assertMatches(fs, matcher1, "folder/c.java", true); |
| 176 | + assertMatches(fs, matcher1, "d", false); |
| 177 | + assertMatches(fs, matcher2, "a.java", true); |
| 178 | + assertMatches(fs, matcher2, "a.text", true); |
| 179 | + assertMatches(fs, matcher2, "folder/c.java", true); |
| 180 | + assertMatches(fs, matcher2, "d", false); |
181 | 181 | } |
182 | 182 | } |
| 183 | + |
| 184 | + private void assertMatches(FileSystem fs, PathMatcher matcher, String toMatch, boolean expected) { |
| 185 | + assertThat(matcher.matches(fs.getPath(toMatch).getFileName())).isEqualTo(expected); |
| 186 | + } |
183 | 187 | } |
0 commit comments