Replace FailureStrategy with FailureMetadata in gtld's 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 []

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=176110788
This commit is contained in:
jianglai 2017-11-17 08:18:43 -08:00
parent 6083ef9ba0
commit 9ab68613a0
12 changed files with 44 additions and 127 deletions

View file

@ -20,7 +20,7 @@ import static com.google.common.truth.Truth.assertThat;
import com.google.common.collect.ImmutableList;
import com.google.common.testing.TestLogHandler;
import com.google.common.truth.Correspondence;
import com.google.common.truth.FailureStrategy;
import com.google.common.truth.FailureMetadata;
import com.google.common.truth.SimpleSubjectBuilder;
import com.google.common.truth.StringSubject;
import com.google.common.truth.Subject;
@ -33,12 +33,8 @@ import java.util.logging.LogRecord;
/** Utility methods for asserting things about logging {@link Handler} instances. */
public class LogsSubject extends Subject<LogsSubject, TestLogHandler> {
/** A factory for instances of this subject. */
private static class SubjectFactory
extends ReflectiveSubjectFactory<TestLogHandler, LogsSubject> {}
public LogsSubject(FailureStrategy strategy, TestLogHandler subject) {
super(strategy, subject);
public LogsSubject(FailureMetadata failureMetadata, TestLogHandler subject) {
super(failureMetadata, subject);
}
private static final Correspondence<String, String> CONTAINS_CORRESPONDENCE =
@ -88,6 +84,6 @@ public class LogsSubject extends Subject<LogsSubject, TestLogHandler> {
}
public static SimpleSubjectBuilder<LogsSubject, TestLogHandler> assertAboutLogs() {
return assertAbout(new SubjectFactory());
return assertAbout(LogsSubject::new);
}
}