Replace .get()).isEqualTo() with hasValue() (#1589)

* Replace .get()).isEqualTo() with hasValue()

* Use containsExactly for list comparison

* Fix spacing
This commit is contained in:
Rachel Guan 2022-04-18 18:35:46 -04:00 committed by GitHub
parent 9939833c25
commit 2a6d4298c6
7 changed files with 18 additions and 15 deletions

0
core/.attach_pid2322753 Normal file
View file

View file

@ -16,6 +16,7 @@ package google.registry.model.tld;
import static com.google.common.collect.ImmutableSet.toImmutableSet; import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.testing.SqlHelper.getMostRecentRegistryLockByRepoId; import static google.registry.testing.SqlHelper.getMostRecentRegistryLockByRepoId;
import static google.registry.testing.SqlHelper.getMostRecentUnlockedRegistryLockByRepoId; import static google.registry.testing.SqlHelper.getMostRecentUnlockedRegistryLockByRepoId;
@ -67,7 +68,7 @@ public final class RegistryLockDaoTest extends EntityTestCase {
() -> { () -> {
RegistryLock fromDatabase = RegistryLock fromDatabase =
RegistryLockDao.getByVerificationCode(lock.getVerificationCode()).get(); RegistryLockDao.getByVerificationCode(lock.getVerificationCode()).get();
assertThat(fromDatabase.getLockCompletionTime().get()).isEqualTo(fakeClock.nowUtc()); assertThat(fromDatabase.getLockCompletionTime()).hasValue(fakeClock.nowUtc());
assertThat(fromDatabase.getLastUpdateTime()).isEqualTo(fakeClock.nowUtc()); assertThat(fromDatabase.getLastUpdateTime()).isEqualTo(fakeClock.nowUtc());
}); });
} }
@ -87,7 +88,7 @@ public final class RegistryLockDaoTest extends EntityTestCase {
assertThat(fromDatabase.getUnlockRequestTime()).isEqualTo(Optional.of(fakeClock.nowUtc())); assertThat(fromDatabase.getUnlockRequestTime()).isEqualTo(Optional.of(fakeClock.nowUtc()));
assertThat(fromDatabase.getUnlockCompletionTime()).isEqualTo(Optional.of(fakeClock.nowUtc())); assertThat(fromDatabase.getUnlockCompletionTime()).isEqualTo(Optional.of(fakeClock.nowUtc()));
assertThat(fromDatabase.isLocked()).isFalse(); assertThat(fromDatabase.isLocked()).isFalse();
assertThat(fromDatabase.getRelockDuration().get()).isEqualTo(Duration.standardHours(6)); assertThat(fromDatabase.getRelockDuration()).hasValue(Duration.standardHours(6));
} }
@Test @Test

View file

@ -261,8 +261,8 @@ public final class RegistryTest extends EntityTestCase {
Registry registry = Registry.get("tld").asBuilder().setPremiumList(pl2).build(); Registry registry = Registry.get("tld").asBuilder().setPremiumList(pl2).build();
Optional<String> pl = registry.getPremiumListName(); Optional<String> pl = registry.getPremiumListName();
assertThat(pl).hasValue("tld2"); assertThat(pl).hasValue("tld2");
PremiumList stored = PremiumListDao.getLatestRevision(pl.get()).get(); assertThat(PremiumListDao.getLatestRevision("tld2")).isPresent();
assertThat(stored.getName()).isEqualTo("tld2"); assertThat(PremiumListDao.getLatestRevision("tld2").get().getName()).isEqualTo("tld2");
} }
@TestOfyAndSql @TestOfyAndSql

View file

@ -261,7 +261,7 @@ public class PremiumListDaoTest {
assertThat(PremiumListDao.premiumListCache.getIfPresent("testname")).isNull(); assertThat(PremiumListDao.premiumListCache.getIfPresent("testname")).isNull();
PremiumListDao.save(testList); PremiumListDao.save(testList);
PremiumList pl = PremiumListDao.getLatestRevision("testname").get(); PremiumList pl = PremiumListDao.getLatestRevision("testname").get();
assertThat(PremiumListDao.premiumListCache.getIfPresent("testname").get()).isEqualTo(pl); assertThat(PremiumListDao.premiumListCache.getIfPresent("testname")).hasValue(pl);
TransactionManagerUtil.transactIfJpaTm( TransactionManagerUtil.transactIfJpaTm(
() -> PremiumListDao.save("testname", USD, ImmutableList.of("test,USD 1"))); () -> PremiumListDao.save("testname", USD, ImmutableList.of("test,USD 1")));
assertThat(PremiumListDao.premiumListCache.getIfPresent("testname")).isNull(); assertThat(PremiumListDao.premiumListCache.getIfPresent("testname")).isNull();

View file

@ -16,6 +16,7 @@ package google.registry.model.tld.label;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage; import static com.google.common.truth.Truth.assertWithMessage;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.testing.DatabaseHelper.createTld; import static google.registry.testing.DatabaseHelper.createTld;
import static google.registry.testing.DatabaseHelper.persistPremiumList; import static google.registry.testing.DatabaseHelper.persistPremiumList;
import static google.registry.testing.DatabaseHelper.persistReservedList; import static google.registry.testing.DatabaseHelper.persistReservedList;
@ -100,8 +101,8 @@ public class PremiumListTest {
@Test @Test
void testParse_canIncludeOrNotIncludeCurrencyUnit() { void testParse_canIncludeOrNotIncludeCurrencyUnit() {
PremiumListDao.save("tld", USD, ImmutableList.of("rofl,USD 90", "paper, 80")); PremiumListDao.save("tld", USD, ImmutableList.of("rofl,USD 90", "paper, 80"));
assertThat(PremiumListDao.getPremiumPrice("tld", "rofl").get()).isEqualTo(Money.of(USD, 90)); assertThat(PremiumListDao.getPremiumPrice("tld", "rofl")).hasValue(Money.of(USD, 90));
assertThat(PremiumListDao.getPremiumPrice("tld", "paper").get()).isEqualTo(Money.of(USD, 80)); assertThat(PremiumListDao.getPremiumPrice("tld", "paper")).hasValue(Money.of(USD, 80));
} }
@Test @Test

View file

@ -15,9 +15,9 @@
package google.registry.model.tmch; package google.registry.model.tmch;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import google.registry.model.EntityTestCase; import google.registry.model.EntityTestCase;
import java.util.Optional;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
/** Unit tests for {@link TmchCrl}. */ /** Unit tests for {@link TmchCrl}. */
@ -29,7 +29,7 @@ public class TmchCrlTest extends EntityTestCase {
@Test @Test
void testSuccess() { void testSuccess() {
assertThat(TmchCrl.get()).isEqualTo(Optional.empty()); assertThat(TmchCrl.get()).isEmpty();
TmchCrl.set("lolcat", "https://lol.cat"); TmchCrl.set("lolcat", "https://lol.cat");
assertThat(TmchCrl.get().get().getCrl()).isEqualTo("lolcat"); assertThat(TmchCrl.get().get().getCrl()).isEqualTo("lolcat");
} }

View file

@ -51,7 +51,7 @@ class FormFieldTest {
@Test @Test
void testConvert_emptyString_returnsEmpty() { void testConvert_emptyString_returnsEmpty() {
assertThat(FormField.named("lol").build().convert("").get()).isEmpty(); assertThat(FormField.named("lol").build().convert("")).hasValue("");
} }
@Test @Test
@ -249,7 +249,8 @@ class FormFieldTest {
@Test @Test
void testAsList_empty_returnsEmpty() { void testAsList_empty_returnsEmpty() {
assertThat(FormField.named("lol").asList().build().convert(ImmutableList.of()).get()).isEmpty(); assertThat(FormField.named("lol").asList().build().convert(ImmutableList.of()))
.hasValue(ImmutableList.of());
} }
@Test @Test
@ -277,16 +278,16 @@ class FormFieldTest {
void testAsEnum() { void testAsEnum() {
FormField<String, ICanHazEnum> omgField = FormField<String, ICanHazEnum> omgField =
FormField.named("omg").asEnum(ICanHazEnum.class).build(); FormField.named("omg").asEnum(ICanHazEnum.class).build();
assertThat(omgField.convert("LOL").get()).isEqualTo(ICanHazEnum.LOL); assertThat(omgField.convert("LOL")).hasValue(ICanHazEnum.LOL);
assertThat(omgField.convert("CAT").get()).isEqualTo(ICanHazEnum.CAT); assertThat(omgField.convert("CAT")).hasValue(ICanHazEnum.CAT);
} }
@Test @Test
void testAsEnum_lowercase_works() { void testAsEnum_lowercase_works() {
FormField<String, ICanHazEnum> omgField = FormField<String, ICanHazEnum> omgField =
FormField.named("omg").asEnum(ICanHazEnum.class).build(); FormField.named("omg").asEnum(ICanHazEnum.class).build();
assertThat(omgField.convert("lol").get()).isEqualTo(ICanHazEnum.LOL); assertThat(omgField.convert("lol")).hasValue(ICanHazEnum.LOL);
assertThat(omgField.convert("cat").get()).isEqualTo(ICanHazEnum.CAT); assertThat(omgField.convert("cat")).hasValue(ICanHazEnum.CAT);
} }
@Test @Test