LocalFileSystem extends FileSystem<LocalResourceId> { @Override protected LocalResourceId matchNewResource(String singleResourceSpec, boolean isDirectory) { if (isDirectory) { if (!singleResourceSpec.endsWith(File.separator)) { singleResourceSpec += File.separator; } } else { checkArgument( !singleResourceSpec.endsWith(File.separator), "Expected file path but received directory path [%s].", singleResourceSpec); } Path path = Paths.get(singleResourceSpec); return LocalResourceId.fromPath(path, isDirectory); } LocalFileSystem();   }
@Test public void testMatchNewResource() { assumeFalse(SystemUtils.IS_OS_WINDOWS); LocalResourceId fileResource = localFileSystem.matchNewResource("/some/test/resource/path", false ); LocalResourceId dirResource = localFileSystem.matchNewResource("/some/test/resource/path", true ); assertNotEquals(fileResource, dirResource); assertThat( fileResource .getCurrentDirectory() .resolve("path", StandardResolveOptions.RESOLVE_DIRECTORY), equalTo(dirResource.getCurrentDirectory())); assertThat( fileResource .getCurrentDirectory() .resolve("path", StandardResolveOptions.RESOLVE_DIRECTORY), equalTo(dirResource.getCurrentDirectory())); assertThat(dirResource.toString(), equalTo("/some/test/resource/path/")); IllegalArgumentException exception = assertThrows( IllegalArgumentException.class, () -> localFileSystem.matchNewResource("/some/test/resource/path/", false)); assertTrue(exception.getMessage().startsWith("Expected file path but received directory path")); }