mirror of
https://github.com/google/nomulus.git
synced 2025-05-13 16:07:15 +02:00
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:
parent
6083ef9ba0
commit
9ab68613a0
12 changed files with 44 additions and 127 deletions
|
@ -15,7 +15,7 @@
|
||||||
package google.registry.testing;
|
package google.registry.testing;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.truth.FailureStrategy;
|
import com.google.common.truth.FailureMetadata;
|
||||||
import google.registry.model.domain.DomainBase;
|
import google.registry.model.domain.DomainBase;
|
||||||
import google.registry.model.domain.DomainResource;
|
import google.registry.model.domain.DomainResource;
|
||||||
import google.registry.model.domain.launch.LaunchNotice;
|
import google.registry.model.domain.launch.LaunchNotice;
|
||||||
|
@ -29,8 +29,8 @@ public abstract class AbstractDomainBaseSubject
|
||||||
<T extends DomainBase, S extends AbstractDomainBaseSubject<T, S>>
|
<T extends DomainBase, S extends AbstractDomainBaseSubject<T, S>>
|
||||||
extends AbstractEppResourceSubject<T, S> {
|
extends AbstractEppResourceSubject<T, S> {
|
||||||
|
|
||||||
public AbstractDomainBaseSubject(FailureStrategy strategy, T subject) {
|
public AbstractDomainBaseSubject(FailureMetadata failureMetadata, T subject) {
|
||||||
super(strategy, subject);
|
super(failureMetadata, subject);
|
||||||
}
|
}
|
||||||
|
|
||||||
public And<S> hasFullyQualifiedDomainName(String fullyQualifiedDomainName) {
|
public And<S> hasFullyQualifiedDomainName(String fullyQualifiedDomainName) {
|
||||||
|
|
|
@ -22,7 +22,7 @@ import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntr
|
||||||
import static google.registry.util.DiffUtils.prettyPrintEntityDeepDiff;
|
import static google.registry.util.DiffUtils.prettyPrintEntityDeepDiff;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.truth.FailureStrategy;
|
import com.google.common.truth.FailureMetadata;
|
||||||
import com.google.common.truth.Subject;
|
import com.google.common.truth.Subject;
|
||||||
import google.registry.model.EppResource;
|
import google.registry.model.EppResource;
|
||||||
import google.registry.model.ImmutableObject;
|
import google.registry.model.ImmutableObject;
|
||||||
|
@ -39,8 +39,8 @@ import org.joda.time.DateTime;
|
||||||
abstract class AbstractEppResourceSubject
|
abstract class AbstractEppResourceSubject
|
||||||
<T extends EppResource, S extends AbstractEppResourceSubject<T, S>> extends Subject<S, T> {
|
<T extends EppResource, S extends AbstractEppResourceSubject<T, S>> extends Subject<S, T> {
|
||||||
|
|
||||||
public AbstractEppResourceSubject(FailureStrategy strategy, T subject) {
|
public AbstractEppResourceSubject(FailureMetadata failureMetadata, T subject) {
|
||||||
super(strategy, checkNotNull(subject));
|
super(failureMetadata, checkNotNull(subject));
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<HistoryEntry> getHistoryEntries() {
|
private List<HistoryEntry> getHistoryEntries() {
|
||||||
|
|
|
@ -17,7 +17,7 @@ package google.registry.testing;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.common.truth.Truth.assertAbout;
|
import static com.google.common.truth.Truth.assertAbout;
|
||||||
|
|
||||||
import com.google.common.truth.FailureStrategy;
|
import com.google.common.truth.FailureMetadata;
|
||||||
import com.google.common.truth.SimpleSubjectBuilder;
|
import com.google.common.truth.SimpleSubjectBuilder;
|
||||||
import google.registry.model.contact.ContactResource;
|
import google.registry.model.contact.ContactResource;
|
||||||
import google.registry.model.contact.PostalInfo;
|
import google.registry.model.contact.PostalInfo;
|
||||||
|
@ -29,12 +29,8 @@ import org.joda.time.DateTime;
|
||||||
public final class ContactResourceSubject
|
public final class ContactResourceSubject
|
||||||
extends AbstractEppResourceSubject<ContactResource, ContactResourceSubject> {
|
extends AbstractEppResourceSubject<ContactResource, ContactResourceSubject> {
|
||||||
|
|
||||||
/** A factory for instances of this subject. */
|
public ContactResourceSubject(FailureMetadata failureMetadata, ContactResource subject) {
|
||||||
private static class SubjectFactory
|
super(failureMetadata, checkNotNull(subject));
|
||||||
extends ReflectiveSubjectFactory<ContactResource, ContactResourceSubject>{}
|
|
||||||
|
|
||||||
public ContactResourceSubject(FailureStrategy strategy, ContactResource subject) {
|
|
||||||
super(strategy, checkNotNull(subject));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public And<ContactResourceSubject> hasLocalizedPostalInfo(PostalInfo postalInfo) {
|
public And<ContactResourceSubject> hasLocalizedPostalInfo(PostalInfo postalInfo) {
|
||||||
|
@ -148,6 +144,6 @@ public final class ContactResourceSubject
|
||||||
|
|
||||||
public static SimpleSubjectBuilder<ContactResourceSubject, ContactResource>
|
public static SimpleSubjectBuilder<ContactResourceSubject, ContactResource>
|
||||||
assertAboutContacts() {
|
assertAboutContacts() {
|
||||||
return assertAbout(new SubjectFactory());
|
return assertAbout(ContactResourceSubject::new);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ import static com.google.common.truth.Truth.assertAbout;
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.truth.FailureStrategy;
|
import com.google.common.truth.FailureMetadata;
|
||||||
import com.google.common.truth.SimpleSubjectBuilder;
|
import com.google.common.truth.SimpleSubjectBuilder;
|
||||||
import google.registry.model.domain.DomainApplication;
|
import google.registry.model.domain.DomainApplication;
|
||||||
import google.registry.model.domain.Period;
|
import google.registry.model.domain.Period;
|
||||||
|
@ -76,16 +76,12 @@ public final class DomainApplicationSubject
|
||||||
return andChainer();
|
return andChainer();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A factory for instances of this subject. */
|
public DomainApplicationSubject(FailureMetadata failureMetadata, DomainApplication subject) {
|
||||||
private static class SubjectFactory
|
super(failureMetadata, checkNotNull(subject));
|
||||||
extends ReflectiveSubjectFactory<DomainApplication, DomainApplicationSubject>{}
|
|
||||||
|
|
||||||
public DomainApplicationSubject(FailureStrategy strategy, DomainApplication subject) {
|
|
||||||
super(strategy, checkNotNull(subject));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SimpleSubjectBuilder<DomainApplicationSubject, DomainApplication>
|
public static SimpleSubjectBuilder<DomainApplicationSubject, DomainApplication>
|
||||||
assertAboutApplications() {
|
assertAboutApplications() {
|
||||||
return assertAbout(new SubjectFactory());
|
return assertAbout(DomainApplicationSubject::new);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ package google.registry.testing;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.common.truth.Truth.assertAbout;
|
import static com.google.common.truth.Truth.assertAbout;
|
||||||
|
|
||||||
import com.google.common.truth.FailureStrategy;
|
import com.google.common.truth.FailureMetadata;
|
||||||
import com.google.common.truth.SimpleSubjectBuilder;
|
import com.google.common.truth.SimpleSubjectBuilder;
|
||||||
import google.registry.model.domain.DomainResource;
|
import google.registry.model.domain.DomainResource;
|
||||||
import google.registry.testing.TruthChainer.And;
|
import google.registry.testing.TruthChainer.And;
|
||||||
|
@ -28,10 +28,6 @@ import org.joda.time.DateTime;
|
||||||
public final class DomainResourceSubject
|
public final class DomainResourceSubject
|
||||||
extends AbstractDomainBaseSubject<DomainResource, DomainResourceSubject> {
|
extends AbstractDomainBaseSubject<DomainResource, DomainResourceSubject> {
|
||||||
|
|
||||||
/** A factory for instances of this subject. */
|
|
||||||
private static class SubjectFactory
|
|
||||||
extends ReflectiveSubjectFactory<DomainResource, DomainResourceSubject>{}
|
|
||||||
|
|
||||||
public And<DomainResourceSubject> hasRegistrationExpirationTime(DateTime expiration) {
|
public And<DomainResourceSubject> hasRegistrationExpirationTime(DateTime expiration) {
|
||||||
if (!Objects.equals(actual().getRegistrationExpirationTime(), expiration)) {
|
if (!Objects.equals(actual().getRegistrationExpirationTime(), expiration)) {
|
||||||
failWithBadResults(
|
failWithBadResults(
|
||||||
|
@ -74,11 +70,11 @@ public final class DomainResourceSubject
|
||||||
return hasValue(smdId, actual().getSmdId(), "has smdId");
|
return hasValue(smdId, actual().getSmdId(), "has smdId");
|
||||||
}
|
}
|
||||||
|
|
||||||
public DomainResourceSubject(FailureStrategy strategy, DomainResource subject) {
|
public DomainResourceSubject(FailureMetadata failureMetadata, DomainResource subject) {
|
||||||
super(strategy, checkNotNull(subject));
|
super(failureMetadata, checkNotNull(subject));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SimpleSubjectBuilder<DomainResourceSubject, DomainResource> assertAboutDomains() {
|
public static SimpleSubjectBuilder<DomainResourceSubject, DomainResource> assertAboutDomains() {
|
||||||
return assertAbout(new SubjectFactory());
|
return assertAbout(DomainResourceSubject::new);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,10 +18,9 @@ import static com.google.common.truth.Truth.assertAbout;
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static google.registry.flows.EppXmlTransformer.marshal;
|
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.SimpleSubjectBuilder;
|
||||||
import com.google.common.truth.Subject;
|
import com.google.common.truth.Subject;
|
||||||
import com.google.common.truth.SubjectFactory;
|
|
||||||
import google.registry.flows.EppException;
|
import google.registry.flows.EppException;
|
||||||
import google.registry.model.eppcommon.Trid;
|
import google.registry.model.eppcommon.Trid;
|
||||||
import google.registry.model.eppoutput.EppOutput;
|
import google.registry.model.eppoutput.EppOutput;
|
||||||
|
@ -33,8 +32,8 @@ import google.registry.xml.XmlException;
|
||||||
/** Utility methods for asserting things about {@link EppException} instances. */
|
/** Utility methods for asserting things about {@link EppException} instances. */
|
||||||
public class EppExceptionSubject extends Subject<EppExceptionSubject, EppException> {
|
public class EppExceptionSubject extends Subject<EppExceptionSubject, EppException> {
|
||||||
|
|
||||||
public EppExceptionSubject(FailureStrategy strategy, EppException subject) {
|
public EppExceptionSubject(FailureMetadata failureMetadata, EppException subject) {
|
||||||
super(strategy, subject);
|
super(failureMetadata, subject);
|
||||||
}
|
}
|
||||||
|
|
||||||
public And<EppExceptionSubject> hasMessage(String expected) {
|
public And<EppExceptionSubject> hasMessage(String expected) {
|
||||||
|
@ -58,10 +57,6 @@ public class EppExceptionSubject extends Subject<EppExceptionSubject, EppExcepti
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SimpleSubjectBuilder<EppExceptionSubject, EppException> assertAboutEppExceptions() {
|
public static SimpleSubjectBuilder<EppExceptionSubject, EppException> assertAboutEppExceptions() {
|
||||||
return assertAbout(new SubjectFactory<EppExceptionSubject, EppException>() {
|
return assertAbout(EppExceptionSubject::new);
|
||||||
@Override
|
|
||||||
public EppExceptionSubject getSubject(FailureStrategy strategy, EppException subject) {
|
|
||||||
return new EppExceptionSubject(strategy, subject);
|
|
||||||
}});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,21 +17,19 @@ package google.registry.testing;
|
||||||
import static com.google.common.truth.Truth.assertAbout;
|
import static com.google.common.truth.Truth.assertAbout;
|
||||||
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
|
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
|
||||||
|
|
||||||
import com.google.common.truth.FailureStrategy;
|
import com.google.common.truth.FailureMetadata;
|
||||||
import com.google.common.truth.Subject;
|
import com.google.common.truth.Subject;
|
||||||
import com.google.common.truth.SubjectFactory;
|
|
||||||
import google.registry.model.eppoutput.Result.Code;
|
import google.registry.model.eppoutput.Result.Code;
|
||||||
import google.registry.monitoring.whitebox.EppMetric;
|
import google.registry.monitoring.whitebox.EppMetric;
|
||||||
import google.registry.testing.TruthChainer.And;
|
import google.registry.testing.TruthChainer.And;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
/** Utility methods for asserting things about {@link EppMetric} instances. */
|
/** Utility methods for asserting things about {@link EppMetric} instances. */
|
||||||
public class EppMetricSubject extends Subject<EppMetricSubject, EppMetric> {
|
public class EppMetricSubject extends Subject<EppMetricSubject, EppMetric> {
|
||||||
|
|
||||||
public EppMetricSubject(FailureStrategy strategy, EppMetric subject) {
|
public EppMetricSubject(FailureMetadata failureMetadata, EppMetric subject) {
|
||||||
super(strategy, subject);
|
super(failureMetadata, subject);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EppMetricSubject assertThat(EppMetric subject) {
|
public static EppMetricSubject assertThat(EppMetric subject) {
|
||||||
|
@ -84,13 +82,7 @@ public class EppMetricSubject extends Subject<EppMetricSubject, EppMetric> {
|
||||||
return new And<>(this);
|
return new And<>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@link SubjectFactory} for assertions about {@link EppMetric} objects. */
|
/** {@link Subject.Factory} for assertions about {@link EppMetric} objects. */
|
||||||
private static final SubjectFactory<EppMetricSubject, EppMetric> SUBJECT_FACTORY =
|
private static final Subject.Factory<EppMetricSubject, EppMetric> SUBJECT_FACTORY =
|
||||||
new SubjectFactory<EppMetricSubject, EppMetric>() {
|
EppMetricSubject::new;
|
||||||
@Override
|
|
||||||
public EppMetricSubject getSubject(
|
|
||||||
FailureStrategy failureStrategy, @Nullable EppMetric target) {
|
|
||||||
return new EppMetricSubject(failureStrategy, target);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,30 +17,20 @@ package google.registry.testing;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.common.truth.Truth.assertAbout;
|
import static com.google.common.truth.Truth.assertAbout;
|
||||||
|
|
||||||
import com.google.common.truth.FailureStrategy;
|
import com.google.common.truth.FailureMetadata;
|
||||||
import com.google.common.truth.SimpleSubjectBuilder;
|
import com.google.common.truth.SimpleSubjectBuilder;
|
||||||
import com.google.common.truth.SubjectFactory;
|
|
||||||
import google.registry.model.EppResource;
|
import google.registry.model.EppResource;
|
||||||
|
|
||||||
/** Truth subject for asserting things about {@link EppResource} instances. */
|
/** Truth subject for asserting things about {@link EppResource} instances. */
|
||||||
public final class GenericEppResourceSubject
|
public final class GenericEppResourceSubject
|
||||||
extends AbstractEppResourceSubject<EppResource, GenericEppResourceSubject> {
|
extends AbstractEppResourceSubject<EppResource, GenericEppResourceSubject> {
|
||||||
|
|
||||||
/** A factory for instances of this subject. */
|
public GenericEppResourceSubject(FailureMetadata failureMetadata, EppResource subject) {
|
||||||
private static class GenericEppResourceSubjectFactory
|
super(failureMetadata, checkNotNull(subject));
|
||||||
extends SubjectFactory<GenericEppResourceSubject, EppResource> {
|
|
||||||
@Override
|
|
||||||
public GenericEppResourceSubject getSubject(FailureStrategy strategy, EppResource subject) {
|
|
||||||
return new GenericEppResourceSubject(strategy, subject);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public GenericEppResourceSubject(FailureStrategy strategy, EppResource subject) {
|
|
||||||
super(strategy, checkNotNull(subject));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SimpleSubjectBuilder<GenericEppResourceSubject, EppResource>
|
public static SimpleSubjectBuilder<GenericEppResourceSubject, EppResource>
|
||||||
assertAboutEppResources() {
|
assertAboutEppResources() {
|
||||||
return assertAbout(new GenericEppResourceSubjectFactory());
|
return assertAbout(GenericEppResourceSubject::new);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ package google.registry.testing;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertAbout;
|
import static com.google.common.truth.Truth.assertAbout;
|
||||||
|
|
||||||
import com.google.common.truth.FailureStrategy;
|
import com.google.common.truth.FailureMetadata;
|
||||||
import com.google.common.truth.SimpleSubjectBuilder;
|
import com.google.common.truth.SimpleSubjectBuilder;
|
||||||
import com.google.common.truth.Subject;
|
import com.google.common.truth.Subject;
|
||||||
import google.registry.model.domain.Period;
|
import google.registry.model.domain.Period;
|
||||||
|
@ -30,12 +30,8 @@ public class HistoryEntrySubject extends Subject<HistoryEntrySubject, HistoryEnt
|
||||||
|
|
||||||
private String customDisplaySubject;
|
private String customDisplaySubject;
|
||||||
|
|
||||||
/** A factory for instances of this subject. */
|
public HistoryEntrySubject(FailureMetadata failureMetadata, HistoryEntry subject) {
|
||||||
private static class SubjectFactory
|
super(failureMetadata, subject);
|
||||||
extends ReflectiveSubjectFactory<HistoryEntry, HistoryEntrySubject>{}
|
|
||||||
|
|
||||||
public HistoryEntrySubject(FailureStrategy strategy, HistoryEntry subject) {
|
|
||||||
super(strategy, subject);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -105,6 +101,6 @@ public class HistoryEntrySubject extends Subject<HistoryEntrySubject, HistoryEnt
|
||||||
|
|
||||||
public static SimpleSubjectBuilder<HistoryEntrySubject, HistoryEntry>
|
public static SimpleSubjectBuilder<HistoryEntrySubject, HistoryEntry>
|
||||||
assertAboutHistoryEntries() {
|
assertAboutHistoryEntries() {
|
||||||
return assertAbout(new SubjectFactory());
|
return assertAbout(HistoryEntrySubject::new);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ package google.registry.testing;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.common.truth.Truth.assertAbout;
|
import static com.google.common.truth.Truth.assertAbout;
|
||||||
|
|
||||||
import com.google.common.truth.FailureStrategy;
|
import com.google.common.truth.FailureMetadata;
|
||||||
import com.google.common.truth.SimpleSubjectBuilder;
|
import com.google.common.truth.SimpleSubjectBuilder;
|
||||||
import com.googlecode.objectify.Key;
|
import com.googlecode.objectify.Key;
|
||||||
import google.registry.model.domain.DomainResource;
|
import google.registry.model.domain.DomainResource;
|
||||||
|
@ -29,16 +29,12 @@ import org.joda.time.DateTime;
|
||||||
public final class HostResourceSubject
|
public final class HostResourceSubject
|
||||||
extends AbstractEppResourceSubject<HostResource, HostResourceSubject> {
|
extends AbstractEppResourceSubject<HostResource, HostResourceSubject> {
|
||||||
|
|
||||||
/** A factory for instances of this subject. */
|
public HostResourceSubject(FailureMetadata failureMetadata, HostResource subject) {
|
||||||
private static class SubjectFactory
|
super(failureMetadata, checkNotNull(subject));
|
||||||
extends ReflectiveSubjectFactory<HostResource, HostResourceSubject>{}
|
|
||||||
|
|
||||||
public HostResourceSubject(FailureStrategy strategy, HostResource subject) {
|
|
||||||
super(strategy, checkNotNull(subject));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SimpleSubjectBuilder<HostResourceSubject, HostResource> assertAboutHosts() {
|
public static SimpleSubjectBuilder<HostResourceSubject, HostResource> assertAboutHosts() {
|
||||||
return assertAbout(new SubjectFactory());
|
return assertAbout(HostResourceSubject::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
public And<HostResourceSubject> hasLastTransferTime(DateTime lastTransferTime) {
|
public And<HostResourceSubject> hasLastTransferTime(DateTime lastTransferTime) {
|
||||||
|
|
|
@ -20,7 +20,7 @@ import static com.google.common.truth.Truth.assertThat;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.testing.TestLogHandler;
|
import com.google.common.testing.TestLogHandler;
|
||||||
import com.google.common.truth.Correspondence;
|
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.SimpleSubjectBuilder;
|
||||||
import com.google.common.truth.StringSubject;
|
import com.google.common.truth.StringSubject;
|
||||||
import com.google.common.truth.Subject;
|
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. */
|
/** Utility methods for asserting things about logging {@link Handler} instances. */
|
||||||
public class LogsSubject extends Subject<LogsSubject, TestLogHandler> {
|
public class LogsSubject extends Subject<LogsSubject, TestLogHandler> {
|
||||||
|
|
||||||
/** A factory for instances of this subject. */
|
public LogsSubject(FailureMetadata failureMetadata, TestLogHandler subject) {
|
||||||
private static class SubjectFactory
|
super(failureMetadata, subject);
|
||||||
extends ReflectiveSubjectFactory<TestLogHandler, LogsSubject> {}
|
|
||||||
|
|
||||||
public LogsSubject(FailureStrategy strategy, TestLogHandler subject) {
|
|
||||||
super(strategy, subject);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Correspondence<String, String> CONTAINS_CORRESPONDENCE =
|
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() {
|
public static SimpleSubjectBuilder<LogsSubject, TestLogHandler> assertAboutLogs() {
|
||||||
return assertAbout(new SubjectFactory());
|
return assertAbout(LogsSubject::new);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package google.registry.testing;
|
|
||||||
|
|
||||||
import com.google.common.truth.FailureStrategy;
|
|
||||||
import com.google.common.truth.Subject;
|
|
||||||
import com.google.common.truth.SubjectFactory;
|
|
||||||
import google.registry.util.TypeUtils.TypeInstantiator;
|
|
||||||
|
|
||||||
/** Helper to reduce boilerplate in making new Truth subject classes. */
|
|
||||||
public class ReflectiveSubjectFactory<T, S extends Subject<S, T>> extends SubjectFactory<S, T> {
|
|
||||||
@Override
|
|
||||||
public S getSubject(FailureStrategy strategy, T subject) {
|
|
||||||
try {
|
|
||||||
Class<S> sType = new TypeInstantiator<S>(getClass()){}.getExactType();
|
|
||||||
return sType
|
|
||||||
.getConstructor(FailureStrategy.class, subject.getClass())
|
|
||||||
.newInstance(strategy, subject);
|
|
||||||
} catch (ReflectiveOperationException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue