Change from assertThat(assertThrow()) to thrown = assertThrows() then assertThat(thrown) (#1606)

This commit is contained in:
Rachel Guan 2022-04-28 16:09:36 -04:00 committed by GitHub
parent f273783894
commit d0af81ecdf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 167 additions and 172 deletions

View file

@ -225,7 +225,9 @@ public final class OteAccountBuilderTest {
OteAccountBuilder oteSetupHelper = OteAccountBuilder.forRegistrarId("myclientid"); OteAccountBuilder oteSetupHelper = OteAccountBuilder.forRegistrarId("myclientid");
assertThat(assertThrows(IllegalStateException.class, () -> oteSetupHelper.buildAndPersist())) IllegalStateException thrown =
assertThrows(IllegalStateException.class, () -> oteSetupHelper.buildAndPersist());
assertThat(thrown)
.hasMessageThat() .hasMessageThat()
.contains("Found existing object(s) conflicting with OT&E objects"); .contains("Found existing object(s) conflicting with OT&E objects");
} }
@ -236,7 +238,9 @@ public final class OteAccountBuilderTest {
OteAccountBuilder oteSetupHelper = OteAccountBuilder.forRegistrarId("myclientid"); OteAccountBuilder oteSetupHelper = OteAccountBuilder.forRegistrarId("myclientid");
assertThat(assertThrows(IllegalStateException.class, () -> oteSetupHelper.buildAndPersist())) IllegalStateException thrown =
assertThrows(IllegalStateException.class, () -> oteSetupHelper.buildAndPersist());
assertThat(thrown)
.hasMessageThat() .hasMessageThat()
.contains("Found existing object(s) conflicting with OT&E objects"); .contains("Found existing object(s) conflicting with OT&E objects");
} }

View file

@ -131,10 +131,11 @@ public class DatabaseMigrationStateScheduleTest extends EntityTestCase {
.put(startTime.plusHours(2), DATASTORE_PRIMARY_NO_ASYNC) .put(startTime.plusHours(2), DATASTORE_PRIMARY_NO_ASYNC)
.put(startTime.plusHours(3), DATASTORE_PRIMARY_READ_ONLY) .put(startTime.plusHours(3), DATASTORE_PRIMARY_READ_ONLY)
.build(); .build();
assertThat( IllegalArgumentException thrown =
assertThrows( assertThrows(
IllegalArgumentException.class, IllegalArgumentException.class,
() -> jpaTm().transact(() -> DatabaseMigrationStateSchedule.set(nowInvalidMap)))) () -> jpaTm().transact(() -> DatabaseMigrationStateSchedule.set(nowInvalidMap)));
assertThat(thrown)
.hasMessageThat() .hasMessageThat()
.isEqualTo( .isEqualTo(
"Cannot transition from current state-as-of-now DATASTORE_ONLY " "Cannot transition from current state-as-of-now DATASTORE_ONLY "
@ -143,14 +144,13 @@ public class DatabaseMigrationStateScheduleTest extends EntityTestCase {
@Test @Test
void testFailure_notInTransaction() { void testFailure_notInTransaction() {
assertThat( IllegalStateException thrown =
assertThrows( assertThrows(
IllegalStateException.class, IllegalStateException.class,
() -> () ->
DatabaseMigrationStateSchedule.set( DatabaseMigrationStateSchedule.set(
DatabaseMigrationStateSchedule.DEFAULT_TRANSITION_MAP.toValueMap()))) DatabaseMigrationStateSchedule.DEFAULT_TRANSITION_MAP.toValueMap()));
.hasMessageThat() assertThat(thrown).hasMessageThat().isEqualTo("Not in a transaction");
.isEqualTo("Not in a transaction");
} }
@Test @Test
@ -188,10 +188,11 @@ public class DatabaseMigrationStateScheduleTest extends EntityTestCase {
private void runInvalidTransition(MigrationState from, MigrationState to) { private void runInvalidTransition(MigrationState from, MigrationState to) {
ImmutableSortedMap<DateTime, MigrationState> transitions = ImmutableSortedMap<DateTime, MigrationState> transitions =
createMapEndingWithTransition(from, to); createMapEndingWithTransition(from, to);
assertThat( IllegalArgumentException thrown =
assertThrows( assertThrows(
IllegalArgumentException.class, IllegalArgumentException.class,
() -> jpaTm().transact(() -> DatabaseMigrationStateSchedule.set(transitions)))) () -> jpaTm().transact(() -> DatabaseMigrationStateSchedule.set(transitions)));
assertThat(thrown)
.hasMessageThat() .hasMessageThat()
.isEqualTo( .isEqualTo(
String.format("validStateTransitions map cannot transition from %s to %s.", from, to)); String.format("validStateTransitions map cannot transition from %s to %s.", from, to));

View file

@ -73,8 +73,10 @@ final class AbstractJsonableObjectTest {
@JsonableElement String myString = "A"; @JsonableElement String myString = "A";
@JsonableElement("myString") String anotherString = "B"; @JsonableElement("myString") String anotherString = "B";
}; };
assertThat(assertThrows(JsonableException.class, () -> jsonable.toJson())) JsonableException thrown = assertThrows(JsonableException.class, () -> jsonable.toJson());
.hasMessageThat().contains("Encountered the same field name 'myString' multiple times"); assertThat(thrown)
.hasMessageThat()
.contains("Encountered the same field name 'myString' multiple times");
} }
@Test @Test
@ -96,8 +98,8 @@ final class AbstractJsonableObjectTest {
return in; return in;
} }
}; };
assertThat(assertThrows(JsonableException.class, () -> jsonable.toJson())) JsonableException thrown = assertThrows(JsonableException.class, () -> jsonable.toJson());
.hasMessageThat().contains("must have no arguments"); assertThat(thrown).hasMessageThat().contains("must have no arguments");
} }
@Test @Test
@ -186,8 +188,10 @@ final class AbstractJsonableObjectTest {
@JsonableElement("myList[]") @JsonableElement("myList[]")
Optional<Integer> myListMeaningOfLife = Optional.of(42); Optional<Integer> myListMeaningOfLife = Optional.of(42);
}; };
assertThat(assertThrows(JsonableException.class, () -> jsonable.toJson())) JsonableException thrown = assertThrows(JsonableException.class, () -> jsonable.toJson());
.hasMessageThat().contains("Encountered the same field name 'myList' multiple times"); assertThat(thrown)
.hasMessageThat()
.contains("Encountered the same field name 'myList' multiple times");
} }
@RestrictJsonNames({"allowed", "allowedList[]"}) @RestrictJsonNames({"allowed", "allowedList[]"})
@ -226,7 +230,8 @@ final class AbstractJsonableObjectTest {
@JsonableElement @JsonableElement
JsonableWithNameRestrictions wrong = new JsonableWithNameRestrictions(); JsonableWithNameRestrictions wrong = new JsonableWithNameRestrictions();
}; };
assertThat(assertThrows(JsonableException.class, () -> jsonable.toJson())) JsonableException thrown = assertThrows(JsonableException.class, () -> jsonable.toJson());
assertThat(thrown)
.hasMessageThat() .hasMessageThat()
.contains("must be named one of ['allowed', 'allowedList[]'], but is named 'wrong'"); .contains("must be named one of ['allowed', 'allowedList[]'], but is named 'wrong'");
} }
@ -237,9 +242,8 @@ final class AbstractJsonableObjectTest {
@JsonableElement @JsonableElement
JsonableWithNoAllowedNames wrong = new JsonableWithNoAllowedNames(); JsonableWithNoAllowedNames wrong = new JsonableWithNoAllowedNames();
}; };
assertThat(assertThrows(JsonableException.class, () -> jsonable.toJson())) JsonableException thrown = assertThrows(JsonableException.class, () -> jsonable.toJson());
.hasMessageThat() assertThat(thrown).hasMessageThat().contains("is annotated with an empty RestrictJsonNames");
.contains("is annotated with an empty RestrictJsonNames");
} }
@RestrictJsonNames({}) @RestrictJsonNames({})

View file

@ -232,17 +232,15 @@ public final class UpdateRegistrarRdapBaseUrlsActionTest {
@TestOfyAndSql @TestOfyAndSql
void testNoTlds() { void testNoTlds() {
deleteTld("tld"); deleteTld("tld");
assertThat(assertThrows(IllegalArgumentException.class, action::run)) IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, action::run);
.hasMessageThat() assertThat(thrown).hasMessageThat().isEqualTo("There must exist at least one REAL TLD.");
.isEqualTo("There must exist at least one REAL TLD.");
} }
@TestOfyAndSql @TestOfyAndSql
void testOnlyTestTlds() { void testOnlyTestTlds() {
persistResource(Registry.get("tld").asBuilder().setTldType(TldType.TEST).build()); persistResource(Registry.get("tld").asBuilder().setTldType(TldType.TEST).build());
assertThat(assertThrows(IllegalArgumentException.class, action::run)) IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, action::run);
.hasMessageThat() assertThat(thrown).hasMessageThat().isEqualTo("There must exist at least one REAL TLD.");
.isEqualTo("There must exist at least one REAL TLD.");
} }
@TestOfyAndSql @TestOfyAndSql
@ -278,7 +276,8 @@ public final class UpdateRegistrarRdapBaseUrlsActionTest {
httpTransport.addNextResponse(badLoginResponse); httpTransport.addNextResponse(badLoginResponse);
httpTransport.addNextResponse(badLoginResponse); httpTransport.addNextResponse(badLoginResponse);
assertThat(assertThrows(RuntimeException.class, action::run)) RuntimeException thrown = assertThrows(RuntimeException.class, action::run);
assertThat(thrown)
.hasMessageThat() .hasMessageThat()
.isEqualTo("Error contacting MosAPI server. Tried TLDs [secondtld, tld]"); .isEqualTo("Error contacting MosAPI server. Tried TLDs [secondtld, tld]");
} }
@ -316,9 +315,8 @@ public final class UpdateRegistrarRdapBaseUrlsActionTest {
httpTransport.addNextResponse(logoutResponse); httpTransport.addNextResponse(logoutResponse);
httpTransport.addNextResponse(badLoginResponse); httpTransport.addNextResponse(badLoginResponse);
assertThat(assertThrows(RuntimeException.class, action::run)) RuntimeException thrown = assertThrows(RuntimeException.class, action::run);
.hasCauseThat() assertThat(thrown).hasCauseThat().isInstanceOf(JsonSyntaxException.class);
.isInstanceOf(JsonSyntaxException.class);
} }
private static void addValidResponses(TestHttpTransport httpTransport) { private static void addValidResponses(TestHttpTransport httpTransport) {

View file

@ -403,9 +403,9 @@ class AuthenticatedRegistrarAccessorTest {
AuthenticatedRegistrarAccessor registrarAccessor = AuthenticatedRegistrarAccessor registrarAccessor =
AuthenticatedRegistrarAccessor.createForTesting(ImmutableSetMultimap.of()); AuthenticatedRegistrarAccessor.createForTesting(ImmutableSetMultimap.of());
assertThat(assertThrows(RegistrarAccessDeniedException.class, registrarAccessor::guessClientId)) RegistrarAccessDeniedException thrown =
.hasMessageThat() assertThrows(RegistrarAccessDeniedException.class, registrarAccessor::guessClientId);
.isEqualTo("TestUserId isn't associated with any registrar"); assertThat(thrown).hasMessageThat().isEqualTo("TestUserId isn't associated with any registrar");
} }
@TestOfyAndSql @TestOfyAndSql

View file

@ -61,41 +61,38 @@ abstract class CreateOrUpdateReservedListCommandTestCase<
@Test @Test
void testFailure_fileDoesntExist() { void testFailure_fileDoesntExist() {
assertThat( ParameterException thrown =
assertThrows( assertThrows(
ParameterException.class, ParameterException.class,
() -> () ->
runCommandForced( runCommandForced(
"--name=xn--q9jyb4c_common-reserved", "--name=xn--q9jyb4c_common-reserved",
"--input=" + reservedTermsPath + "-nonexistent"))) "--input=" + reservedTermsPath + "-nonexistent"));
.hasMessageThat() assertThat(thrown).hasMessageThat().contains("-i not found");
.contains("-i not found");
} }
@Test @Test
void testFailure_fileDoesntParse() { void testFailure_fileDoesntParse() {
assertThat( IllegalArgumentException thrown =
assertThrows( assertThrows(
IllegalArgumentException.class, IllegalArgumentException.class,
() -> () ->
runCommandForced( runCommandForced(
"--name=xn--q9jyb4c_common-reserved", "--name=xn--q9jyb4c_common-reserved", "--input=" + invalidReservedTermsPath));
"--input=" + invalidReservedTermsPath))) assertThat(thrown).hasMessageThat().contains("No enum constant");
.hasMessageThat()
.contains("No enum constant");
} }
@Test @Test
void testFailure_invalidLabel_includesFullDomainName() throws Exception { void testFailure_invalidLabel_includesFullDomainName() throws Exception {
Files.asCharSink(new File(invalidReservedTermsPath), UTF_8) Files.asCharSink(new File(invalidReservedTermsPath), UTF_8)
.write("example.tld,FULLY_BLOCKED\n\n"); .write("example.tld,FULLY_BLOCKED\n\n");
assertThat( IllegalArgumentException thrown =
assertThrows( assertThrows(
IllegalArgumentException.class, IllegalArgumentException.class,
() -> () ->
runCommandForced( runCommandForced(
"--name=xn--q9jyb4c_common-reserved", "--name=xn--q9jyb4c_common-reserved", "--input=" + invalidReservedTermsPath));
"--input=" + invalidReservedTermsPath))) assertThat(thrown)
.hasMessageThat() .hasMessageThat()
.isEqualTo("Label example.tld must not be a multi-level domain name"); .isEqualTo("Label example.tld must not be a multi-level domain name");
} }

View file

@ -60,7 +60,6 @@ import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.joda.time.DateTimeZone; import org.joda.time.DateTimeZone;
import org.junit.Assert;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.api.extension.RegisterExtension;
import org.mockito.junit.jupiter.MockitoSettings; import org.mockito.junit.jupiter.MockitoSettings;
@ -317,12 +316,13 @@ public final class DomainLockUtilsTest {
domainLockUtils.saveNewRegistryUnlockRequest( domainLockUtils.saveNewRegistryUnlockRequest(
DOMAIN_NAME, "TheRegistrar", false, Optional.empty()); DOMAIN_NAME, "TheRegistrar", false, Optional.empty());
assertThat( IllegalArgumentException thrown =
assertThrows( assertThrows(
IllegalArgumentException.class, IllegalArgumentException.class,
() -> () ->
domainLockUtils.saveNewRegistryUnlockRequest( domainLockUtils.saveNewRegistryUnlockRequest(
DOMAIN_NAME, "TheRegistrar", false, Optional.empty()))) DOMAIN_NAME, "TheRegistrar", false, Optional.empty()));
assertThat(thrown)
.hasMessageThat() .hasMessageThat()
.isEqualTo("A pending unlock action already exists for example.tld"); .isEqualTo("A pending unlock action already exists for example.tld");
} }
@ -332,37 +332,38 @@ public final class DomainLockUtilsTest {
RegistryLock lock = RegistryLock lock =
domainLockUtils.saveNewRegistryLockRequest(DOMAIN_NAME, "TheRegistrar", null, true); domainLockUtils.saveNewRegistryLockRequest(DOMAIN_NAME, "TheRegistrar", null, true);
domainLockUtils.verifyAndApplyLock(lock.getVerificationCode(), true); domainLockUtils.verifyAndApplyLock(lock.getVerificationCode(), true);
assertThat( IllegalArgumentException thrown =
assertThrows( assertThrows(
IllegalArgumentException.class, IllegalArgumentException.class,
() -> () ->
domainLockUtils.saveNewRegistryUnlockRequest( domainLockUtils.saveNewRegistryUnlockRequest(
DOMAIN_NAME, "TheRegistrar", false, Optional.empty()))) DOMAIN_NAME, "TheRegistrar", false, Optional.empty()));
assertThat(thrown)
.hasMessageThat() .hasMessageThat()
.isEqualTo("Non-admin user cannot unlock admin-locked domain example.tld"); .isEqualTo("Non-admin user cannot unlock admin-locked domain example.tld");
} }
@TestOfyAndSql @TestOfyAndSql
void testFailure_createLock_unknownDomain() { void testFailure_createLock_unknownDomain() {
assertThat( IllegalArgumentException thrown =
assertThrows( assertThrows(
IllegalArgumentException.class, IllegalArgumentException.class,
() -> () ->
domainLockUtils.saveNewRegistryLockRequest( domainLockUtils.saveNewRegistryLockRequest(
"asdf.tld", "TheRegistrar", POC_ID, false))) "asdf.tld", "TheRegistrar", POC_ID, false));
.hasMessageThat() assertThat(thrown).hasMessageThat().isEqualTo("Domain doesn't exist");
.isEqualTo("Domain doesn't exist");
} }
@TestOfyAndSql @TestOfyAndSql
void testFailure_createLock_alreadyPendingLock() { void testFailure_createLock_alreadyPendingLock() {
domainLockUtils.saveNewRegistryLockRequest(DOMAIN_NAME, "TheRegistrar", POC_ID, false); domainLockUtils.saveNewRegistryLockRequest(DOMAIN_NAME, "TheRegistrar", POC_ID, false);
assertThat( IllegalArgumentException thrown =
assertThrows( assertThrows(
IllegalArgumentException.class, IllegalArgumentException.class,
() -> () ->
domainLockUtils.saveNewRegistryLockRequest( domainLockUtils.saveNewRegistryLockRequest(
DOMAIN_NAME, "TheRegistrar", POC_ID, false))) DOMAIN_NAME, "TheRegistrar", POC_ID, false));
assertThat(thrown)
.hasMessageThat() .hasMessageThat()
.isEqualTo("A pending or completed lock action already exists for example.tld"); .isEqualTo("A pending or completed lock action already exists for example.tld");
} }
@ -370,26 +371,24 @@ public final class DomainLockUtilsTest {
@TestOfyAndSql @TestOfyAndSql
void testFailure_createLock_alreadyLocked() { void testFailure_createLock_alreadyLocked() {
persistResource(domain.asBuilder().setStatusValues(REGISTRY_LOCK_STATUSES).build()); persistResource(domain.asBuilder().setStatusValues(REGISTRY_LOCK_STATUSES).build());
assertThat( IllegalArgumentException thrown =
assertThrows( assertThrows(
IllegalArgumentException.class, IllegalArgumentException.class,
() -> () ->
domainLockUtils.saveNewRegistryLockRequest( domainLockUtils.saveNewRegistryLockRequest(
DOMAIN_NAME, "TheRegistrar", POC_ID, false))) DOMAIN_NAME, "TheRegistrar", POC_ID, false));
.hasMessageThat() assertThat(thrown).hasMessageThat().isEqualTo("Domain example.tld is already locked");
.isEqualTo("Domain example.tld is already locked");
} }
@TestOfyAndSql @TestOfyAndSql
void testFailure_createUnlock_alreadyUnlocked() { void testFailure_createUnlock_alreadyUnlocked() {
assertThat( IllegalArgumentException thrown =
assertThrows( assertThrows(
IllegalArgumentException.class, IllegalArgumentException.class,
() -> () ->
domainLockUtils.saveNewRegistryUnlockRequest( domainLockUtils.saveNewRegistryUnlockRequest(
DOMAIN_NAME, "TheRegistrar", false, Optional.empty()))) DOMAIN_NAME, "TheRegistrar", false, Optional.empty()));
.hasMessageThat() assertThat(thrown).hasMessageThat().isEqualTo("Domain example.tld is already unlocked");
.isEqualTo("Domain example.tld is already unlocked");
} }
@TestOfyAndSql @TestOfyAndSql
@ -398,12 +397,11 @@ public final class DomainLockUtilsTest {
domainLockUtils.saveNewRegistryLockRequest(DOMAIN_NAME, "TheRegistrar", POC_ID, false); domainLockUtils.saveNewRegistryLockRequest(DOMAIN_NAME, "TheRegistrar", POC_ID, false);
domainLockUtils.verifyAndApplyLock(lock.getVerificationCode(), false); domainLockUtils.verifyAndApplyLock(lock.getVerificationCode(), false);
domain = loadByEntity(domain); domain = loadByEntity(domain);
assertThat( IllegalArgumentException thrown =
assertThrows( assertThrows(
IllegalArgumentException.class, IllegalArgumentException.class,
() -> domainLockUtils.verifyAndApplyLock(lock.getVerificationCode(), false))) () -> domainLockUtils.verifyAndApplyLock(lock.getVerificationCode(), false));
.hasMessageThat() assertThat(thrown).hasMessageThat().isEqualTo("Domain example.tld is already locked");
.isEqualTo("Domain example.tld is already locked");
assertNoDomainChanges(); assertNoDomainChanges();
} }
@ -412,12 +410,11 @@ public final class DomainLockUtilsTest {
RegistryLock lock = RegistryLock lock =
domainLockUtils.saveNewRegistryLockRequest(DOMAIN_NAME, "TheRegistrar", POC_ID, false); domainLockUtils.saveNewRegistryLockRequest(DOMAIN_NAME, "TheRegistrar", POC_ID, false);
clock.advanceBy(standardDays(1)); clock.advanceBy(standardDays(1));
assertThat( IllegalArgumentException thrown =
assertThrows( assertThrows(
IllegalArgumentException.class, IllegalArgumentException.class,
() -> domainLockUtils.verifyAndApplyLock(lock.getVerificationCode(), true))) () -> domainLockUtils.verifyAndApplyLock(lock.getVerificationCode(), true));
.hasMessageThat() assertThat(thrown).hasMessageThat().isEqualTo("The pending lock has expired; please try again");
.isEqualTo("The pending lock has expired; please try again");
assertNoDomainChanges(); assertNoDomainChanges();
} }
@ -425,12 +422,11 @@ public final class DomainLockUtilsTest {
void testFailure_applyLock_nonAdmin_applyAdminLock() { void testFailure_applyLock_nonAdmin_applyAdminLock() {
RegistryLock lock = RegistryLock lock =
domainLockUtils.saveNewRegistryLockRequest(DOMAIN_NAME, "TheRegistrar", null, true); domainLockUtils.saveNewRegistryLockRequest(DOMAIN_NAME, "TheRegistrar", null, true);
assertThat( IllegalArgumentException thrown =
assertThrows( assertThrows(
IllegalArgumentException.class, IllegalArgumentException.class,
() -> domainLockUtils.verifyAndApplyLock(lock.getVerificationCode(), false))) () -> domainLockUtils.verifyAndApplyLock(lock.getVerificationCode(), false));
.hasMessageThat() assertThat(thrown).hasMessageThat().isEqualTo("Non-admin user cannot complete admin lock");
.isEqualTo("Non-admin user cannot complete admin lock");
assertNoDomainChanges(); assertNoDomainChanges();
} }
@ -444,12 +440,11 @@ public final class DomainLockUtilsTest {
DOMAIN_NAME, "TheRegistrar", false, Optional.empty()); DOMAIN_NAME, "TheRegistrar", false, Optional.empty());
domainLockUtils.verifyAndApplyUnlock(unlock.getVerificationCode(), false); domainLockUtils.verifyAndApplyUnlock(unlock.getVerificationCode(), false);
assertThat( IllegalArgumentException thrown =
assertThrows( assertThrows(
IllegalArgumentException.class, IllegalArgumentException.class,
() -> domainLockUtils.verifyAndApplyUnlock(unlock.getVerificationCode(), false))) () -> domainLockUtils.verifyAndApplyUnlock(unlock.getVerificationCode(), false));
.hasMessageThat() assertThat(thrown).hasMessageThat().isEqualTo("Domain example.tld is already unlocked");
.isEqualTo("Domain example.tld is already unlocked");
assertNoDomainChanges(); assertNoDomainChanges();
} }
@ -461,12 +456,11 @@ public final class DomainLockUtilsTest {
// reload to pick up modification times, etc // reload to pick up modification times, etc
lock = getRegistryLockByVerificationCode(verificationCode).get(); lock = getRegistryLockByVerificationCode(verificationCode).get();
domain = persistResource(domain.asBuilder().setStatusValues(REGISTRY_LOCK_STATUSES).build()); domain = persistResource(domain.asBuilder().setStatusValues(REGISTRY_LOCK_STATUSES).build());
assertThat( IllegalArgumentException thrown =
assertThrows( assertThrows(
IllegalArgumentException.class, IllegalArgumentException.class,
() -> domainLockUtils.verifyAndApplyLock(verificationCode, false))) () -> domainLockUtils.verifyAndApplyLock(verificationCode, false));
.hasMessageThat() assertThat(thrown).hasMessageThat().isEqualTo("Domain example.tld is already locked");
.isEqualTo("Domain example.tld is already locked");
// Failure during Datastore portion shouldn't affect the SQL object // Failure during Datastore portion shouldn't affect the SQL object
RegistryLock afterAction = getRegistryLockByVerificationCode(lock.getVerificationCode()).get(); RegistryLock afterAction = getRegistryLockByVerificationCode(lock.getVerificationCode()).get();
@ -517,10 +511,11 @@ public final class DomainLockUtilsTest {
.setRegistrarPocId("someone@example.com") .setRegistrarPocId("someone@example.com")
.setVerificationCode("hi") .setVerificationCode("hi")
.build()); .build());
assertThat( IllegalArgumentException thrown =
Assert.assertThrows( assertThrows(
IllegalArgumentException.class, IllegalArgumentException.class,
() -> domainLockUtils.enqueueDomainRelock(lockWithoutDuration))) () -> domainLockUtils.enqueueDomainRelock(lockWithoutDuration));
assertThat(thrown)
.hasMessageThat() .hasMessageThat()
.isEqualTo( .isEqualTo(
String.format( String.format(

View file

@ -139,14 +139,15 @@ public class SetDatabaseMigrationStateCommandTest
@TestOfyAndSql @TestOfyAndSql
void testFailure_invalidTransition() { void testFailure_invalidTransition() {
assertThat( IllegalArgumentException thrown =
assertThrows( assertThrows(
IllegalArgumentException.class, IllegalArgumentException.class,
() -> () ->
runCommandForced( runCommandForced(
String.format( String.format(
"--migration_schedule=%s=DATASTORE_ONLY,%s=DATASTORE_PRIMARY_READ_ONLY", "--migration_schedule=%s=DATASTORE_ONLY,%s=DATASTORE_PRIMARY_READ_ONLY",
START_OF_TIME, START_OF_TIME.plusHours(1))))) START_OF_TIME, START_OF_TIME.plusHours(1))));
assertThat(thrown)
.hasMessageThat() .hasMessageThat()
.isEqualTo( .isEqualTo(
"validStateTransitions map cannot transition from DATASTORE_ONLY " "validStateTransitions map cannot transition from DATASTORE_ONLY "
@ -158,7 +159,7 @@ public class SetDatabaseMigrationStateCommandTest
// The map we pass in is valid by itself, but we can't go from DATASTORE_ONLY now to // The map we pass in is valid by itself, but we can't go from DATASTORE_ONLY now to
// DATASTORE_PRIMARY_READ_ONLY now // DATASTORE_PRIMARY_READ_ONLY now
DateTime now = fakeClock.nowUtc(); DateTime now = fakeClock.nowUtc();
assertThat( IllegalArgumentException thrown =
assertThrows( assertThrows(
IllegalArgumentException.class, IllegalArgumentException.class,
() -> () ->
@ -166,10 +167,8 @@ public class SetDatabaseMigrationStateCommandTest
String.format( String.format(
"--migration_schedule=%s=DATASTORE_ONLY,%s=DATASTORE_PRIMARY," "--migration_schedule=%s=DATASTORE_ONLY,%s=DATASTORE_PRIMARY,"
+ "%s=DATASTORE_PRIMARY_NO_ASYNC,%s=DATASTORE_PRIMARY_READ_ONLY", + "%s=DATASTORE_PRIMARY_NO_ASYNC,%s=DATASTORE_PRIMARY_READ_ONLY",
START_OF_TIME, START_OF_TIME, now.minusHours(3), now.minusHours(2), now.minusHours(1))));
now.minusHours(3), assertThat(thrown)
now.minusHours(2),
now.minusHours(1)))))
.hasMessageThat() .hasMessageThat()
.isEqualTo( .isEqualTo(
"Cannot transition from current state-as-of-now DATASTORE_ONLY " "Cannot transition from current state-as-of-now DATASTORE_ONLY "

View file

@ -226,25 +226,22 @@ final class RegistryLockGetActionTest {
@Test @Test
void testFailure_invalidMethod() { void testFailure_invalidMethod() {
action.method = Method.POST; action.method = Method.POST;
assertThat(assertThrows(IllegalArgumentException.class, action::run)) IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, action::run);
.hasMessageThat() assertThat(thrown).hasMessageThat().isEqualTo("Only GET requests allowed");
.isEqualTo("Only GET requests allowed");
} }
@Test @Test
void testFailure_noAuthInfo() { void testFailure_noAuthInfo() {
action.authResult = AuthResult.NOT_AUTHENTICATED; action.authResult = AuthResult.NOT_AUTHENTICATED;
assertThat(assertThrows(IllegalArgumentException.class, action::run)) IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, action::run);
.hasMessageThat() assertThat(thrown).hasMessageThat().isEqualTo("User auth info must be present");
.isEqualTo("User auth info must be present");
} }
@Test @Test
void testFailure_noClientId() { void testFailure_noClientId() {
action.paramClientId = Optional.empty(); action.paramClientId = Optional.empty();
assertThat(assertThrows(IllegalArgumentException.class, action::run)) IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, action::run);
.hasMessageThat() assertThat(thrown).hasMessageThat().isEqualTo("clientId must be present");
.isEqualTo("clientId must be present");
} }
@Test @Test