Use new Truth failWithActual() method

Migrate Truth subjects from the old fail(String, Object) to the new failWithActual(String, Object), tweaking verbs for the new grammar.

Before:
  fail("has foo", expected);

After:
  failWithActual("expected to have foo", expected);

Open-source note: The fail*() methods used by this CL were added in Truth 0.41.

More information:
  []
Tested:
    TAP --sample for global presubmit queue
    []

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=244418884
This commit is contained in:
cpovirk 2019-04-19 14:05:12 -07:00 committed by jianglai
parent 24bb78bd16
commit a46227b201
5 changed files with 25 additions and 20 deletions

View file

@ -80,7 +80,7 @@ abstract class AbstractEppResourceSubject
public And<S> hasNoHistoryEntries() {
if (!getHistoryEntries().isEmpty()) {
fail("has no history entries");
failWithActual(simpleFact("expected to have no history entries"));
}
return andChainer();
}

View file

@ -15,6 +15,7 @@
package google.registry.testing;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.truth.Fact.simpleFact;
import static com.google.common.truth.Truth.assertAbout;
import com.google.common.truth.FailureMetadata;
@ -39,14 +40,14 @@ public final class ContactResourceSubject
public And<ContactResourceSubject> hasNullLocalizedPostalInfo() {
if (actual().getLocalizedPostalInfo() != null) {
fail("has null localized postal info");
failWithActual(simpleFact("expected to have null localized postal info"));
}
return andChainer();
}
public And<ContactResourceSubject> hasNonNullLocalizedPostalInfo() {
if (actual().getLocalizedPostalInfo() == null) {
fail("has non-null localized postal info");
failWithActual(simpleFact("expected to have non-null localized postal info"));
}
return andChainer();
}
@ -61,7 +62,7 @@ public final class ContactResourceSubject
public And<ContactResourceSubject> hasNullInternationalizedPostalInfo() {
if (actual().getInternationalizedPostalInfo() != null) {
fail("has null internationalized postal info");
failWithActual(simpleFact("expected to have null internationalized postal info"));
}
return andChainer();
}
@ -69,49 +70,49 @@ public final class ContactResourceSubject
public And<ContactResourceSubject> hasNonNullInternationalizedPostalInfo() {
if (actual().getInternationalizedPostalInfo() == null) {
fail("has non-null internationalized postal info");
failWithActual(simpleFact("expected to have non-null internationalized postal info"));
}
return andChainer();
}
public And<ContactResourceSubject> hasNullEmailAddress() {
if (actual().getEmailAddress() != null) {
fail("has null email address");
failWithActual(simpleFact("expected to have null email address"));
}
return andChainer();
}
public And<ContactResourceSubject> hasNonNullEmailAddress() {
if (actual().getEmailAddress() == null) {
fail("has non-null email address");
failWithActual(simpleFact("expected to have non-null email address"));
}
return andChainer();
}
public And<ContactResourceSubject> hasNullVoiceNumber() {
if (actual().getVoiceNumber() != null) {
fail("has null voice number");
failWithActual(simpleFact("expected to have null voice number"));
}
return andChainer();
}
public And<ContactResourceSubject> hasNonNullVoiceNumber() {
if (actual().getVoiceNumber() == null) {
fail("has non-null voice number");
failWithActual(simpleFact("expected to have non-null voice number"));
}
return andChainer();
}
public And<ContactResourceSubject> hasNullFaxNumber() {
if (actual().getFaxNumber() != null) {
fail("has null fax number");
failWithActual(simpleFact("expected to have null fax number"));
}
return andChainer();
}
public And<ContactResourceSubject> hasNonNullFaxNumber() {
if (actual().getFaxNumber() == null) {
fail("has non-null fax number");
failWithActual(simpleFact("expected to have non-null fax number"));
}
return andChainer();
}

View file

@ -15,6 +15,7 @@
package google.registry.testing;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.truth.Fact.simpleFact;
import static com.google.common.truth.Truth.assertAbout;
import com.google.common.truth.FailureMetadata;
@ -54,14 +55,14 @@ public final class DomainBaseSubject
public And<DomainBaseSubject> hasDeletePollMessage() {
if (actual().getDeletePollMessage() == null) {
fail("has a delete poll message");
failWithActual(simpleFact("expected to have a delete poll message"));
}
return andChainer();
}
public And<DomainBaseSubject> hasNoDeletePollMessage() {
if (actual().getDeletePollMessage() != null) {
fail("has no delete poll message");
failWithActual(simpleFact("expected to have no delete poll message"));
}
return andChainer();
}

View file

@ -14,6 +14,7 @@
package google.registry.testing;
import static com.google.common.truth.Fact.simpleFact;
import static com.google.common.truth.Truth.assertAbout;
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
@ -50,7 +51,7 @@ public class EppMetricSubject extends Subject<EppMetricSubject, EppMetric> {
public And<EppMetricSubject> hasNoStatus() {
if (actual().getStatus().isPresent()) {
fail("has no status");
failWithActual(simpleFact("expected to have no status"));
}
return new And<>(this);
}
@ -61,7 +62,7 @@ public class EppMetricSubject extends Subject<EppMetricSubject, EppMetric> {
public And<EppMetricSubject> hasNoTld() {
if (actual().getTld().isPresent()) {
fail("has no tld");
failWithActual(simpleFact("expected to have no tld"));
}
return new And<>(this);
}
@ -69,9 +70,9 @@ public class EppMetricSubject extends Subject<EppMetricSubject, EppMetric> {
private <E> And<EppMetricSubject> hasValue(E expected, Optional<E> actual, String verb) {
checkArgumentNotNull(expected, "Expected value cannot be null");
if (actual == null) {
fail("is non-null", expected);
failWithActual("expected to be non-null", expected);
} else if (!actual.isPresent()) {
fail("has value", expected);
failWithActual("expected to have value", expected);
} else if (!Objects.equals(expected, actual.get())) {
failWithBadResults(verb, expected, verb, actual);
}

View file

@ -14,6 +14,7 @@
package google.registry.testing;
import static com.google.common.truth.Fact.simpleFact;
import static com.google.common.truth.Truth.assertAbout;
import com.google.common.truth.FailureMetadata;
@ -67,7 +68,7 @@ public class HistoryEntrySubject extends Subject<HistoryEntrySubject, HistoryEnt
public And<HistoryEntrySubject> hasPeriod() {
if (actual().getPeriod() == null) {
fail("has a period");
failWithActual(simpleFact("expected to have a period"));
}
return new And<>(this);
}
@ -80,7 +81,7 @@ public class HistoryEntrySubject extends Subject<HistoryEntrySubject, HistoryEnt
public And<HistoryEntrySubject> hasNoXml() {
if (actual().getXmlBytes() != null) {
fail("has no xml");
failWithActual(simpleFact("expected to have no xml"));
}
return new And<>(this);
}
@ -92,7 +93,8 @@ public class HistoryEntrySubject extends Subject<HistoryEntrySubject, HistoryEnt
public And<HistoryEntrySubject> hasMetadataRequestedByRegistrar(
boolean requestedByRegistrar) {
if (actual().getRequestedByRegistrar() != requestedByRegistrar) {
fail("has metadata requestedByRegistrar with value", requestedByRegistrar);
failWithActual(
"expected to have metadata requestedByRegistrar with value", requestedByRegistrar);
}
return new And<>(this);
}