Move thrown.expect() right before the throwing statement

aka regexing for fun and profit.

This also makes sure that there are no statements after the
throwing statement, since these would be dead code. There
were a surprising number of places with assertions after
the throw, and none of these are actually triggered in tests
ever. When I found these, I replaced them with try/catch/rethrow
which makes the assertions actually happen:

before:

// This is the ExceptionRule that checks EppException marshaling
thrown.expect(FooException.class);
doThrowingThing();
assertSomething();  // Dead code!

after:

try {
  doThrowingThing();
  assertWithMessage("...").fail();
} catch (FooException e) {
  assertSomething();
  // For EppExceptions:
  assertAboutEppExceptins().that(e).marshalsToXml();
}

To make this work, I added EppExceptionSubject.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=135793407
This commit is contained in:
cgoldfeder 2016-10-11 07:19:48 -07:00 committed by Ben McIlwain
parent cb8320ff40
commit f3a0b78145
62 changed files with 519 additions and 450 deletions

View file

@ -259,73 +259,73 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
@Test
public void testFailure_refundableFee_v06() throws Exception {
thrown.expect(UnsupportedFeeAttributeException.class);
setEppInput("domain_renew_fee_refundable.xml", FEE_06_MAP);
persistDomain();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
}
@Test
public void testFailure_refundableFee_v11() throws Exception {
thrown.expect(UnsupportedFeeAttributeException.class);
setEppInput("domain_renew_fee_refundable.xml", FEE_11_MAP);
persistDomain();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
}
@Test
public void testFailure_refundableFee_v12() throws Exception {
thrown.expect(UnsupportedFeeAttributeException.class);
setEppInput("domain_renew_fee_refundable.xml", FEE_12_MAP);
persistDomain();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
}
@Test
public void testFailure_gracePeriodFee_v06() throws Exception {
thrown.expect(UnsupportedFeeAttributeException.class);
setEppInput("domain_renew_fee_grace_period.xml", FEE_06_MAP);
persistDomain();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
}
@Test
public void testFailure_gracePeriodFee_v11() throws Exception {
thrown.expect(UnsupportedFeeAttributeException.class);
setEppInput("domain_renew_fee_grace_period.xml", FEE_11_MAP);
persistDomain();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
}
@Test
public void testFailure_gracePeriodFee_v12() throws Exception {
thrown.expect(UnsupportedFeeAttributeException.class);
setEppInput("domain_renew_fee_grace_period.xml", FEE_12_MAP);
persistDomain();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
}
@Test
public void testFailure_appliedFee_v06() throws Exception {
thrown.expect(UnsupportedFeeAttributeException.class);
setEppInput("domain_renew_fee_applied.xml", FEE_06_MAP);
persistDomain();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
}
@Test
public void testFailure_appliedFee_v11() throws Exception {
thrown.expect(UnsupportedFeeAttributeException.class);
setEppInput("domain_renew_fee_applied.xml", FEE_11_MAP);
persistDomain();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
}
@Test
public void testFailure_appliedFee_v12() throws Exception {
thrown.expect(UnsupportedFeeAttributeException.class);
setEppInput("domain_renew_fee_applied.xml", FEE_12_MAP);
persistDomain();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
}
@ -388,30 +388,29 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
@Test
public void testFailure_existedButWasDeleted() throws Exception {
persistDeletedDomain(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1));
thrown.expect(
ResourceDoesNotExistException.class,
String.format("(%s)", getUniqueIdFromCommand()));
persistDeletedDomain(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1));
runFlow();
}
@Test
public void testFailure_clientRenewProhibited() throws Exception {
thrown.expect(ResourceStatusProhibitsOperationException.class);
persistDomain(StatusValue.CLIENT_RENEW_PROHIBITED);
thrown.expect(ResourceStatusProhibitsOperationException.class);
runFlow();
}
@Test
public void testFailure_serverRenewProhibited() throws Exception {
thrown.expect(ResourceStatusProhibitsOperationException.class);
persistDomain(StatusValue.SERVER_RENEW_PROHIBITED);
thrown.expect(ResourceStatusProhibitsOperationException.class);
runFlow();
}
@Test
public void testFailure_wrongFeeAmount_v06() throws Exception {
thrown.expect(FeesMismatchException.class);
setEppInput("domain_renew_fee.xml", FEE_06_MAP);
persistResource(
Registry.get("tld")
@ -419,12 +418,12 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
.setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 20)))
.build());
persistDomain();
thrown.expect(FeesMismatchException.class);
runFlow();
}
@Test
public void testFailure_wrongFeeAmount_v11() throws Exception {
thrown.expect(FeesMismatchException.class);
setEppInput("domain_renew_fee.xml", FEE_11_MAP);
persistResource(
Registry.get("tld")
@ -432,12 +431,12 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
.setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 20)))
.build());
persistDomain();
thrown.expect(FeesMismatchException.class);
runFlow();
}
@Test
public void testFailure_wrongFeeAmount_v12() throws Exception {
thrown.expect(FeesMismatchException.class);
setEppInput("domain_renew_fee.xml", FEE_12_MAP);
persistResource(
Registry.get("tld")
@ -445,12 +444,12 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
.setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 20)))
.build());
persistDomain();
thrown.expect(FeesMismatchException.class);
runFlow();
}
@Test
public void testFailure_wrongCurrency_v06() throws Exception {
thrown.expect(CurrencyUnitMismatchException.class);
setEppInput("domain_renew_fee.xml", FEE_06_MAP);
persistResource(
Registry.get("tld")
@ -463,12 +462,12 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
.setServerStatusChangeBillingCost(Money.of(EUR, 19))
.build());
persistDomain();
thrown.expect(CurrencyUnitMismatchException.class);
runFlow();
}
@Test
public void testFailure_wrongCurrency_v11() throws Exception {
thrown.expect(CurrencyUnitMismatchException.class);
setEppInput("domain_renew_fee.xml", FEE_11_MAP);
persistResource(
Registry.get("tld")
@ -481,12 +480,12 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
.setServerStatusChangeBillingCost(Money.of(EUR, 19))
.build());
persistDomain();
thrown.expect(CurrencyUnitMismatchException.class);
runFlow();
}
@Test
public void testFailure_wrongCurrency_v12() throws Exception {
thrown.expect(CurrencyUnitMismatchException.class);
setEppInput("domain_renew_fee.xml", FEE_12_MAP);
persistResource(
Registry.get("tld")
@ -499,99 +498,100 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
.setServerStatusChangeBillingCost(Money.of(EUR, 19))
.build());
persistDomain();
thrown.expect(CurrencyUnitMismatchException.class);
runFlow();
}
@Test
public void testFailure_feeGivenInWrongScale_v06() throws Exception {
thrown.expect(CurrencyValueScaleException.class);
setEppInput("domain_renew_fee_bad_scale.xml", FEE_06_MAP);
persistDomain();
thrown.expect(CurrencyValueScaleException.class);
runFlow();
}
@Test
public void testFailure_feeGivenInWrongScale_v11() throws Exception {
thrown.expect(CurrencyValueScaleException.class);
setEppInput("domain_renew_fee_bad_scale.xml", FEE_11_MAP);
persistDomain();
thrown.expect(CurrencyValueScaleException.class);
runFlow();
}
@Test
public void testFailure_feeGivenInWrongScale_v12() throws Exception {
thrown.expect(CurrencyValueScaleException.class);
setEppInput("domain_renew_fee_bad_scale.xml", FEE_12_MAP);
persistDomain();
thrown.expect(CurrencyValueScaleException.class);
runFlow();
}
@Test
public void testFailure_pendingTransfer() throws Exception {
thrown.expect(DomainHasPendingTransferException.class);
persistDomain();
persistWithPendingTransfer(reloadResourceByForeignKey()
.asBuilder()
.setRegistrationExpirationTime(DateTime.parse("2001-09-08T22:00:00.0Z"))
.build());
thrown.expect(DomainHasPendingTransferException.class);
runFlow();
}
@Test
public void testFailure_periodInMonths() throws Exception {
thrown.expect(BadPeriodUnitException.class);
setEppInput("domain_renew_months.xml");
persistDomain();
thrown.expect(BadPeriodUnitException.class);
runFlow();
}
@Test
public void testFailure_max10Years() throws Exception {
thrown.expect(ExceedsMaxRegistrationYearsException.class);
setEppInput("domain_renew_11_years.xml");
persistDomain();
thrown.expect(ExceedsMaxRegistrationYearsException.class);
runFlow();
}
@Test
public void testFailure_pendingDelete() throws Exception {
thrown.expect(ResourceStatusProhibitsOperationException.class);
persistResource(newDomainResource(getUniqueIdFromCommand()).asBuilder()
.setRegistrationExpirationTime(expirationTime)
.setDeletionTime(clock.nowUtc().plusDays(1))
.addStatusValue(StatusValue.PENDING_DELETE)
.build());
thrown.expect(ResourceStatusProhibitsOperationException.class);
runFlow();
}
@Test
public void testFailure_curExpDateMustMatch() throws Exception {
thrown.expect(IncorrectCurrentExpirationDateException.class);
persistDomain();
// Note expiration time is off by one day.
persistResource(reloadResourceByForeignKey().asBuilder()
.setRegistrationExpirationTime(DateTime.parse("2000-04-04T22:00:00.0Z"))
.build());
thrown.expect(IncorrectCurrentExpirationDateException.class);
runFlow();
}
@Test
public void testFailure_unauthorizedClient() throws Exception {
thrown.expect(ResourceNotOwnedException.class);
sessionMetadata.setClientId("NewRegistrar");
persistActiveDomain(getUniqueIdFromCommand());
thrown.expect(ResourceNotOwnedException.class);
runFlow();
}
@Test
public void testFailure_notAuthorizedForTld() throws Exception {
thrown.expect(NotAuthorizedForTldException.class);
persistResource(
Registrar.loadByClientId("TheRegistrar")
.asBuilder()
.setAllowedTlds(ImmutableSet.<String>of())
.build());
persistDomain();
thrown.expect(NotAuthorizedForTldException.class);
runFlow();
}
@ -605,11 +605,11 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
@Test
public void testFailure_feeNotProvidedOnPremiumName() throws Exception {
thrown.expect(FeesRequiredForPremiumNameException.class);
createTld("example");
persistResource(Registry.get("example").asBuilder().setPremiumPriceAckRequired(true).build());
setEppInput("domain_renew_premium.xml");
persistDomain();
thrown.expect(FeesRequiredForPremiumNameException.class);
runFlow();
}