GcsResourceId implements ResourceId { @Override public GcsResourceId resolve(String other, ResolveOptions resolveOptions) { checkState( isDirectory(), String.format("Expected the gcsPath is a directory, but had [%s].", gcsPath)); checkArgument( resolveOptions.equals(StandardResolveOptions.RESOLVE_FILE) || resolveOptions.equals(StandardResolveOptions.RESOLVE_DIRECTORY), String.format("ResolveOptions: [%s] is not supported.", resolveOptions)); if (resolveOptions.equals(StandardResolveOptions.RESOLVE_FILE)) { checkArgument( !other.endsWith("/"), "The resolved file: [%s] should not end with '/'.", other); return fromGcsPath(gcsPath.resolve(other)); } else { if (other.endsWith("/")) { return fromGcsPath(gcsPath.resolve(other)); } else { return fromGcsPath(gcsPath.resolve(other + "/")); } } } private  GcsResourceId(GcsPath gcsPath); @Override GcsResourceId resolve(String other, ResolveOptions resolveOptions); @Override GcsResourceId getCurrentDirectory(); @Override boolean isDirectory(); @Override String getScheme(); @Override @Nullable String getFilename(); @Override String toString(); @Override boolean equals(@Nullable Object obj); @Override int hashCode();  }
@Test public void testResolve() { assertEquals( toResourceIdentifier("gs: toResourceIdentifier("gs: .resolve("aa", StandardResolveOptions.RESOLVE_FILE)); assertEquals( toResourceIdentifier("gs: toResourceIdentifier("gs: .resolve("aa", StandardResolveOptions.RESOLVE_DIRECTORY) .resolve("bb", StandardResolveOptions.RESOLVE_DIRECTORY) .resolve("cc", StandardResolveOptions.RESOLVE_DIRECTORY)); assertEquals( toResourceIdentifier("gs: toResourceIdentifier("gs: .resolve("gs: assertEquals( toResourceIdentifier("gs: toResourceIdentifier("gs: assertEquals( toResourceIdentifier("gs: toResourceIdentifier("gs: .resolve("输出 文件01.txt", StandardResolveOptions.RESOLVE_FILE)); }
@Test public void testResolveHandleBadInputs() { assertEquals( toResourceIdentifier("gs: toResourceIdentifier("gs: .resolve("tmp/", StandardResolveOptions.RESOLVE_DIRECTORY)); }
@Test public void testResolveInvalidInputs() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("The resolved file: [tmp/] should not end with '/'."); toResourceIdentifier("gs: }
@Test public void testResolveInvalidNotDirectory() { ResourceId tmpDir = toResourceIdentifier("gs: .resolve("tmp dir", StandardResolveOptions.RESOLVE_FILE); thrown.expect(IllegalStateException.class); thrown.expectMessage("Expected the gcsPath is a directory, but had [gs: tmpDir.resolve("aa", StandardResolveOptions.RESOLVE_FILE); }