Automatically refactor more exception testing to use new JUnit rules

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=179072309
This commit is contained in:
mcilwain 2017-12-14 11:40:04 -08:00 committed by Ben McIlwain
parent d5d29959b4
commit 9157930983
100 changed files with 3900 additions and 3192 deletions

View file

@ -465,88 +465,128 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
@Test
public void testFailure_invalidAddGracePeriod() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Invalid format: \"5m\"");
runCommandForced("--add_grace_period=5m", "xn--q9jyb4c");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() -> runCommandForced("--add_grace_period=5m", "xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("Invalid format: \"5m\"");
}
@Test
public void testFailure_invalidRedemptionGracePeriod() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Invalid format: \"5m\"");
runCommandForced("--redemption_grace_period=5m", "xn--q9jyb4c");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() -> runCommandForced("--redemption_grace_period=5m", "xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("Invalid format: \"5m\"");
}
@Test
public void testFailure_invalidPendingDeleteLength() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Invalid format: \"5m\"");
runCommandForced("--pending_delete_length=5m", "xn--q9jyb4c");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() -> runCommandForced("--pending_delete_length=5m", "xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("Invalid format: \"5m\"");
}
@Test
public void testFailure_invalidTldState() throws Exception {
thrown.expect(ParameterException.class);
thrown.expectMessage(
"INVALID_STATE not formatted correctly or has transition times out of order");
runCommandForced("--tld_state_transitions=" + START_OF_TIME + "=INVALID_STATE", "xn--q9jyb4c");
ParameterException thrown =
expectThrows(
ParameterException.class,
() ->
runCommandForced(
"--tld_state_transitions=" + START_OF_TIME + "=INVALID_STATE", "xn--q9jyb4c"));
assertThat(thrown)
.hasMessageThat()
.contains("INVALID_STATE not formatted correctly or has transition times out of order");
}
@Test
public void testFailure_invalidTldStateTransitionTime() throws Exception {
thrown.expect(ParameterException.class);
thrown.expectMessage(
"INVALID_STATE not formatted correctly or has transition times out of order");
runCommandForced("--tld_state_transitions=tomorrow=INVALID_STATE", "xn--q9jyb4c");
ParameterException thrown =
expectThrows(
ParameterException.class,
() ->
runCommandForced("--tld_state_transitions=tomorrow=INVALID_STATE", "xn--q9jyb4c"));
assertThat(thrown)
.hasMessageThat()
.contains("INVALID_STATE not formatted correctly or has transition times out of order");
}
@Test
public void testFailure_tldStatesOutOfOrder() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("The TLD states are chronologically out of order");
runCommandForced(
String.format(
"--tld_state_transitions=%s=SUNRISE,%s=PREDELEGATION", now, now.plusMonths(1)),
"xn--q9jyb4c");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
String.format(
"--tld_state_transitions=%s=SUNRISE,%s=PREDELEGATION",
now, now.plusMonths(1)),
"xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("The TLD states are chronologically out of order");
}
@Test
public void testFailure_duplicateTldStateTransitions() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("The TLD states are chronologically out of order");
runCommandForced(
String.format("--tld_state_transitions=%s=SUNRISE,%s=SUNRISE", now, now.plusMonths(1)),
"xn--q9jyb4c");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
String.format(
"--tld_state_transitions=%s=SUNRISE,%s=SUNRISE", now, now.plusMonths(1)),
"xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("The TLD states are chronologically out of order");
}
@Test
public void testFailure_duplicateTldStateTransitionTimes() throws Exception {
thrown.expect(ParameterException.class);
thrown.expectMessage("not formatted correctly or has transition times out of order");
runCommandForced(
String.format("--tld_state_transitions=%s=PREDELEGATION,%s=SUNRISE", now, now),
"xn--q9jyb4c");
ParameterException thrown =
expectThrows(
ParameterException.class,
() ->
runCommandForced(
String.format("--tld_state_transitions=%s=PREDELEGATION,%s=SUNRISE", now, now),
"xn--q9jyb4c"));
assertThat(thrown)
.hasMessageThat()
.contains("not formatted correctly or has transition times out of order");
}
@Test
public void testFailure_outOfOrderTldStateTransitionTimes() throws Exception {
thrown.expect(ParameterException.class);
thrown.expectMessage("not formatted correctly or has transition times out of order");
runCommandForced(
String.format(
"--tld_state_transitions=%s=PREDELEGATION,%s=SUNRISE",
now, now.minus(Duration.millis(1))),
"xn--q9jyb4c");
ParameterException thrown =
expectThrows(
ParameterException.class,
() ->
runCommandForced(
String.format(
"--tld_state_transitions=%s=PREDELEGATION,%s=SUNRISE",
now, now.minus(Duration.millis(1))),
"xn--q9jyb4c"));
assertThat(thrown)
.hasMessageThat()
.contains("not formatted correctly or has transition times out of order");
}
@Test
public void testFailure_bothTldStateFlags() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Don't pass both --set_current_tld_state and --tld_state_transitions");
runCommandForced(
String.format("--tld_state_transitions=%s=PREDELEGATION,%s=SUNRISE", now, now.plusDays(1)),
"--set_current_tld_state=GENERAL_AVAILABILITY",
"xn--q9jyb4c");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
String.format(
"--tld_state_transitions=%s=PREDELEGATION,%s=SUNRISE",
now, now.plusDays(1)),
"--set_current_tld_state=GENERAL_AVAILABILITY",
"xn--q9jyb4c"));
assertThat(thrown)
.hasMessageThat()
.contains("Don't pass both --set_current_tld_state and --tld_state_transitions");
}
@Test
@ -558,9 +598,11 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
START_OF_TIME, TldState.PREDELEGATION,
now.minusMonths(1), TldState.GENERAL_AVAILABILITY))
.build());
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("The TLD states are chronologically out of order");
runCommandForced("--set_current_tld_state=SUNRISE", "xn--q9jyb4c");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() -> runCommandForced("--set_current_tld_state=SUNRISE", "xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("The TLD states are chronologically out of order");
}
@Test
@ -572,9 +614,13 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
START_OF_TIME, TldState.PREDELEGATION,
now.plusMonths(1), TldState.GENERAL_AVAILABILITY))
.build());
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage(" when there is a later transition already scheduled");
runCommandForced("--set_current_tld_state=SUNRISE", "xn--q9jyb4c");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() -> runCommandForced("--set_current_tld_state=SUNRISE", "xn--q9jyb4c"));
assertThat(thrown)
.hasMessageThat()
.contains(" when there is a later transition already scheduled");
}
@Test
@ -586,99 +632,139 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
START_OF_TIME, TldState.PREDELEGATION,
now.minusMonths(1), TldState.GENERAL_AVAILABILITY))
.build());
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("--set_current_tld_state is not safe to use in production.");
runCommandInEnvironment(
RegistryToolEnvironment.PRODUCTION,
"--set_current_tld_state=SUNRISE",
"xn--q9jyb4c",
"--force");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandInEnvironment(
RegistryToolEnvironment.PRODUCTION,
"--set_current_tld_state=SUNRISE",
"xn--q9jyb4c",
"--force"));
assertThat(thrown)
.hasMessageThat()
.contains("--set_current_tld_state is not safe to use in production.");
}
@Test
public void testFailure_invalidRenewBillingCost() throws Exception {
thrown.expect(ParameterException.class);
thrown.expectMessage("not formatted correctly or has transition times out of order");
runCommandForced(
String.format("--renew_billing_cost_transitions=%s=US42", START_OF_TIME), "xn--q9jyb4c");
ParameterException thrown =
expectThrows(
ParameterException.class,
() ->
runCommandForced(
String.format("--renew_billing_cost_transitions=%s=US42", START_OF_TIME),
"xn--q9jyb4c"));
assertThat(thrown)
.hasMessageThat()
.contains("not formatted correctly or has transition times out of order");
}
@Test
public void testFailure_negativeRenewBillingCost() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Renew billing cost cannot be negative");
runCommandForced(
String.format("--renew_billing_cost_transitions=%s=USD-42", START_OF_TIME),
"xn--q9jyb4c");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
String.format("--renew_billing_cost_transitions=%s=USD-42", START_OF_TIME),
"xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("Renew billing cost cannot be negative");
}
@Test
public void testFailure_invalidRenewCostTransitionTime() throws Exception {
thrown.expect(ParameterException.class);
thrown.expectMessage("not formatted correctly or has transition times out of order");
runCommandForced("--renew_billing_cost_transitions=tomorrow=USD 1", "xn--q9jyb4c");
ParameterException thrown =
expectThrows(
ParameterException.class,
() ->
runCommandForced("--renew_billing_cost_transitions=tomorrow=USD 1", "xn--q9jyb4c"));
assertThat(thrown)
.hasMessageThat()
.contains("not formatted correctly or has transition times out of order");
}
@Test
public void testFailure_duplicateRenewCostTransitionTimes() throws Exception {
thrown.expect(ParameterException.class);
thrown.expectMessage("not formatted correctly or has transition times out of order");
runCommandForced(
String.format("--renew_billing_cost_transitions=\"%s=USD 1,%s=USD 2\"", now, now),
"xn--q9jyb4c");
ParameterException thrown =
expectThrows(
ParameterException.class,
() ->
runCommandForced(
String.format(
"--renew_billing_cost_transitions=\"%s=USD 1,%s=USD 2\"", now, now),
"xn--q9jyb4c"));
assertThat(thrown)
.hasMessageThat()
.contains("not formatted correctly or has transition times out of order");
}
@Test
public void testFailure_outOfOrderRenewCostTransitionTimes() throws Exception {
thrown.expect(ParameterException.class);
thrown.expectMessage("not formatted correctly or has transition times out of order");
runCommandForced(
String.format(
"--renew_billing_cost_transitions=\"%s=USD 1,%s=USD 2\"",
now, now.minus(Duration.millis(1))),
"xn--q9jyb4c");
ParameterException thrown =
expectThrows(
ParameterException.class,
() ->
runCommandForced(
String.format(
"--renew_billing_cost_transitions=\"%s=USD 1,%s=USD 2\"",
now, now.minus(Duration.millis(1))),
"xn--q9jyb4c"));
assertThat(thrown)
.hasMessageThat()
.contains("not formatted correctly or has transition times out of order");
}
@Test
public void testFailure_noTldName() throws Exception {
thrown.expect(ParameterException.class);
thrown.expectMessage("Main parameters are required (\"Names of the TLDs\")");
runCommandForced();
ParameterException thrown = expectThrows(ParameterException.class, () -> runCommandForced());
assertThat(thrown)
.hasMessageThat()
.contains("Main parameters are required (\"Names of the TLDs\")");
}
@Test
public void testFailure_oneTldDoesNotExist() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("TLD foo does not exist");
runCommandForced("foo", "xn--q9jyb4c");
IllegalArgumentException thrown =
expectThrows(IllegalArgumentException.class, () -> runCommandForced("foo", "xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("TLD foo does not exist");
}
@Test
public void testFailure_duplicateArguments() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Duplicate arguments found: 'xn--q9jyb4c'");
runCommandForced("xn--q9jyb4c", "xn--q9jyb4c");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class, () -> runCommandForced("xn--q9jyb4c", "xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("Duplicate arguments found: 'xn--q9jyb4c'");
}
@Test
public void testFailure_tldDoesNotExist() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("TLD foobarbaz does not exist");
runCommandForced("foobarbaz");
IllegalArgumentException thrown =
expectThrows(IllegalArgumentException.class, () -> runCommandForced("foobarbaz"));
assertThat(thrown).hasMessageThat().contains("TLD foobarbaz does not exist");
}
@Test
public void testFailure_specifiedDnsWriter_doesntExist() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Invalid DNS writer name(s) specified: [InvalidDnsWriter]");
runCommandForced("xn--q9jyb4c", "--dns_writers=InvalidDnsWriter");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() -> runCommandForced("xn--q9jyb4c", "--dns_writers=InvalidDnsWriter"));
assertThat(thrown)
.hasMessageThat()
.contains("Invalid DNS writer name(s) specified: [InvalidDnsWriter]");
}
@Test
public void testFailure_setNonExistentReservedLists() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Could not find reserved list xn--q9jyb4c_ZZZ to add to the tld");
runCommandForced("--reserved_lists", "xn--q9jyb4c_ZZZ", "xn--q9jyb4c");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() -> runCommandForced("--reserved_lists", "xn--q9jyb4c_ZZZ", "xn--q9jyb4c"));
assertThat(thrown)
.hasMessageThat()
.contains("Could not find reserved list xn--q9jyb4c_ZZZ to add to the tld");
}
@Test
@ -686,9 +772,11 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
persistResource(Registry.get("xn--q9jyb4c").asBuilder()
.setReservedListsByName(ImmutableSet.of("xn--q9jyb4c_r1", "xn--q9jyb4c_r2"))
.build());
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("xn--q9jyb4c_r1");
runCommandForced("--add_reserved_lists=xn--q9jyb4c_r1", "xn--q9jyb4c");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() -> runCommandForced("--add_reserved_lists=xn--q9jyb4c_r1", "xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("xn--q9jyb4c_r1");
}
@Test
@ -696,19 +784,24 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
persistResource(Registry.get("xn--q9jyb4c").asBuilder()
.setReservedListsByName(ImmutableSet.of("xn--q9jyb4c_r1", "xn--q9jyb4c_r2"))
.build());
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("xn--q9jyb4c_Z");
runCommandForced("--remove_reserved_lists=xn--q9jyb4c_Z", "xn--q9jyb4c");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() -> runCommandForced("--remove_reserved_lists=xn--q9jyb4c_Z", "xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("xn--q9jyb4c_Z");
}
@Test
public void testFailure_cantAddAndRemoveSameReservedListSimultaneously() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("xn--q9jyb4c_r1");
runCommandForced(
"--add_reserved_lists=xn--q9jyb4c_r1",
"--remove_reserved_lists=xn--q9jyb4c_r1",
"xn--q9jyb4c");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--add_reserved_lists=xn--q9jyb4c_r1",
"--remove_reserved_lists=xn--q9jyb4c_r1",
"xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("xn--q9jyb4c_r1");
}
@Test
@ -717,9 +810,11 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
Registry.get("xn--q9jyb4c").asBuilder()
.setAllowedRegistrantContactIds(ImmutableSet.of("alice", "bob"))
.build());
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("alice");
runCommandForced("--add_allowed_registrants=alice", "xn--q9jyb4c");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() -> runCommandForced("--add_allowed_registrants=alice", "xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("alice");
}
@Test
@ -728,19 +823,24 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
Registry.get("xn--q9jyb4c").asBuilder()
.setAllowedRegistrantContactIds(ImmutableSet.of("alice"))
.build());
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("bob");
runCommandForced("--remove_allowed_registrants=bob", "xn--q9jyb4c");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() -> runCommandForced("--remove_allowed_registrants=bob", "xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("bob");
}
@Test
public void testFailure_cantAddAndRemoveSameAllowedRegistrantsSimultaneously() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("alice");
runCommandForced(
"--add_allowed_registrants=alice",
"--remove_allowed_registrants=alice",
"xn--q9jyb4c");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--add_allowed_registrants=alice",
"--remove_allowed_registrants=alice",
"xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("alice");
}
@Test
@ -750,9 +850,11 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
.setAllowedFullyQualifiedHostNames(
ImmutableSet.of("ns1.example.com", "ns2.example.com"))
.build());
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("ns1.example.com");
runCommandForced("--add_allowed_nameservers=ns1.example.com", "xn--q9jyb4c");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() -> runCommandForced("--add_allowed_nameservers=ns1.example.com", "xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("ns1.example.com");
}
@Test
@ -762,19 +864,24 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
.setAllowedFullyQualifiedHostNames(
ImmutableSet.of("ns1.example.com"))
.build());
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("ns2.example.com");
runCommandForced("--remove_allowed_nameservers=ns2.example.com", "xn--q9jyb4c");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() -> runCommandForced("--remove_allowed_nameservers=ns2.example.com", "xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("ns2.example.com");
}
@Test
public void testFailure_cantAddAndRemoveSameAllowedNameserversSimultaneously() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("ns1.example.com");
runCommandForced(
"--add_allowed_nameservers=ns1.example.com",
"--remove_allowed_nameservers=ns1.example.com",
"xn--q9jyb4c");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--add_allowed_nameservers=ns1.example.com",
"--remove_allowed_nameservers=ns1.example.com",
"xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("ns1.example.com");
}
@Test
@ -895,9 +1002,11 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
@Test
public void testFailure_setPremiumListThatDoesntExist() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("The premium list 'phonies' doesn't exist");
runCommandForced("--premium_list=phonies", "xn--q9jyb4c");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() -> runCommandForced("--premium_list=phonies", "xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("The premium list 'phonies' doesn't exist");
}
@Test
@ -910,17 +1019,24 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
@Test
public void testFailure_updateLrpPeriod_backwardsInterval() throws Exception {
thrown.expect(ParameterException.class);
thrown.expectMessage(
"--lrp_period=2005-06-09T12:30:00Z/2004-07-10T13:30:00Z not an ISO-8601 interval");
runCommandForced("--lrp_period=2005-06-09T12:30:00Z/2004-07-10T13:30:00Z", "xn--q9jyb4c");
ParameterException thrown =
expectThrows(
ParameterException.class,
() ->
runCommandForced(
"--lrp_period=2005-06-09T12:30:00Z/2004-07-10T13:30:00Z", "xn--q9jyb4c"));
assertThat(thrown)
.hasMessageThat()
.contains(
"--lrp_period=2005-06-09T12:30:00Z/2004-07-10T13:30:00Z not an ISO-8601 interval");
}
@Test
public void testFailure_updateLrpPeriod_badInterval() throws Exception {
thrown.expect(ParameterException.class);
thrown.expectMessage("--lrp_period=foobar not an ISO-8601 interval");
runCommandForced("--lrp_period=foobar", "xn--q9jyb4c");
ParameterException thrown =
expectThrows(
ParameterException.class, () -> runCommandForced("--lrp_period=foobar", "xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("--lrp_period=foobar not an ISO-8601 interval");
}
private void runSuccessfulReservedListsTest(String reservedLists) throws Exception {