LocalFileSystem extends FileSystem<LocalResourceId> { @Override protected List<MatchResult> match(List<String> specs) throws IOException { return match(new File(".").getAbsolutePath(), specs); } LocalFileSystem();   }
@Test public void testMatchRelativeWildcardPath() throws Exception { File baseFolder = temporaryFolder.newFolder("A"); File expectedFile1 = new File(baseFolder, "file1"); expectedFile1.createNewFile(); List<String> expected = ImmutableList.of(expectedFile1.getAbsolutePath()); List<MatchResult> matchResults = localFileSystem.match(temporaryFolder.getRoot().toString(), ImmutableList.of("A/*")); assertThat( toFilenames(matchResults), containsInAnyOrder(expected.toArray(new String[expected.size()]))); }
@Test public void testMatchExact() throws Exception { List<String> expected = ImmutableList.of(temporaryFolder.newFile("a").toString()); temporaryFolder.newFile("aa"); temporaryFolder.newFile("ab"); List<MatchResult> matchResults = localFileSystem.match( ImmutableList.of(temporaryFolder.getRoot().toPath().resolve("a").toString())); assertThat( toFilenames(matchResults), containsInAnyOrder(expected.toArray(new String[expected.size()]))); }
@Test public void testMatchForNonExistentFile() throws Exception { temporaryFolder.newFile("aa"); List<MatchResult> matchResults = localFileSystem.match( ImmutableList.of(temporaryFolder.getRoot().toPath().resolve("a").toString())); assertEquals(1, matchResults.size()); assertEquals(MatchResult.Status.NOT_FOUND, matchResults.get(0).status()); }
@Test public void testMatchInDirectory() throws Exception { List<String> expected = ImmutableList.of(temporaryFolder.newFile("a").toString()); temporaryFolder.newFile("aa"); temporaryFolder.newFile("ab"); String expectedFile = expected.get(0); int slashIndex = expectedFile.lastIndexOf('/'); if (SystemUtils.IS_OS_WINDOWS) { slashIndex = expectedFile.lastIndexOf('\\'); } String directory = expectedFile.substring(0, slashIndex); String relative = expectedFile.substring(slashIndex + 1); List<MatchResult> results = localFileSystem.match(directory, ImmutableList.of(relative)); assertThat( toFilenames(results), containsInAnyOrder(expected.toArray(new String[expected.size()]))); }
@Test public void testMatchWithFileSlashPrefix() throws Exception { List<String> expected = ImmutableList.of(temporaryFolder.newFile("a").toString()); temporaryFolder.newFile("aa"); temporaryFolder.newFile("ab"); String file = "file:/" + temporaryFolder.getRoot().toPath().resolve("a").toString(); List<MatchResult> results = localFileSystem.match(ImmutableList.of(file)); assertThat( toFilenames(results), containsInAnyOrder(expected.toArray(new String[expected.size()]))); }
@Test public void testMatchWithFileThreeSlashesPrefix() throws Exception { List<String> expected = ImmutableList.of(temporaryFolder.newFile("a").toString()); temporaryFolder.newFile("aa"); temporaryFolder.newFile("ab"); String file = "file: List<MatchResult> results = localFileSystem.match(ImmutableList.of(file)); assertThat( toFilenames(results), containsInAnyOrder(expected.toArray(new String[expected.size()]))); }
@Test public void testMatchWithoutParentDirectory() throws Exception { assumeFalse(SystemUtils.IS_OS_WINDOWS); Path pattern = LocalResourceId.fromPath(temporaryFolder.getRoot().toPath(), true ) .resolve("non_existing_dir", StandardResolveOptions.RESOLVE_DIRECTORY) .resolve("*", StandardResolveOptions.RESOLVE_FILE) .getPath(); assertTrue(toFilenames(localFileSystem.match(ImmutableList.of(pattern.toString()))).isEmpty()); }