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;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.ContactResourceSubject.assertAboutContacts;
import static google.registry.testing.DatastoreHelper.assertNoBillingEvents;
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.persistDeletedContact;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.expectThrows;
import com.google.common.collect.ImmutableSet;
import google.registry.flows.ResourceFlowTestCase;
@ -82,17 +84,6 @@ public class ContactDeleteFlowTest
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
public void testFailure_existedButWasClientDeleteProhibited() throws Exception {
doFailingStatusTest(
@ -111,6 +102,16 @@ public class ContactDeleteFlowTest
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
public void testFailure_unauthorizedClient() throws Exception {
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.DomainApplicationSubject.assertAboutApplications;
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 java.util.Comparator.comparing;
import static org.joda.money.CurrencyUnit.EUR;
@ -1736,8 +1737,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrise_signed_mark_uppercase.xml");
eppLoader.replaceAll("TEST-VALIDATE.tld", domainName);
persistContactsAndHosts();
thrown.expect(exception);
runFlow();
assertThrows(exception, this::runFlow);
}
@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.persistResource;
import static google.registry.testing.DomainApplicationSubject.assertAboutApplications;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
import com.google.common.collect.ImmutableMap;
@ -333,8 +334,7 @@ public class DomainApplicationUpdateFlowTest
setEppInput(xmlFilename);
persistReferencedEntities();
persistNewApplication();
thrown.expect(expectedException);
runFlow();
assertThrows(expectedException, this::runFlow);
}
@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.persistReservedList;
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 org.joda.money.CurrencyUnit.USD;
@ -304,8 +305,7 @@ public class DomainCheckFlowTest
private void doFailingBadLabelTest(String label, Class<? extends Exception> expectedException)
throws Exception {
setEppInput("domain_check_template.xml", ImmutableMap.of("LABEL", label));
thrown.expect(expectedException);
runFlow();
assertThrows(expectedException, this::runFlow);
}
@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.DomainResourceSubject.assertAboutDomains;
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.TaskQueueHelper.assertDnsTasksEnqueued;
import static google.registry.testing.TaskQueueHelper.assertNoDnsTasksEnqueued;
@ -637,9 +638,8 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
.build());
setEppInput("domain_create_lrp.xml");
persistContactsAndHosts();
thrown.expect(InvalidLrpTokenException.class);
thrown.expectMessage("Invalid limited registration period token");
runFlow();
Exception e = expectThrows(InvalidLrpTokenException.class, this::runFlow);
assertThat(e).hasMessageThat().isEqualTo("Invalid limited registration period token");
assertThat(ofy().load().entity(token).now().getRedemptionHistoryEntry()).isNull();
}
@ -1460,8 +1460,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
setEppInput("domain_create_uppercase.xml");
eppLoader.replaceAll("Example.tld", domainName);
persistContactsAndHosts();
thrown.expect(exception);
runFlow();
assertThrows(exception, this::runFlow);
}
@Test
@ -1649,10 +1648,10 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
@Test
public void testFailure_landrushRegistration() throws Exception {
thrown.expect(NoGeneralRegistrationsInCurrentPhaseException.class);
createTld("tld", TldState.LANDRUSH);
setEppInput("domain_create_registration_landrush.xml");
persistContactsAndHosts();
thrown.expect(NoGeneralRegistrationsInCurrentPhaseException.class);
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.DomainResourceSubject.assertAboutDomains;
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.TaskQueueHelper.assertDnsTasksEnqueued;
import static org.joda.money.CurrencyUnit.USD;
@ -754,8 +755,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
setEppInput(xmlFilename);
persistReferencedEntities();
persistActiveDomain(getUniqueIdFromCommand());
thrown.expect(expectedException);
runFlow();
assertThrows(expectedException, this::runFlow);
}
@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.persistResource;
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.assertNoDnsTasksEnqueued;
@ -240,12 +241,10 @@ public class HostCreateFlowTest extends ResourceFlowTestCase<HostCreateFlow, Hos
runFlow();
}
private void doFailingHostNameTest(
String hostName,
Class<? extends Throwable> exception) throws Exception {
private void doFailingHostNameTest(String hostName, Class<? extends Throwable> exception)
throws Exception {
setEppHostCreateInputWithIps(hostName);
thrown.expect(exception);
runFlow();
assertThrows(exception, this::runFlow);
}
@Test

View file

@ -14,6 +14,7 @@
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.createTld;
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.persistResource;
import static google.registry.testing.HostResourceSubject.assertAboutHosts;
import static google.registry.testing.JUnitBackports.expectThrows;
import static google.registry.testing.TaskQueueHelper.assertNoDnsTasksEnqueued;
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)
throws Exception {
persistResource(
newHostResource("ns1.example.tld").asBuilder()
newHostResource("ns1.example.tld")
.asBuilder()
.setStatusValues(ImmutableSet.of(statusValue))
.build());
thrown.expect(exception);
thrown.expectMessage(statusValue.getXmlName());
runFlow();
Exception e = expectThrows(exception, this::runFlow);
assertThat(e).hasMessageThat().contains(statusValue.getXmlName());
}
@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.HistoryEntrySubject.assertAboutHistoryEntries;
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.assertNoDnsTasksEnqueued;
import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued;
@ -371,8 +373,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
DomainResource domain = persistActiveDomain("example.tld");
persistActiveHost(oldHostName());
assertThat(domain.getSubordinateHosts()).isEmpty();
thrown.expect(CannotRenameExternalHostException.class);
runFlow();
expectThrows(CannotRenameExternalHostException.class, this::runFlow);
assertNoDnsTasksEnqueued();
}
@ -1183,8 +1184,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
hostName,
"<host:addr ip=\"v4\">192.0.2.22</host:addr>",
"<host:addr ip=\"v6\">1080:0:0:0:8:800:200C:417A</host:addr>");
thrown.expect(exception);
runFlow();
assertThrows(exception, this::runFlow);
}
@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.loadRegistrar;
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.UnimplementedObjectServiceException;
@ -60,11 +61,9 @@ public abstract class LoginFlowTestCase extends FlowTestCase<LoginFlow> {
}
// Also called in subclasses.
void doFailingTest(String xmlFilename, Class<? extends Exception> exception)
throws Exception {
void doFailingTest(String xmlFilename, Class<? extends Exception> exception) throws Exception {
setEppInput(xmlFilename);
thrown.expect(exception);
runFlow();
assertThrows(exception, this::runFlow);
}
@Test

View file

@ -617,13 +617,16 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
private void runFailureReservedListsTest(
String reservedLists, Class<? extends Exception> errorClass, String errorMsg)
throws Exception {
thrown.expect(errorClass);
thrown.expectMessage(errorMsg);
runCommandForced(
"--reserved_lists",
reservedLists,
"--roid_suffix=Q9JYB4C",
"--dns_writers=VoidDnsWriter",
"xn--q9jyb4c");
Exception e =
expectThrows(
errorClass,
() ->
runCommandForced(
"--reserved_lists",
reservedLists,
"--roid_suffix=Q9JYB4C",
"--dns_writers=VoidDnsWriter",
"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.persistReservedList;
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.START_OF_TIME;
import static org.joda.money.CurrencyUnit.JPY;
@ -934,11 +935,11 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
}
private void runFailureReservedListsTest(
String reservedLists,
Class<? extends Exception> errorClass,
String errorMsg) throws Exception {
thrown.expect(errorClass);
thrown.expectMessage(errorMsg);
runCommandForced("--reserved_lists", reservedLists, "xn--q9jyb4c");
String reservedLists, Class<? extends Exception> errorClass, String errorMsg)
throws Exception {
Exception e =
expectThrows(
errorClass, () -> runCommandForced("--reserved_lists", reservedLists, "xn--q9jyb4c"));
assertThat(e).hasMessageThat().isEqualTo(errorMsg);
}
}