Skip to content

Commit

Permalink
Merge 998ae3d into b85e1cc
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-philippe-martin committed Dec 9, 2016
2 parents b85e1cc + 998ae3d commit c1798ce
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.net.URISyntaxException;
import java.nio.file.FileStore;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.nio.file.PathMatcher;
import java.nio.file.WatchService;
Expand Down Expand Up @@ -210,13 +211,9 @@ public Set<String> supportedFileAttributeViews() {
return SUPPORTED_VIEWS;
}

/**
* Throws {@link UnsupportedOperationException} because this feature hasn't been implemented yet.
*/
@Override
public PathMatcher getPathMatcher(String syntaxAndPattern) {
// TODO(#813): Implement me.
throw new UnsupportedOperationException();
return FileSystems.getDefault().getPathMatcher(syntaxAndPattern);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
package com.google.cloud.storage.contrib.nio;

import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static java.nio.charset.StandardCharsets.UTF_8;

import com.google.cloud.storage.StorageOptions;
import com.google.common.collect.ImmutableList;
import com.google.common.testing.EqualsTester;
import com.google.common.testing.NullPointerTester;

Expand All @@ -34,6 +36,7 @@
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.PathMatcher;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -159,4 +162,22 @@ public void testListFiles() throws IOException {
assertThat(got).containsExactlyElementsIn(goodPaths);
}
}

@Test
public void testMatcher() throws IOException {
try (FileSystem fs = CloudStorageFileSystem.forBucket("bucket")) {
List<String> paths = ImmutableList.of("a.java", "a.text", "folder/c.java", "d");
String pattern1 = "glob:*.java";
PathMatcher matcher1 = fs.getPathMatcher(pattern1);
List<Boolean> matches1 = ImmutableList.of(true, false, true, false);
String pattern2 = "glob:*.{java,text}";
PathMatcher matcher2 = fs.getPathMatcher(pattern2);
List<Boolean> matches2 = ImmutableList.of(true, true, true, false);
for (int i=0; i<paths.size(); i++) {
Path input = fs.getPath(paths.get(i)).getFileName();
assertWithMessage(pattern1 + " on " + paths.get(i)).that(matcher1.matches(input)).isEqualTo(matches1.get(i));
assertWithMessage(pattern2 + " on " + paths.get(i)).that(matcher2.matches(input)).isEqualTo(matches2.get(i));
}
}
}
}

0 comments on commit c1798ce

Please sign in to comment.