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

@ -18,10 +18,9 @@ import static com.google.common.truth.Truth.assertAbout;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.flows.EppXmlTransformer.marshal;
import com.google.common.truth.FailureStrategy;
import com.google.common.truth.FailureMetadata;
import com.google.common.truth.SimpleSubjectBuilder;
import com.google.common.truth.Subject;
import com.google.common.truth.SubjectFactory;
import google.registry.flows.EppException;
import google.registry.model.eppcommon.Trid;
import google.registry.model.eppoutput.EppOutput;
@ -33,8 +32,8 @@ import google.registry.xml.XmlException;
/** Utility methods for asserting things about {@link EppException} instances. */
public class EppExceptionSubject extends Subject<EppExceptionSubject, EppException> {
public EppExceptionSubject(FailureStrategy strategy, EppException subject) {
super(strategy, subject);
public EppExceptionSubject(FailureMetadata failureMetadata, EppException subject) {
super(failureMetadata, subject);
}
public And<EppExceptionSubject> hasMessage(String expected) {
@ -58,10 +57,6 @@ public class EppExceptionSubject extends Subject<EppExceptionSubject, EppExcepti
}
public static SimpleSubjectBuilder<EppExceptionSubject, EppException> assertAboutEppExceptions() {
return assertAbout(new SubjectFactory<EppExceptionSubject, EppException>() {
@Override
public EppExceptionSubject getSubject(FailureStrategy strategy, EppException subject) {
return new EppExceptionSubject(strategy, subject);
}});
return assertAbout(EppExceptionSubject::new);
}
}