Migrate users from the old, deprecated Subject.fail* methods to the new Subject.fail* methods or, in some cases, to Subject.check.

Most of the changes in this CL were made manually.

I've tried to preserve all information (and of course behavior!), but the format and grammar of the messages does change. For example before-and-after messages, see the LSC doc.

In some of the CLs in this round (e.g., jscomp), I don't know a lot about the domain being tested, and the assertions are complex, so please let me know if my new phrasing is wrong or confusing.

Thanks again for your patience with all the Truth changes lately.

END_PUBLIC

More information:
  []

Tested:
    TAP for global presubmit queue
    []

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=248543745
This commit is contained in:
cpovirk 2019-05-16 09:41:11 -07:00 committed by jianglai
parent 210c08cbb9
commit 37f1734ee2
5 changed files with 43 additions and 86 deletions

View file

@ -23,7 +23,6 @@ import com.google.common.truth.Subject;
import google.registry.model.domain.Period;
import google.registry.model.reporting.HistoryEntry;
import google.registry.testing.TruthChainer.And;
import java.util.Objects;
import java.util.Optional;
import org.joda.time.DateTime;
@ -49,23 +48,23 @@ public class HistoryEntrySubject extends Subject<HistoryEntrySubject, HistoryEnt
}
public And<HistoryEntrySubject> hasType(HistoryEntry.Type type) {
return hasValue(type, actual.getType(), "has type");
return hasValue(type, actual.getType(), "getType()");
}
public And<HistoryEntrySubject> hasClientId(String clientId) {
return hasValue(clientId, actual.getClientId(), "has client ID");
return hasValue(clientId, actual.getClientId(), "getClientId()");
}
public And<HistoryEntrySubject> hasOtherClientId(String otherClientId) {
return hasValue(otherClientId, actual.getOtherClientId(), "has other client ID");
return hasValue(otherClientId, actual.getOtherClientId(), "getOtherClientId()");
}
public And<HistoryEntrySubject> hasModificationTime(DateTime modificationTime) {
return hasValue(modificationTime, actual.getModificationTime(), "has modification time");
return hasValue(modificationTime, actual.getModificationTime(), "getModificationTime()");
}
public And<HistoryEntrySubject> bySuperuser(boolean superuser) {
return hasValue(superuser, actual.getBySuperuser(), "has modification time");
return hasValue(superuser, actual.getBySuperuser(), "getBySuperuser()");
}
public And<HistoryEntrySubject> hasPeriod() {
@ -78,9 +77,9 @@ public class HistoryEntrySubject extends Subject<HistoryEntrySubject, HistoryEnt
public And<HistoryEntrySubject> hasPeriodYears(int years) {
return hasPeriod()
.and()
.hasValue(Period.Unit.YEARS, actual.getPeriod().getUnit(), "has period in")
.hasValue(Period.Unit.YEARS, actual.getPeriod().getUnit(), "getPeriod().getUnit()")
.and()
.hasValue(years, actual.getPeriod().getValue(), "has period length");
.hasValue(years, actual.getPeriod().getValue(), "getPeriod().getValue()");
}
public And<HistoryEntrySubject> hasNoXml() {
@ -91,26 +90,17 @@ public class HistoryEntrySubject extends Subject<HistoryEntrySubject, HistoryEnt
}
public And<HistoryEntrySubject> hasMetadataReason(String reason) {
return hasValue(reason, actual.getReason(), "has metadata reason");
return hasValue(reason, actual.getReason(), "getReason()");
}
public And<HistoryEntrySubject> hasMetadataRequestedByRegistrar(
boolean requestedByRegistrar) {
if (actual.getRequestedByRegistrar() != requestedByRegistrar) {
failWithActual(
"expected to have metadata requestedByRegistrar with value", requestedByRegistrar);
}
return new And<>(this);
return hasValue(
requestedByRegistrar, actual.getRequestedByRegistrar(), "getRequestedByRegistrar()");
}
protected void failWithBadResults(String dualVerb, Object expected, Object actual) {
failWithBadResults(dualVerb, expected, dualVerb, actual);
}
protected <E> And<HistoryEntrySubject> hasValue(E expected, E actual, String verb) {
if (!Objects.equals(expected, actual)) {
failWithBadResults(verb, expected, actual);
}
protected <E> And<HistoryEntrySubject> hasValue(E expected, E actual, String name) {
check(name).that(actual).isEqualTo(expected);
return new And<>(this);
}