Manually migrate some ExceptionRules to Junit 4.13 style asserts

These testing helper functions can't be handled by the automatic refactoring
tool because they're taking in expected exception details as parameters.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=178832406
This commit is contained in:
mcilwain 2017-12-12 16:21:26 -08:00 committed by jianglai
parent c2ed7429d3
commit 52ce49a02c
12 changed files with 60 additions and 56 deletions

View file

@ -14,6 +14,7 @@
package google.registry.flows.contact; package google.registry.flows.contact;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.ContactResourceSubject.assertAboutContacts; import static google.registry.testing.ContactResourceSubject.assertAboutContacts;
import static google.registry.testing.DatastoreHelper.assertNoBillingEvents; import static google.registry.testing.DatastoreHelper.assertNoBillingEvents;
import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.createTld;
@ -22,6 +23,7 @@ import static google.registry.testing.DatastoreHelper.newDomainResource;
import static google.registry.testing.DatastoreHelper.persistActiveContact; import static google.registry.testing.DatastoreHelper.persistActiveContact;
import static google.registry.testing.DatastoreHelper.persistDeletedContact; import static google.registry.testing.DatastoreHelper.persistDeletedContact;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.expectThrows;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import google.registry.flows.ResourceFlowTestCase; import google.registry.flows.ResourceFlowTestCase;
@ -82,17 +84,6 @@ public class ContactDeleteFlowTest
runFlow(); runFlow();
} }
private void doFailingStatusTest(StatusValue statusValue, Class<? extends Exception> exception)
throws Exception {
persistResource(
newContactResource(getUniqueIdFromCommand()).asBuilder()
.setStatusValues(ImmutableSet.of(statusValue))
.build());
thrown.expect(exception);
thrown.expectMessage(statusValue.getXmlName());
runFlow();
}
@Test @Test
public void testFailure_existedButWasClientDeleteProhibited() throws Exception { public void testFailure_existedButWasClientDeleteProhibited() throws Exception {
doFailingStatusTest( doFailingStatusTest(
@ -111,6 +102,16 @@ public class ContactDeleteFlowTest
StatusValue.PENDING_DELETE, ResourceStatusProhibitsOperationException.class); StatusValue.PENDING_DELETE, ResourceStatusProhibitsOperationException.class);
} }
private void doFailingStatusTest(StatusValue statusValue, Class<? extends Exception> exception)
throws Exception {
persistResource(
newContactResource(getUniqueIdFromCommand()).asBuilder()
.setStatusValues(ImmutableSet.of(statusValue))
.build());
Exception e = expectThrows(exception, this::runFlow);
assertThat(e).hasMessageThat().contains(statusValue.getXmlName());
}
@Test @Test
public void testFailure_unauthorizedClient() throws Exception { public void testFailure_unauthorizedClient() throws Exception {
sessionMetadata.setClientId("NewRegistrar"); sessionMetadata.setClientId("NewRegistrar");

View file

@ -33,6 +33,7 @@ import static google.registry.testing.DatastoreHelper.persistReservedList;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.DomainApplicationSubject.assertAboutApplications; import static google.registry.testing.DomainApplicationSubject.assertAboutApplications;
import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions; import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.util.DateTimeUtils.START_OF_TIME; import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static java.util.Comparator.comparing; import static java.util.Comparator.comparing;
import static org.joda.money.CurrencyUnit.EUR; import static org.joda.money.CurrencyUnit.EUR;
@ -1736,8 +1737,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrise_signed_mark_uppercase.xml"); setEppInput("domain_create_sunrise_signed_mark_uppercase.xml");
eppLoader.replaceAll("TEST-VALIDATE.tld", domainName); eppLoader.replaceAll("TEST-VALIDATE.tld", domainName);
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(exception); assertThrows(exception, this::runFlow);
runFlow();
} }
@Test @Test

View file

@ -28,6 +28,7 @@ import static google.registry.testing.DatastoreHelper.persistActiveHost;
import static google.registry.testing.DatastoreHelper.persistReservedList; import static google.registry.testing.DatastoreHelper.persistReservedList;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.DomainApplicationSubject.assertAboutApplications; import static google.registry.testing.DomainApplicationSubject.assertAboutApplications;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.util.DateTimeUtils.START_OF_TIME; import static google.registry.util.DateTimeUtils.START_OF_TIME;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
@ -333,8 +334,7 @@ public class DomainApplicationUpdateFlowTest
setEppInput(xmlFilename); setEppInput(xmlFilename);
persistReferencedEntities(); persistReferencedEntities();
persistNewApplication(); persistNewApplication();
thrown.expect(expectedException); assertThrows(expectedException, this::runFlow);
runFlow();
} }
@Test @Test

View file

@ -24,6 +24,7 @@ import static google.registry.testing.DatastoreHelper.persistDeletedDomain;
import static google.registry.testing.DatastoreHelper.persistPremiumList; import static google.registry.testing.DatastoreHelper.persistPremiumList;
import static google.registry.testing.DatastoreHelper.persistReservedList; import static google.registry.testing.DatastoreHelper.persistReservedList;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.util.DateTimeUtils.START_OF_TIME; import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static org.joda.money.CurrencyUnit.USD; import static org.joda.money.CurrencyUnit.USD;
@ -304,8 +305,7 @@ public class DomainCheckFlowTest
private void doFailingBadLabelTest(String label, Class<? extends Exception> expectedException) private void doFailingBadLabelTest(String label, Class<? extends Exception> expectedException)
throws Exception { throws Exception {
setEppInput("domain_check_template.xml", ImmutableMap.of("LABEL", label)); setEppInput("domain_check_template.xml", ImmutableMap.of("LABEL", label));
thrown.expect(expectedException); assertThrows(expectedException, this::runFlow);
runFlow();
} }
@Test @Test

View file

@ -43,6 +43,7 @@ import static google.registry.testing.DatastoreHelper.persistReservedList;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.DomainResourceSubject.assertAboutDomains; import static google.registry.testing.DomainResourceSubject.assertAboutDomains;
import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions; import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows; import static google.registry.testing.JUnitBackports.expectThrows;
import static google.registry.testing.TaskQueueHelper.assertDnsTasksEnqueued; import static google.registry.testing.TaskQueueHelper.assertDnsTasksEnqueued;
import static google.registry.testing.TaskQueueHelper.assertNoDnsTasksEnqueued; import static google.registry.testing.TaskQueueHelper.assertNoDnsTasksEnqueued;
@ -637,9 +638,8 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
.build()); .build());
setEppInput("domain_create_lrp.xml"); setEppInput("domain_create_lrp.xml");
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(InvalidLrpTokenException.class); Exception e = expectThrows(InvalidLrpTokenException.class, this::runFlow);
thrown.expectMessage("Invalid limited registration period token"); assertThat(e).hasMessageThat().isEqualTo("Invalid limited registration period token");
runFlow();
assertThat(ofy().load().entity(token).now().getRedemptionHistoryEntry()).isNull(); assertThat(ofy().load().entity(token).now().getRedemptionHistoryEntry()).isNull();
} }
@ -1460,8 +1460,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
setEppInput("domain_create_uppercase.xml"); setEppInput("domain_create_uppercase.xml");
eppLoader.replaceAll("Example.tld", domainName); eppLoader.replaceAll("Example.tld", domainName);
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(exception); assertThrows(exception, this::runFlow);
runFlow();
} }
@Test @Test
@ -1649,10 +1648,10 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
@Test @Test
public void testFailure_landrushRegistration() throws Exception { public void testFailure_landrushRegistration() throws Exception {
thrown.expect(NoGeneralRegistrationsInCurrentPhaseException.class);
createTld("tld", TldState.LANDRUSH); createTld("tld", TldState.LANDRUSH);
setEppInput("domain_create_registration_landrush.xml"); setEppInput("domain_create_registration_landrush.xml");
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(NoGeneralRegistrationsInCurrentPhaseException.class);
runFlow(); runFlow();
} }

View file

@ -35,6 +35,7 @@ import static google.registry.testing.DatastoreHelper.persistReservedList;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.DomainResourceSubject.assertAboutDomains; import static google.registry.testing.DomainResourceSubject.assertAboutDomains;
import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries; import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows; import static google.registry.testing.JUnitBackports.expectThrows;
import static google.registry.testing.TaskQueueHelper.assertDnsTasksEnqueued; import static google.registry.testing.TaskQueueHelper.assertDnsTasksEnqueued;
import static org.joda.money.CurrencyUnit.USD; import static org.joda.money.CurrencyUnit.USD;
@ -754,8 +755,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
setEppInput(xmlFilename); setEppInput(xmlFilename);
persistReferencedEntities(); persistReferencedEntities();
persistActiveDomain(getUniqueIdFromCommand()); persistActiveDomain(getUniqueIdFromCommand());
thrown.expect(expectedException); assertThrows(expectedException, this::runFlow);
runFlow();
} }
@Test @Test

View file

@ -25,6 +25,7 @@ import static google.registry.testing.DatastoreHelper.persistActiveHost;
import static google.registry.testing.DatastoreHelper.persistDeletedHost; import static google.registry.testing.DatastoreHelper.persistDeletedHost;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.HostResourceSubject.assertAboutHosts; import static google.registry.testing.HostResourceSubject.assertAboutHosts;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.TaskQueueHelper.assertDnsTasksEnqueued; import static google.registry.testing.TaskQueueHelper.assertDnsTasksEnqueued;
import static google.registry.testing.TaskQueueHelper.assertNoDnsTasksEnqueued; import static google.registry.testing.TaskQueueHelper.assertNoDnsTasksEnqueued;
@ -240,12 +241,10 @@ public class HostCreateFlowTest extends ResourceFlowTestCase<HostCreateFlow, Hos
runFlow(); runFlow();
} }
private void doFailingHostNameTest( private void doFailingHostNameTest(String hostName, Class<? extends Throwable> exception)
String hostName, throws Exception {
Class<? extends Throwable> exception) throws Exception {
setEppHostCreateInputWithIps(hostName); setEppHostCreateInputWithIps(hostName);
thrown.expect(exception); assertThrows(exception, this::runFlow);
runFlow();
} }
@Test @Test

View file

@ -14,6 +14,7 @@
package google.registry.flows.host; package google.registry.flows.host;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.DatastoreHelper.assertNoBillingEvents; import static google.registry.testing.DatastoreHelper.assertNoBillingEvents;
import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.newDomainApplication; import static google.registry.testing.DatastoreHelper.newDomainApplication;
@ -23,6 +24,7 @@ import static google.registry.testing.DatastoreHelper.persistActiveHost;
import static google.registry.testing.DatastoreHelper.persistDeletedHost; import static google.registry.testing.DatastoreHelper.persistDeletedHost;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.HostResourceSubject.assertAboutHosts; import static google.registry.testing.HostResourceSubject.assertAboutHosts;
import static google.registry.testing.JUnitBackports.expectThrows;
import static google.registry.testing.TaskQueueHelper.assertNoDnsTasksEnqueued; import static google.registry.testing.TaskQueueHelper.assertNoDnsTasksEnqueued;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
@ -97,12 +99,12 @@ public class HostDeleteFlowTest extends ResourceFlowTestCase<HostDeleteFlow, Hos
private void doFailingStatusTest(StatusValue statusValue, Class<? extends Exception> exception) private void doFailingStatusTest(StatusValue statusValue, Class<? extends Exception> exception)
throws Exception { throws Exception {
persistResource( persistResource(
newHostResource("ns1.example.tld").asBuilder() newHostResource("ns1.example.tld")
.asBuilder()
.setStatusValues(ImmutableSet.of(statusValue)) .setStatusValues(ImmutableSet.of(statusValue))
.build()); .build());
thrown.expect(exception); Exception e = expectThrows(exception, this::runFlow);
thrown.expectMessage(statusValue.getXmlName()); assertThat(e).hasMessageThat().contains(statusValue.getXmlName());
runFlow();
} }
@Test @Test

View file

@ -33,6 +33,8 @@ import static google.registry.testing.DomainResourceSubject.assertAboutDomains;
import static google.registry.testing.GenericEppResourceSubject.assertAboutEppResources; import static google.registry.testing.GenericEppResourceSubject.assertAboutEppResources;
import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries; import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries;
import static google.registry.testing.HostResourceSubject.assertAboutHosts; import static google.registry.testing.HostResourceSubject.assertAboutHosts;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows;
import static google.registry.testing.TaskQueueHelper.assertDnsTasksEnqueued; import static google.registry.testing.TaskQueueHelper.assertDnsTasksEnqueued;
import static google.registry.testing.TaskQueueHelper.assertNoDnsTasksEnqueued; import static google.registry.testing.TaskQueueHelper.assertNoDnsTasksEnqueued;
import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued; import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued;
@ -371,8 +373,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
DomainResource domain = persistActiveDomain("example.tld"); DomainResource domain = persistActiveDomain("example.tld");
persistActiveHost(oldHostName()); persistActiveHost(oldHostName());
assertThat(domain.getSubordinateHosts()).isEmpty(); assertThat(domain.getSubordinateHosts()).isEmpty();
thrown.expect(CannotRenameExternalHostException.class); expectThrows(CannotRenameExternalHostException.class, this::runFlow);
runFlow();
assertNoDnsTasksEnqueued(); assertNoDnsTasksEnqueued();
} }
@ -1183,8 +1184,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
hostName, hostName,
"<host:addr ip=\"v4\">192.0.2.22</host:addr>", "<host:addr ip=\"v4\">192.0.2.22</host:addr>",
"<host:addr ip=\"v6\">1080:0:0:0:8:800:200C:417A</host:addr>"); "<host:addr ip=\"v6\">1080:0:0:0:8:800:200C:417A</host:addr>");
thrown.expect(exception); assertThrows(exception, this::runFlow);
runFlow();
} }
@Test @Test

View file

@ -17,6 +17,7 @@ package google.registry.flows.session;
import static google.registry.testing.DatastoreHelper.deleteResource; import static google.registry.testing.DatastoreHelper.deleteResource;
import static google.registry.testing.DatastoreHelper.loadRegistrar; import static google.registry.testing.DatastoreHelper.loadRegistrar;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows;
import google.registry.flows.EppException.UnimplementedExtensionException; import google.registry.flows.EppException.UnimplementedExtensionException;
import google.registry.flows.EppException.UnimplementedObjectServiceException; import google.registry.flows.EppException.UnimplementedObjectServiceException;
@ -60,11 +61,9 @@ public abstract class LoginFlowTestCase extends FlowTestCase<LoginFlow> {
} }
// Also called in subclasses. // Also called in subclasses.
void doFailingTest(String xmlFilename, Class<? extends Exception> exception) void doFailingTest(String xmlFilename, Class<? extends Exception> exception) throws Exception {
throws Exception {
setEppInput(xmlFilename); setEppInput(xmlFilename);
thrown.expect(exception); assertThrows(exception, this::runFlow);
runFlow();
} }
@Test @Test

View file

@ -617,13 +617,16 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
private void runFailureReservedListsTest( private void runFailureReservedListsTest(
String reservedLists, Class<? extends Exception> errorClass, String errorMsg) String reservedLists, Class<? extends Exception> errorClass, String errorMsg)
throws Exception { throws Exception {
thrown.expect(errorClass); Exception e =
thrown.expectMessage(errorMsg); expectThrows(
errorClass,
() ->
runCommandForced( runCommandForced(
"--reserved_lists", "--reserved_lists",
reservedLists, reservedLists,
"--roid_suffix=Q9JYB4C", "--roid_suffix=Q9JYB4C",
"--dns_writers=VoidDnsWriter", "--dns_writers=VoidDnsWriter",
"xn--q9jyb4c"); "xn--q9jyb4c"));
assertThat(e).hasMessageThat().isEqualTo(errorMsg);
} }
} }

View file

@ -21,6 +21,7 @@ import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.persistPremiumList; import static google.registry.testing.DatastoreHelper.persistPremiumList;
import static google.registry.testing.DatastoreHelper.persistReservedList; import static google.registry.testing.DatastoreHelper.persistReservedList;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.expectThrows;
import static google.registry.util.DateTimeUtils.END_OF_TIME; import static google.registry.util.DateTimeUtils.END_OF_TIME;
import static google.registry.util.DateTimeUtils.START_OF_TIME; import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static org.joda.money.CurrencyUnit.JPY; import static org.joda.money.CurrencyUnit.JPY;
@ -934,11 +935,11 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
} }
private void runFailureReservedListsTest( private void runFailureReservedListsTest(
String reservedLists, String reservedLists, Class<? extends Exception> errorClass, String errorMsg)
Class<? extends Exception> errorClass, throws Exception {
String errorMsg) throws Exception { Exception e =
thrown.expect(errorClass); expectThrows(
thrown.expectMessage(errorMsg); errorClass, () -> runCommandForced("--reserved_lists", reservedLists, "xn--q9jyb4c"));
runCommandForced("--reserved_lists", reservedLists, "xn--q9jyb4c"); assertThat(e).hasMessageThat().isEqualTo(errorMsg);
} }
} }