diff options
author | jijiang <jijiang@google.com> | 2017-11-15 06:27:22 -0800 |
---|---|---|
committer | Ron Shapiro <ronshapiro@google.com> | 2017-11-20 15:12:10 -0500 |
commit | 726b14ba240a2c897d39858516c174e654a29877 (patch) | |
tree | 53ab59ea409d98c55d6d0322624d5f8a1c35cb99 | |
parent | 7e5b6fe2a0b7ef8cb1ff59b9f43cdbc54c5c59e9 (diff) | |
download | jimfs-726b14ba240a2c897d39858516c174e654a29877.tar.gz |
Replace truth.FailureStrategy with truth.FailureMetadata in custom Subjects.
Also changed truth.SubjectFactory to truth.Subject.Factory (plain renaming) and use method reference instead of anonymous class to create the factory when applicable.
FailureMetadata, an opaque object to its users, is introduced to replace FailureStrategy in in custom Subject in order to resolve some existing flaws of FailureStrategy as well as enable new features to be added to Truth.
New API is available in Truth-0.36, if there is a build/pom.xml, it's also updated to use this version.
More information: See [] & []
Tested:
TAP --sample for global presubmit queue
[]
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=175818007
-rw-r--r-- | jimfs/src/test/java/com/google/common/jimfs/PathSubject.java | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/jimfs/src/test/java/com/google/common/jimfs/PathSubject.java b/jimfs/src/test/java/com/google/common/jimfs/PathSubject.java index c5387a1..5eb1c0b 100644 --- a/jimfs/src/test/java/com/google/common/jimfs/PathSubject.java +++ b/jimfs/src/test/java/com/google/common/jimfs/PathSubject.java @@ -21,10 +21,8 @@ import static java.nio.charset.StandardCharsets.UTF_8; import com.google.common.collect.ImmutableList; import com.google.common.io.BaseEncoding; -import com.google.common.truth.FailureStrategy; +import com.google.common.truth.FailureMetadata; import com.google.common.truth.Subject; -import com.google.common.truth.SubjectFactory; - import java.io.IOException; import java.nio.charset.Charset; import java.nio.file.DirectoryStream; @@ -36,7 +34,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Objects; - import javax.annotation.Nullable; /** @@ -46,10 +43,8 @@ import javax.annotation.Nullable; */ public final class PathSubject extends Subject<PathSubject, Path> { - /** - * Returns the subject factory for doing assertions on paths. - */ - public static SubjectFactory<PathSubject, Path> paths() { + /** Returns the subject factory for doing assertions on paths. */ + public static Subject.Factory<PathSubject, Path> paths() { return new PathSubjectFactory(); } @@ -59,8 +54,8 @@ public final class PathSubject extends Subject<PathSubject, Path> { protected LinkOption[] linkOptions = FOLLOW_LINKS; private Charset charset = UTF_8; - private PathSubject(FailureStrategy failureStrategy, Path subject) { - super(failureStrategy, subject); + private PathSubject(FailureMetadata failureMetadata, Path subject) { + super(failureMetadata, subject); } private Path toPath(String path) { @@ -79,7 +74,7 @@ public final class PathSubject extends Subject<PathSubject, Path> { */ // TODO(cgruber): Talk to cdecker about removing this as an anti-pattern. public PathSubject andThat(String path, LinkOption... linkOptions) { - PathSubject newSubject = new PathSubject(failureStrategy, toPath(path)); + PathSubject newSubject = check().about(paths()).that(toPath(path)); if (linkOptions.length != 0) { newSubject = newSubject.noFollowLinks(); } @@ -445,11 +440,11 @@ public final class PathSubject extends Subject<PathSubject, Path> { }; } - private static class PathSubjectFactory extends SubjectFactory<PathSubject, Path> { + private static class PathSubjectFactory implements Subject.Factory<PathSubject, Path> { @Override - public PathSubject getSubject(FailureStrategy fs, Path that) { - return new PathSubject(fs, that); + public PathSubject createSubject(FailureMetadata failureMetadata, Path that) { + return new PathSubject(failureMetadata, that); } } |