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

@ -20,6 +20,7 @@ import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.loadRegistrar;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.expectThrows;
import static org.joda.money.CurrencyUnit.USD;
import static org.joda.time.DateTimeZone.UTC;
@ -80,75 +81,96 @@ public class CreateCreditBalanceCommandTest extends CommandTestCase<CreateCredit
@Test
public void testFailure_nonexistentParentRegistrar() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Registrar FakeRegistrar not found");
runCommandForced(
"--registrar=FakeRegistrar",
"--credit_id=" + creditId,
"--balance=\"USD 100\"",
"--effective_time=2014-11-01T01:02:03Z");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--registrar=FakeRegistrar",
"--credit_id=" + creditId,
"--balance=\"USD 100\"",
"--effective_time=2014-11-01T01:02:03Z"));
assertThat(thrown).hasMessageThat().contains("Registrar FakeRegistrar not found");
}
@Test
public void testFailure_nonexistentCreditId() throws Exception {
long badId = creditId + 1;
thrown.expect(NullPointerException.class);
thrown.expectMessage("ID " + badId);
runCommandForced(
"--registrar=TheRegistrar",
"--credit_id=" + badId,
"--balance=\"USD 100\"",
"--effective_time=2014-11-01T01:02:03Z");
NullPointerException thrown =
expectThrows(
NullPointerException.class,
() ->
runCommandForced(
"--registrar=TheRegistrar",
"--credit_id=" + badId,
"--balance=\"USD 100\"",
"--effective_time=2014-11-01T01:02:03Z"));
assertThat(thrown).hasMessageThat().contains("ID " + badId);
}
@Test
public void testFailure_negativeBalance() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("negative");
runCommandForced(
"--registrar=TheRegistrar",
"--credit_id=" + creditId,
"--balance=\"USD -1\"",
"--effective_time=2014-11-01T01:02:03Z");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--registrar=TheRegistrar",
"--credit_id=" + creditId,
"--balance=\"USD -1\"",
"--effective_time=2014-11-01T01:02:03Z"));
assertThat(thrown).hasMessageThat().contains("negative");
}
@Test
public void testFailure_noRegistrar() throws Exception {
thrown.expect(ParameterException.class);
thrown.expectMessage("--registrar");
runCommandForced(
"--credit_id=" + creditId,
"--balance=\"USD 100\"",
"--effective_time=2014-11-01T01:02:03Z");
ParameterException thrown =
expectThrows(
ParameterException.class,
() ->
runCommandForced(
"--credit_id=" + creditId,
"--balance=\"USD 100\"",
"--effective_time=2014-11-01T01:02:03Z"));
assertThat(thrown).hasMessageThat().contains("--registrar");
}
@Test
public void testFailure_noCreditId() throws Exception {
thrown.expect(ParameterException.class);
thrown.expectMessage("--credit_id");
runCommandForced(
"--registrar=TheRegistrar",
"--balance=\"USD 100\"",
"--effective_time=2014-11-01T01:02:03Z");
ParameterException thrown =
expectThrows(
ParameterException.class,
() ->
runCommandForced(
"--registrar=TheRegistrar",
"--balance=\"USD 100\"",
"--effective_time=2014-11-01T01:02:03Z"));
assertThat(thrown).hasMessageThat().contains("--credit_id");
}
@Test
public void testFailure_noBalance() throws Exception {
thrown.expect(ParameterException.class);
thrown.expectMessage("--balance");
runCommandForced(
"--registrar=TheRegistrar",
"--credit_id=" + creditId,
"--effective_time=2014-11-01T01:02:03Z");
ParameterException thrown =
expectThrows(
ParameterException.class,
() ->
runCommandForced(
"--registrar=TheRegistrar",
"--credit_id=" + creditId,
"--effective_time=2014-11-01T01:02:03Z"));
assertThat(thrown).hasMessageThat().contains("--balance");
}
@Test
public void testFailure_noEffectiveTime() throws Exception {
thrown.expect(ParameterException.class);
thrown.expectMessage("--effective_time");
runCommandForced(
"--registrar=TheRegistrar",
"--credit_id=" + creditId,
"--balance=\"USD 100\"");
ParameterException thrown =
expectThrows(
ParameterException.class,
() ->
runCommandForced(
"--registrar=TheRegistrar",
"--credit_id=" + creditId,
"--balance=\"USD 100\""));
assertThat(thrown).hasMessageThat().contains("--effective_time");
}
}