diff --git a/core/src/test/java/google/registry/batch/DeleteProberDataActionTest.java b/core/src/test/java/google/registry/batch/DeleteProberDataActionTest.java index f83f1ed54..0153110b4 100644 --- a/core/src/test/java/google/registry/batch/DeleteProberDataActionTest.java +++ b/core/src/test/java/google/registry/batch/DeleteProberDataActionTest.java @@ -46,7 +46,7 @@ import google.registry.model.registry.Registry; import google.registry.model.registry.Registry.TldType; import google.registry.model.reporting.HistoryEntry; import google.registry.testing.FakeResponse; -import google.registry.testing.SystemPropertyRule; +import google.registry.testing.SystemPropertyExtension; import google.registry.testing.mapreduce.MapreduceTestCase; import java.util.Optional; import java.util.Set; @@ -61,7 +61,8 @@ class DeleteProberDataActionTest extends MapreduceTestCase jpaTm().saveNew(testPersist)); checkAll(testPersist, 1, 0, 0, 0); @@ -84,7 +81,7 @@ public class EntityCallbacksListenerTest { } @Test - public void verifyAllManagedEntities_haveNoMethodWithEmbedded() { + void verifyAllManagedEntities_haveNoMethodWithEmbedded() { ImmutableSet violations = PersistenceXmlUtility.getManagedClasses().stream() .filter(clazz -> clazz.isAnnotationPresent(Entity.class)) @@ -98,7 +95,7 @@ public class EntityCallbacksListenerTest { } @Test - public void verifyHasMethodAnnotatedWithEmbedded_work() { + void verifyHasMethodAnnotatedWithEmbedded_work() { assertThat(hasMethodAnnotatedWithEmbedded(ViolationEntity.class)).isTrue(); } diff --git a/core/src/test/java/google/registry/persistence/converter/BillingCostTransitionConverterTest.java b/core/src/test/java/google/registry/persistence/converter/BillingCostTransitionConverterTest.java index c3457a105..2c8665646 100644 --- a/core/src/test/java/google/registry/persistence/converter/BillingCostTransitionConverterTest.java +++ b/core/src/test/java/google/registry/persistence/converter/BillingCostTransitionConverterTest.java @@ -24,7 +24,7 @@ import google.registry.model.ImmutableObject; import google.registry.model.common.TimedTransitionProperty; import google.registry.model.registry.Registry.BillingCostTransition; import google.registry.persistence.transaction.JpaTestRules; -import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestRule; +import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestExtension; import javax.persistence.Entity; import javax.persistence.Id; import org.joda.money.Money; @@ -36,7 +36,7 @@ import org.junit.jupiter.api.extension.RegisterExtension; public class BillingCostTransitionConverterTest { @RegisterExtension - public final JpaUnitTestRule jpa = + public final JpaUnitTestExtension jpa = new JpaTestRules.Builder() .withInitScript("sql/flyway/V14__load_extension_for_hstore.sql") .withEntityClass(TestEntity.class) diff --git a/core/src/test/java/google/registry/persistence/converter/BloomFilterConverterTest.java b/core/src/test/java/google/registry/persistence/converter/BloomFilterConverterTest.java index 91eb2551a..a3753d899 100644 --- a/core/src/test/java/google/registry/persistence/converter/BloomFilterConverterTest.java +++ b/core/src/test/java/google/registry/persistence/converter/BloomFilterConverterTest.java @@ -22,25 +22,22 @@ import com.google.common.collect.ImmutableSet; import com.google.common.hash.BloomFilter; import google.registry.model.ImmutableObject; import google.registry.persistence.transaction.JpaTestRules; -import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestRule; +import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestExtension; import google.registry.schema.replay.EntityTest.EntityForTesting; import javax.persistence.Entity; import javax.persistence.Id; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; /** Unit tests for {@link BloomFilterConverter}. */ -@RunWith(JUnit4.class) -public class BloomFilterConverterTest { +class BloomFilterConverterTest { - @Rule - public final JpaUnitTestRule jpaRule = + @RegisterExtension + public final JpaUnitTestExtension jpaExtension = new JpaTestRules.Builder().withEntityClass(TestEntity.class).buildUnitTestRule(); @Test - public void roundTripConversion_returnsSameBloomFilter() { + void roundTripConversion_returnsSameBloomFilter() { BloomFilter bloomFilter = BloomFilter.create(stringFunnel(US_ASCII), 3); ImmutableSet.of("foo", "bar", "baz").forEach(bloomFilter::put); TestEntity entity = new TestEntity(bloomFilter); diff --git a/core/src/test/java/google/registry/persistence/converter/CidrAddressBlockListConverterTest.java b/core/src/test/java/google/registry/persistence/converter/CidrAddressBlockListConverterTest.java index 7287d58df..71da05235 100644 --- a/core/src/test/java/google/registry/persistence/converter/CidrAddressBlockListConverterTest.java +++ b/core/src/test/java/google/registry/persistence/converter/CidrAddressBlockListConverterTest.java @@ -20,25 +20,23 @@ import static google.registry.persistence.transaction.TransactionManagerFactory. import com.google.common.collect.ImmutableList; import google.registry.model.ImmutableObject; import google.registry.persistence.transaction.JpaTestRules; -import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestRule; +import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestExtension; import google.registry.util.CidrAddressBlock; import java.util.List; import javax.persistence.Entity; import javax.persistence.Id; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; /** Unit tests for {@link CidrAddressBlockListConverter}. */ -@RunWith(JUnit4.class) public class CidrAddressBlockListConverterTest { - @Rule - public final JpaUnitTestRule jpaRule = + + @RegisterExtension + public final JpaUnitTestExtension jpaExtension = new JpaTestRules.Builder().withEntityClass(TestEntity.class).buildUnitTestRule(); @Test - public void roundTripConversion_returnsSameCidrAddressBlock() { + void roundTripConversion_returnsSameCidrAddressBlock() { List addresses = ImmutableList.of( CidrAddressBlock.create("0.0.0.0/32"), diff --git a/core/src/test/java/google/registry/persistence/converter/CreateAutoTimestampConverterTest.java b/core/src/test/java/google/registry/persistence/converter/CreateAutoTimestampConverterTest.java index b75753d88..65be75b27 100644 --- a/core/src/test/java/google/registry/persistence/converter/CreateAutoTimestampConverterTest.java +++ b/core/src/test/java/google/registry/persistence/converter/CreateAutoTimestampConverterTest.java @@ -19,32 +19,29 @@ import static google.registry.persistence.transaction.TransactionManagerFactory. import google.registry.model.CreateAutoTimestamp; import google.registry.model.ImmutableObject; import google.registry.persistence.transaction.JpaTestRules; -import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestRule; +import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestExtension; import google.registry.schema.replay.EntityTest.EntityForTesting; import google.registry.testing.FakeClock; import javax.persistence.Entity; import javax.persistence.Id; import org.joda.time.DateTime; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; /** Unit tests for {@link CreateAutoTimestampConverter}. */ -@RunWith(JUnit4.class) public class CreateAutoTimestampConverterTest { private final FakeClock fakeClock = new FakeClock(); - @Rule - public final JpaUnitTestRule jpaRule = + @RegisterExtension + public final JpaUnitTestExtension jpaExtension = new JpaTestRules.Builder() .withClock(fakeClock) .withEntityClass(TestEntity.class) .buildUnitTestRule(); @Test - public void testTypeConversion() { + void testTypeConversion() { CreateAutoTimestamp ts = CreateAutoTimestamp.create(DateTime.parse("2019-09-9T11:39:00Z")); TestEntity ent = new TestEntity("myinst", ts); @@ -55,7 +52,7 @@ public class CreateAutoTimestampConverterTest { } @Test - public void testAutoInitialization() { + void testAutoInitialization() { CreateAutoTimestamp ts = CreateAutoTimestamp.create(null); TestEntity ent = new TestEntity("autoinit", ts); diff --git a/core/src/test/java/google/registry/persistence/converter/CurrencyToBillingConverterTest.java b/core/src/test/java/google/registry/persistence/converter/CurrencyToBillingConverterTest.java index 1682c41ed..65b05af12 100644 --- a/core/src/test/java/google/registry/persistence/converter/CurrencyToBillingConverterTest.java +++ b/core/src/test/java/google/registry/persistence/converter/CurrencyToBillingConverterTest.java @@ -21,28 +21,26 @@ import com.google.common.collect.ImmutableMap; import google.registry.model.ImmutableObject; import google.registry.model.registrar.Registrar.BillingAccountEntry; import google.registry.persistence.transaction.JpaTestRules; -import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestRule; +import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestExtension; import java.util.Map; import javax.persistence.Entity; import javax.persistence.Id; import org.joda.money.CurrencyUnit; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; /** Unit tests for {@link CurrencyToBillingConverter}. */ -@RunWith(JUnit4.class) public class CurrencyToBillingConverterTest { - @Rule - public final JpaUnitTestRule jpaRule = + + @RegisterExtension + public final JpaUnitTestExtension jpaExtension = new JpaTestRules.Builder() .withInitScript("sql/flyway/V14__load_extension_for_hstore.sql") .withEntityClass(TestEntity.class) .buildUnitTestRule(); @Test - public void roundTripConversion_returnsSameCurrencyToBillingMap() { + void roundTripConversion_returnsSameCurrencyToBillingMap() { ImmutableMap currencyToBilling = ImmutableMap.of( CurrencyUnit.of("USD"), diff --git a/core/src/test/java/google/registry/persistence/converter/CurrencyUnitConverterTest.java b/core/src/test/java/google/registry/persistence/converter/CurrencyUnitConverterTest.java index 790e25b74..e09d60100 100644 --- a/core/src/test/java/google/registry/persistence/converter/CurrencyUnitConverterTest.java +++ b/core/src/test/java/google/registry/persistence/converter/CurrencyUnitConverterTest.java @@ -20,27 +20,24 @@ import static org.junit.Assert.assertThrows; import google.registry.model.ImmutableObject; import google.registry.persistence.transaction.JpaTestRules; -import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestRule; +import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestExtension; import google.registry.schema.replay.EntityTest.EntityForTesting; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.PersistenceException; import org.joda.money.CurrencyUnit; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; /** Unit tests for {@link CurrencyUnitConverter}. */ -@RunWith(JUnit4.class) public class CurrencyUnitConverterTest { - @Rule - public final JpaUnitTestRule jpaRule = + @RegisterExtension + public final JpaUnitTestExtension jpaExtension = new JpaTestRules.Builder().withEntityClass(TestEntity.class).buildUnitTestRule(); @Test - public void roundTripConversion() { + void roundTripConversion() { TestEntity entity = new TestEntity(CurrencyUnit.EUR); jpaTm().transact(() -> jpaTm().getEntityManager().persist(entity)); assertThat( @@ -59,7 +56,7 @@ public class CurrencyUnitConverterTest { } @Test - public void invalidCurrency() { + void invalidCurrency() { jpaTm() .transact( () -> diff --git a/core/src/test/java/google/registry/persistence/converter/DateTimeConverterTest.java b/core/src/test/java/google/registry/persistence/converter/DateTimeConverterTest.java index bc3066fe6..e971514aa 100644 --- a/core/src/test/java/google/registry/persistence/converter/DateTimeConverterTest.java +++ b/core/src/test/java/google/registry/persistence/converter/DateTimeConverterTest.java @@ -19,46 +19,43 @@ import static google.registry.persistence.transaction.TransactionManagerFactory. import google.registry.model.ImmutableObject; import google.registry.persistence.transaction.JpaTestRules; -import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestRule; +import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestExtension; import java.sql.Timestamp; import javax.persistence.Entity; import javax.persistence.Id; import org.joda.time.DateTime; import org.joda.time.format.ISODateTimeFormat; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; /** Unit tests for {@link DateTimeConverter}. */ -@RunWith(JUnit4.class) public class DateTimeConverterTest { - @Rule - public final JpaUnitTestRule jpaRule = + @RegisterExtension + public final JpaUnitTestExtension jpaExtension = new JpaTestRules.Builder().withEntityClass(TestEntity.class).buildUnitTestRule(); private final DateTimeConverter converter = new DateTimeConverter(); @Test - public void convertToDatabaseColumn_returnsNullIfInputIsNull() { + void convertToDatabaseColumn_returnsNullIfInputIsNull() { assertThat(converter.convertToDatabaseColumn(null)).isNull(); } @Test - public void convertToDatabaseColumn_convertsCorrectly() { + void convertToDatabaseColumn_convertsCorrectly() { DateTime dateTime = DateTime.parse("2019-09-01T01:01:01"); assertThat(converter.convertToDatabaseColumn(dateTime).getTime()) .isEqualTo(dateTime.getMillis()); } @Test - public void convertToEntityAttribute_returnsNullIfInputIsNull() { + void convertToEntityAttribute_returnsNullIfInputIsNull() { assertThat(converter.convertToEntityAttribute(null)).isNull(); } @Test - public void convertToEntityAttribute_convertsCorrectly() { + void convertToEntityAttribute_convertsCorrectly() { DateTime dateTime = DateTime.parse("2019-09-01T01:01:01Z"); long millis = dateTime.getMillis(); assertThat(converter.convertToEntityAttribute(new Timestamp(millis))).isEqualTo(dateTime); @@ -69,7 +66,7 @@ public class DateTimeConverterTest { } @Test - public void converter_generatesTimestampWithNormalizedZone() { + void converter_generatesTimestampWithNormalizedZone() { DateTime dt = parseDateTime("2019-09-01T01:01:01Z"); TestEntity entity = new TestEntity("normalized_utc_time", dt); jpaTm().transact(() -> jpaTm().getEntityManager().persist(entity)); @@ -81,7 +78,7 @@ public class DateTimeConverterTest { } @Test - public void converter_convertsNonUtcZoneCorrectly() { + void converter_convertsNonUtcZoneCorrectly() { DateTime dt = parseDateTime("2019-09-01T01:01:01-05:00"); TestEntity entity = new TestEntity("new_york_time", dt); diff --git a/core/src/test/java/google/registry/persistence/converter/DurationConverterTest.java b/core/src/test/java/google/registry/persistence/converter/DurationConverterTest.java index c87b2e2c6..01f2d1992 100644 --- a/core/src/test/java/google/registry/persistence/converter/DurationConverterTest.java +++ b/core/src/test/java/google/registry/persistence/converter/DurationConverterTest.java @@ -19,35 +19,32 @@ import static google.registry.persistence.transaction.TransactionManagerFactory. import google.registry.model.ImmutableObject; import google.registry.persistence.transaction.JpaTestRules; -import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestRule; +import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestExtension; import google.registry.schema.replay.EntityTest.EntityForTesting; import java.math.BigInteger; import javax.persistence.Entity; import javax.persistence.Id; import org.joda.time.Duration; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; /** Unit tests for {@link DurationConverter}. */ -@RunWith(JUnit4.class) public class DurationConverterTest { - @Rule - public final JpaUnitTestRule jpaRule = + @RegisterExtension + public final JpaUnitTestExtension jpaExtension = new JpaTestRules.Builder().withEntityClass(TestEntity.class).buildUnitTestRule(); private final DurationConverter converter = new DurationConverter(); @Test - public void testNulls() { + void testNulls() { assertThat(converter.convertToDatabaseColumn(null)).isNull(); assertThat(converter.convertToEntityAttribute(null)).isNull(); } @Test - public void testRoundTrip() { + void testRoundTrip() { TestEntity entity = new TestEntity(Duration.standardDays(6)); jpaTm().transact(() -> jpaTm().getEntityManager().persist(entity)); assertThat( diff --git a/core/src/test/java/google/registry/persistence/converter/InetAddressSetConverterTest.java b/core/src/test/java/google/registry/persistence/converter/InetAddressSetConverterTest.java index 05f9c9594..308015dda 100644 --- a/core/src/test/java/google/registry/persistence/converter/InetAddressSetConverterTest.java +++ b/core/src/test/java/google/registry/persistence/converter/InetAddressSetConverterTest.java @@ -42,7 +42,7 @@ public class InetAddressSetConverterTest { .build(); @Test - public void roundTripConversion_returnsSameAddresses() { + void roundTripConversion_returnsSameAddresses() { verifySaveAndLoad( ImmutableSet.of( InetAddresses.forString("0.0.0.0"), @@ -52,12 +52,12 @@ public class InetAddressSetConverterTest { } @Test - public void roundTrip_emptySet() { + void roundTrip_emptySet() { verifySaveAndLoad(ImmutableSet.of()); } @Test - public void roundTrip_null() { + void roundTrip_null() { verifySaveAndLoad(null); } diff --git a/core/src/test/java/google/registry/persistence/converter/JodaMoneyConverterTest.java b/core/src/test/java/google/registry/persistence/converter/JodaMoneyConverterTest.java index 67eff7ffd..84852931f 100644 --- a/core/src/test/java/google/registry/persistence/converter/JodaMoneyConverterTest.java +++ b/core/src/test/java/google/registry/persistence/converter/JodaMoneyConverterTest.java @@ -19,7 +19,7 @@ import static google.registry.persistence.transaction.TransactionManagerFactory. import com.google.common.collect.ImmutableMap; import google.registry.model.ImmutableObject; import google.registry.persistence.transaction.JpaTestRules; -import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestRule; +import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestExtension; import google.registry.schema.replay.EntityTest.EntityForTesting; import java.math.BigDecimal; import java.util.Arrays; @@ -38,10 +38,8 @@ import javax.persistence.MapKeyColumn; import javax.persistence.PostLoad; import org.joda.money.CurrencyUnit; import org.joda.money.Money; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; /** * Unit tests for embeddable {@link Money}. @@ -61,16 +59,16 @@ import org.junit.runners.JUnit4; * appropriate for the currency. This is espcially necessary for currencies like JPY where the scale * is 0, which is different from the default scale that {@link BigDecimal} is persisted in database. */ -@RunWith(JUnit4.class) public class JodaMoneyConverterTest { - @Rule - public final JpaUnitTestRule jpaRule = + + @RegisterExtension + public final JpaUnitTestExtension jpaExtension = new JpaTestRules.Builder() .withEntityClass(TestEntity.class, ComplexTestEntity.class) .buildUnitTestRule(); @Test - public void roundTripConversion() { + void roundTripConversion() { Money money = Money.of(CurrencyUnit.USD, 100); TestEntity entity = new TestEntity(money); jpaTm().transact(() -> jpaTm().getEntityManager().persist(entity)); @@ -94,7 +92,7 @@ public class JodaMoneyConverterTest { } @Test - public void roundTripConversionWithComplexEntity() { + void roundTripConversionWithComplexEntity() { Money myMoney = Money.of(CurrencyUnit.USD, 100); Money yourMoney = Money.of(CurrencyUnit.GBP, 80); ImmutableMap moneyMap = diff --git a/core/src/test/java/google/registry/persistence/converter/LocalDateConverterTest.java b/core/src/test/java/google/registry/persistence/converter/LocalDateConverterTest.java index 2310f2548..257e8f881 100644 --- a/core/src/test/java/google/registry/persistence/converter/LocalDateConverterTest.java +++ b/core/src/test/java/google/registry/persistence/converter/LocalDateConverterTest.java @@ -20,7 +20,7 @@ import static google.registry.persistence.transaction.TransactionManagerFactory. import google.registry.model.ImmutableObject; import google.registry.persistence.VKey; import google.registry.persistence.transaction.JpaTestRules; -import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestRule; +import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestExtension; import google.registry.schema.replay.EntityTest; import javax.persistence.Entity; import javax.persistence.Id; @@ -33,7 +33,7 @@ import org.junit.jupiter.api.extension.RegisterExtension; public class LocalDateConverterTest { @RegisterExtension - public final JpaUnitTestRule jpaRule = + public final JpaUnitTestExtension jpaExtension = new JpaTestRules.Builder() .withEntityClass(LocalDateConverterTestEntity.class) .buildUnitTestRule(); @@ -41,13 +41,13 @@ public class LocalDateConverterTest { private final LocalDate exampleDate = LocalDate.parse("2020-06-10", ISODateTimeFormat.date()); @Test - public void testNullInput() { + void testNullInput() { LocalDateConverterTestEntity retrievedEntity = persistAndLoadTestEntity(null); assertThat(retrievedEntity.date).isNull(); } @Test - public void testSaveAndLoad_success() { + void testSaveAndLoad_success() { LocalDateConverterTestEntity retrievedEntity = persistAndLoadTestEntity(exampleDate); assertThat(retrievedEntity.date).isEqualTo(exampleDate); } diff --git a/core/src/test/java/google/registry/persistence/converter/LongVKeyConverterTest.java b/core/src/test/java/google/registry/persistence/converter/LongVKeyConverterTest.java index 149f0b108..4e7544e47 100644 --- a/core/src/test/java/google/registry/persistence/converter/LongVKeyConverterTest.java +++ b/core/src/test/java/google/registry/persistence/converter/LongVKeyConverterTest.java @@ -20,26 +20,23 @@ import static google.registry.persistence.transaction.TransactionManagerFactory. import google.registry.persistence.VKey; import google.registry.persistence.WithLongVKey; import google.registry.persistence.transaction.JpaTestRules; -import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestRule; +import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestExtension; import javax.persistence.Entity; import javax.persistence.Id; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; /** Test SQL persistence of VKey. */ -@RunWith(JUnit4.class) public class LongVKeyConverterTest { - @Rule - public final JpaUnitTestRule jpaRule = + @RegisterExtension + public final JpaUnitTestExtension jpaExtension = new JpaTestRules.Builder() .withEntityClass(TestEntity.class, VKeyConverter_LongType.class) .buildUnitTestRule(); @Test - public void testRoundTrip() { + void testRoundTrip() { TestEntity original = new TestEntity(VKey.createSql(TestEntity.class, 10L)); jpaTm().transact(() -> jpaTm().getEntityManager().persist(original)); diff --git a/core/src/test/java/google/registry/persistence/converter/StatusValueSetConverterTest.java b/core/src/test/java/google/registry/persistence/converter/StatusValueSetConverterTest.java index c86819107..1c59685e9 100644 --- a/core/src/test/java/google/registry/persistence/converter/StatusValueSetConverterTest.java +++ b/core/src/test/java/google/registry/persistence/converter/StatusValueSetConverterTest.java @@ -20,24 +20,22 @@ import static google.registry.persistence.transaction.TransactionManagerFactory. import com.google.common.collect.ImmutableSet; import google.registry.model.eppcommon.StatusValue; import google.registry.persistence.transaction.JpaTestRules; -import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestRule; +import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestExtension; import java.util.Set; import javax.persistence.Entity; import javax.persistence.Id; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; /** Unit tests for {@link StatusValueSetConverter}. */ -@RunWith(JUnit4.class) public class StatusValueSetConverterTest { - @Rule - public final JpaUnitTestRule jpaRule = + + @RegisterExtension + public final JpaUnitTestExtension jpaExtension = new JpaTestRules.Builder().withEntityClass(TestEntity.class).buildUnitTestRule(); @Test - public void testRoundTrip() { + void testRoundTrip() { Set enums = ImmutableSet.of(StatusValue.INACTIVE, StatusValue.PENDING_DELETE); TestEntity obj = new TestEntity("foo", enums); diff --git a/core/src/test/java/google/registry/persistence/converter/StringListConverterTest.java b/core/src/test/java/google/registry/persistence/converter/StringListConverterTest.java index c39e12f18..c61ecafc4 100644 --- a/core/src/test/java/google/registry/persistence/converter/StringListConverterTest.java +++ b/core/src/test/java/google/registry/persistence/converter/StringListConverterTest.java @@ -21,25 +21,23 @@ import static org.junit.Assert.assertThrows; import com.google.common.collect.ImmutableList; import google.registry.model.ImmutableObject; import google.registry.persistence.transaction.JpaTestRules; -import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestRule; +import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestExtension; import java.util.List; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.NoResultException; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; /** Unit tests for {@link StringListConverter}. */ -@RunWith(JUnit4.class) public class StringListConverterTest { - @Rule - public final JpaUnitTestRule jpaRule = + + @RegisterExtension + public final JpaUnitTestExtension jpaExtension = new JpaTestRules.Builder().withEntityClass(TestEntity.class).buildUnitTestRule(); @Test - public void roundTripConversion_returnsSameStringList() { + void roundTripConversion_returnsSameStringList() { List tlds = ImmutableList.of("app", "dev", "how"); TestEntity testEntity = new TestEntity(tlds); jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity)); @@ -49,7 +47,7 @@ public class StringListConverterTest { } @Test - public void testMerge_succeeds() { + void testMerge_succeeds() { List tlds = ImmutableList.of("app", "dev", "how"); TestEntity testEntity = new TestEntity(tlds); jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity)); @@ -63,7 +61,7 @@ public class StringListConverterTest { } @Test - public void testNullValue_writesAndReadsNullSuccessfully() { + void testNullValue_writesAndReadsNullSuccessfully() { TestEntity testEntity = new TestEntity(null); jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity)); TestEntity persisted = @@ -72,7 +70,7 @@ public class StringListConverterTest { } @Test - public void testEmptyCollection_writesAndReadsEmptyCollectionSuccessfully() { + void testEmptyCollection_writesAndReadsEmptyCollectionSuccessfully() { TestEntity testEntity = new TestEntity(ImmutableList.of()); jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity)); TestEntity persisted = @@ -81,7 +79,7 @@ public class StringListConverterTest { } @Test - public void testNativeQuery_succeeds() throws Exception { + void testNativeQuery_succeeds() throws Exception { executeNativeQuery("INSERT INTO \"TestEntity\" (name, tlds) VALUES ('id', '{app, dev}')"); assertThat( diff --git a/core/src/test/java/google/registry/persistence/converter/StringMapConverterBaseTest.java b/core/src/test/java/google/registry/persistence/converter/StringMapConverterBaseTest.java index 61749e952..8c323a66d 100644 --- a/core/src/test/java/google/registry/persistence/converter/StringMapConverterBaseTest.java +++ b/core/src/test/java/google/registry/persistence/converter/StringMapConverterBaseTest.java @@ -22,21 +22,20 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; import google.registry.model.ImmutableObject; import google.registry.persistence.transaction.JpaTestRules; +import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestExtension; import java.util.Map; import javax.persistence.Converter; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.NoResultException; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; /** Unit tests for {@link StringMapConverterBase}. */ -@RunWith(JUnit4.class) public class StringMapConverterBaseTest { - @Rule - public final JpaTestRules.JpaUnitTestRule jpaRule = + + @RegisterExtension + public final JpaUnitTestExtension jpaExtension = new JpaTestRules.Builder() .withInitScript("sql/flyway/V14__load_extension_for_hstore.sql") .withEntityClass(TestStringMapConverter.class, TestEntity.class) @@ -49,7 +48,7 @@ public class StringMapConverterBaseTest { new Key("key3"), new Value("value3")); @Test - public void roundTripConversion_returnsSameMap() { + void roundTripConversion_returnsSameMap() { TestEntity testEntity = new TestEntity(MAP); jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity)); TestEntity persisted = @@ -58,7 +57,7 @@ public class StringMapConverterBaseTest { } @Test - public void testUpdateColumn_succeeds() { + void testUpdateColumn_succeeds() { TestEntity testEntity = new TestEntity(MAP); jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity)); TestEntity persisted = @@ -72,7 +71,7 @@ public class StringMapConverterBaseTest { } @Test - public void testNullValue_writesAndReadsNullSuccessfully() { + void testNullValue_writesAndReadsNullSuccessfully() { TestEntity testEntity = new TestEntity(null); jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity)); TestEntity persisted = @@ -81,7 +80,7 @@ public class StringMapConverterBaseTest { } @Test - public void testEmptyMap_writesAndReadsEmptyCollectionSuccessfully() { + void testEmptyMap_writesAndReadsEmptyCollectionSuccessfully() { TestEntity testEntity = new TestEntity(ImmutableMap.of()); jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity)); TestEntity persisted = @@ -90,7 +89,7 @@ public class StringMapConverterBaseTest { } @Test - public void testNativeQuery_succeeds() { + void testNativeQuery_succeeds() { executeNativeQuery( "INSERT INTO \"TestEntity\" (name, map) VALUES ('id', 'key1=>value1, key2=>value2')"); diff --git a/core/src/test/java/google/registry/persistence/converter/StringSetConverterTest.java b/core/src/test/java/google/registry/persistence/converter/StringSetConverterTest.java index ae862967f..9f8b29c4f 100644 --- a/core/src/test/java/google/registry/persistence/converter/StringSetConverterTest.java +++ b/core/src/test/java/google/registry/persistence/converter/StringSetConverterTest.java @@ -20,24 +20,22 @@ import static google.registry.persistence.transaction.TransactionManagerFactory. import com.google.common.collect.ImmutableSet; import google.registry.model.ImmutableObject; import google.registry.persistence.transaction.JpaTestRules; -import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestRule; +import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestExtension; import java.util.Set; import javax.persistence.Entity; import javax.persistence.Id; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; /** Unit tests for {@link StringSetConverter}. */ -@RunWith(JUnit4.class) public class StringSetConverterTest { - @Rule - public final JpaUnitTestRule jpaRule = + + @RegisterExtension + public final JpaUnitTestExtension jpaExtension = new JpaTestRules.Builder().withEntityClass(TestEntity.class).buildUnitTestRule(); @Test - public void roundTripConversion_returnsSameStringList() { + void roundTripConversion_returnsSameStringList() { Set tlds = ImmutableSet.of("app", "dev", "how"); TestEntity testEntity = new TestEntity(tlds); jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity)); @@ -47,7 +45,7 @@ public class StringSetConverterTest { } @Test - public void testNullValue_writesAndReadsNullSuccessfully() { + void testNullValue_writesAndReadsNullSuccessfully() { TestEntity testEntity = new TestEntity(null); jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity)); TestEntity persisted = @@ -56,7 +54,7 @@ public class StringSetConverterTest { } @Test - public void testEmptyCollection_writesAndReadsEmptyCollectionSuccessfully() { + void testEmptyCollection_writesAndReadsEmptyCollectionSuccessfully() { TestEntity testEntity = new TestEntity(ImmutableSet.of()); jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity)); TestEntity persisted = diff --git a/core/src/test/java/google/registry/persistence/converter/StringVKeyConverterTest.java b/core/src/test/java/google/registry/persistence/converter/StringVKeyConverterTest.java index dbc21bd24..59eea6cf6 100644 --- a/core/src/test/java/google/registry/persistence/converter/StringVKeyConverterTest.java +++ b/core/src/test/java/google/registry/persistence/converter/StringVKeyConverterTest.java @@ -20,28 +20,23 @@ import static google.registry.persistence.transaction.TransactionManagerFactory. import google.registry.persistence.VKey; import google.registry.persistence.WithStringVKey; import google.registry.persistence.transaction.JpaTestRules; -import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestRule; +import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestExtension; import javax.persistence.Entity; import javax.persistence.Id; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; /** Test SQL persistence of VKey. */ -@RunWith(JUnit4.class) public class StringVKeyConverterTest { - @Rule - public final JpaUnitTestRule jpaRule = + @RegisterExtension + public final JpaUnitTestExtension jpaExtension = new JpaTestRules.Builder() .withEntityClass(TestEntity.class, VKeyConverter_StringType.class) .buildUnitTestRule(); - public StringVKeyConverterTest() {} - @Test - public void testRoundTrip() { + void testRoundTrip() { TestEntity original = new TestEntity("TheRealSpartacus", VKey.createSql(TestEntity.class, "ImSpartacus!")); jpaTm().transact(() -> jpaTm().getEntityManager().persist(original)); diff --git a/core/src/test/java/google/registry/persistence/converter/StringValueEnumeratedTest.java b/core/src/test/java/google/registry/persistence/converter/StringValueEnumeratedTest.java index 02db57a3b..79e9d9e32 100644 --- a/core/src/test/java/google/registry/persistence/converter/StringValueEnumeratedTest.java +++ b/core/src/test/java/google/registry/persistence/converter/StringValueEnumeratedTest.java @@ -20,26 +20,23 @@ import static google.registry.persistence.transaction.TransactionManagerFactory. import google.registry.model.ImmutableObject; import google.registry.model.registrar.Registrar.State; import google.registry.persistence.transaction.JpaTestRules; -import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestRule; +import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestExtension; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; import javax.persistence.Id; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; /** Unit tests for {@link Enumerated} annotation. */ -@RunWith(JUnit4.class) public class StringValueEnumeratedTest { - @Rule - public final JpaUnitTestRule jpaRule = + @RegisterExtension + public final JpaUnitTestExtension jpaExtension = new JpaTestRules.Builder().withEntityClass(TestEntity.class).buildUnitTestRule(); @Test - public void roundTripConversion_returnsSameEnum() { + void roundTripConversion_returnsSameEnum() { TestEntity testEntity = new TestEntity(State.ACTIVE); jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity)); TestEntity persisted = @@ -48,7 +45,7 @@ public class StringValueEnumeratedTest { } @Test - public void testNativeQuery_succeeds() { + void testNativeQuery_succeeds() { TestEntity testEntity = new TestEntity(State.DISABLED); jpaTm().transact(() -> jpaTm().getEntityManager().persist(testEntity)); diff --git a/core/src/test/java/google/registry/persistence/converter/TimedTransitionPropertyConverterBaseTest.java b/core/src/test/java/google/registry/persistence/converter/TimedTransitionPropertyConverterBaseTest.java index c5e01452d..82fd2d94d 100644 --- a/core/src/test/java/google/registry/persistence/converter/TimedTransitionPropertyConverterBaseTest.java +++ b/core/src/test/java/google/registry/persistence/converter/TimedTransitionPropertyConverterBaseTest.java @@ -25,7 +25,7 @@ import google.registry.model.ImmutableObject; import google.registry.model.common.TimedTransitionProperty; import google.registry.model.common.TimedTransitionProperty.TimedTransition; import google.registry.persistence.transaction.JpaTestRules; -import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestRule; +import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestExtension; import java.util.Map; import javax.persistence.Converter; import javax.persistence.Entity; @@ -36,10 +36,10 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; /** Unit tests for {@link TimedTransitionPropertyConverterBase}. */ -public class TimedTransitionPropertyConverterBaseTest { +class TimedTransitionPropertyConverterBaseTest { @RegisterExtension - public final JpaUnitTestRule jpa = + public final JpaUnitTestExtension jpa = new JpaTestRules.Builder() .withInitScript("sql/flyway/V14__load_extension_for_hstore.sql") .withEntityClass(TestTimedTransitionPropertyConverter.class, TestEntity.class) diff --git a/core/src/test/java/google/registry/persistence/converter/TldStateTransitionConverterTest.java b/core/src/test/java/google/registry/persistence/converter/TldStateTransitionConverterTest.java index 852c1fe78..4a782b9d6 100644 --- a/core/src/test/java/google/registry/persistence/converter/TldStateTransitionConverterTest.java +++ b/core/src/test/java/google/registry/persistence/converter/TldStateTransitionConverterTest.java @@ -24,7 +24,7 @@ import google.registry.model.common.TimedTransitionProperty; import google.registry.model.registry.Registry.TldState; import google.registry.model.registry.Registry.TldStateTransition; import google.registry.persistence.transaction.JpaTestRules; -import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestRule; +import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestExtension; import javax.persistence.Entity; import javax.persistence.Id; import org.joda.time.DateTime; @@ -32,10 +32,10 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; /** Unit tests for {@link TldStateTransitionConverter}. */ -public class TldStateTransitionConverterTest { +class TldStateTransitionConverterTest { @RegisterExtension - public final JpaUnitTestRule jpa = + public final JpaUnitTestExtension jpa = new JpaTestRules.Builder() .withInitScript("sql/flyway/V14__load_extension_for_hstore.sql") .withEntityClass(TestEntity.class) diff --git a/core/src/test/java/google/registry/persistence/converter/UpdateAutoTimestampConverterTest.java b/core/src/test/java/google/registry/persistence/converter/UpdateAutoTimestampConverterTest.java index a6aa107a4..28471586e 100644 --- a/core/src/test/java/google/registry/persistence/converter/UpdateAutoTimestampConverterTest.java +++ b/core/src/test/java/google/registry/persistence/converter/UpdateAutoTimestampConverterTest.java @@ -19,31 +19,28 @@ import static google.registry.persistence.transaction.TransactionManagerFactory. import google.registry.model.ImmutableObject; import google.registry.model.UpdateAutoTimestamp; import google.registry.persistence.transaction.JpaTestRules; -import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestRule; +import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestExtension; import google.registry.schema.replay.EntityTest.EntityForTesting; import google.registry.testing.FakeClock; import javax.persistence.Entity; import javax.persistence.Id; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; /** Unit tests for {@link UpdateAutoTimestampConverter}. */ -@RunWith(JUnit4.class) public class UpdateAutoTimestampConverterTest { private final FakeClock fakeClock = new FakeClock(); - @Rule - public final JpaUnitTestRule jpaRule = + @RegisterExtension + public final JpaUnitTestExtension jpaExtension = new JpaTestRules.Builder() .withClock(fakeClock) .withEntityClass(TestEntity.class) .buildUnitTestRule(); @Test - public void testTypeConversion() { + void testTypeConversion() { TestEntity ent = new TestEntity("myinst", null); jpaTm().transact(() -> jpaTm().getEntityManager().persist(ent)); @@ -56,7 +53,7 @@ public class UpdateAutoTimestampConverterTest { } @Test - public void testTimeChangesOnSubsequentTransactions() { + void testTimeChangesOnSubsequentTransactions() { TestEntity ent1 = new TestEntity("myinst1", null); jpaTm().transact(() -> jpaTm().getEntityManager().persist(ent1)); diff --git a/core/src/test/java/google/registry/persistence/converter/ZonedDateTimeConverterTest.java b/core/src/test/java/google/registry/persistence/converter/ZonedDateTimeConverterTest.java index 88fe1da11..af253a083 100644 --- a/core/src/test/java/google/registry/persistence/converter/ZonedDateTimeConverterTest.java +++ b/core/src/test/java/google/registry/persistence/converter/ZonedDateTimeConverterTest.java @@ -19,46 +19,43 @@ import static google.registry.persistence.transaction.TransactionManagerFactory. import google.registry.model.ImmutableObject; import google.registry.persistence.transaction.JpaTestRules; -import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestRule; +import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestExtension; import java.sql.Timestamp; import java.time.Instant; import java.time.ZonedDateTime; import javax.persistence.Entity; import javax.persistence.Id; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; /** Unit tests for {@link ZonedDateTimeConverter}. */ -@RunWith(JUnit4.class) public class ZonedDateTimeConverterTest { - @Rule - public final JpaUnitTestRule jpaRule = + @RegisterExtension + public final JpaUnitTestExtension jpaExtension = new JpaTestRules.Builder().withEntityClass(TestEntity.class).buildUnitTestRule(); private final ZonedDateTimeConverter converter = new ZonedDateTimeConverter(); @Test - public void convertToDatabaseColumn_returnsNullIfInputIsNull() { + void convertToDatabaseColumn_returnsNullIfInputIsNull() { assertThat(converter.convertToDatabaseColumn(null)).isNull(); } @Test - public void convertToDatabaseColumn_convertsCorrectly() { + void convertToDatabaseColumn_convertsCorrectly() { ZonedDateTime zonedDateTime = ZonedDateTime.parse("2019-09-01T01:01:01Z"); assertThat(converter.convertToDatabaseColumn(zonedDateTime).toInstant()) .isEqualTo(zonedDateTime.toInstant()); } @Test - public void convertToEntityAttribute_returnsNullIfInputIsNull() { + void convertToEntityAttribute_returnsNullIfInputIsNull() { assertThat(converter.convertToEntityAttribute(null)).isNull(); } @Test - public void convertToEntityAttribute_convertsCorrectly() { + void convertToEntityAttribute_convertsCorrectly() { ZonedDateTime zonedDateTime = ZonedDateTime.parse("2019-09-01T01:01:01Z"); Instant instant = zonedDateTime.toInstant(); assertThat(converter.convertToEntityAttribute(Timestamp.from(instant))) @@ -66,7 +63,7 @@ public class ZonedDateTimeConverterTest { } @Test - public void converter_generatesTimestampWithNormalizedZone() { + void converter_generatesTimestampWithNormalizedZone() { ZonedDateTime zdt = ZonedDateTime.parse("2019-09-01T01:01:01Z"); TestEntity entity = new TestEntity("normalized_utc_time", zdt); jpaTm().transact(() -> jpaTm().getEntityManager().persist(entity)); @@ -78,7 +75,7 @@ public class ZonedDateTimeConverterTest { } @Test - public void converter_convertsNonNormalizedZoneCorrectly() { + void converter_convertsNonNormalizedZoneCorrectly() { ZonedDateTime zdt = ZonedDateTime.parse("2019-09-01T01:01:01Z[UTC]"); TestEntity entity = new TestEntity("non_normalized_utc_time", zdt); @@ -91,7 +88,7 @@ public class ZonedDateTimeConverterTest { } @Test - public void converter_convertsNonUtcZoneCorrectly() { + void converter_convertsNonUtcZoneCorrectly() { ZonedDateTime zdt = ZonedDateTime.parse("2019-09-01T01:01:01+05:00"); TestEntity entity = new TestEntity("new_york_time", zdt); diff --git a/core/src/test/java/google/registry/persistence/transaction/JpaTestRules.java b/core/src/test/java/google/registry/persistence/transaction/JpaTestRules.java index cb9175a77..b7282248a 100644 --- a/core/src/test/java/google/registry/persistence/transaction/JpaTestRules.java +++ b/core/src/test/java/google/registry/persistence/transaction/JpaTestRules.java @@ -43,6 +43,7 @@ import org.junit.runners.model.Statement; * JpaTransactionManager} instances. */ public class JpaTestRules { + private static final String GOLDEN_SCHEMA_SQL_PATH = "sql/schema/nomulus.golden.sql"; /** @@ -50,7 +51,6 @@ public class JpaTestRules { * with the Nomulus Cloud SQL schema. */ public static class JpaIntegrationTestRule extends JpaTransactionManagerRule { - private JpaIntegrationTestRule( Clock clock, ImmutableList extraEntityClasses, @@ -59,14 +59,15 @@ public class JpaTestRules { } } + private static final AssertionError EXCEPTION_OF_DISAPPROVAL = + new AssertionError("ಠ_ಠ Why are you writing new tests in JUnit 4?? ಠ_ಠ"); + /** - * Junit rule for unit tests with JPA framework, when the underlying database is populated by the - * optional init script (which must not be the Nomulus Cloud SQL schema). This rule can also be - * used as am extension for JUnit5 tests. + * JUnit extension for unit tests with JPA framework, when the underlying database is populated by + * the optional init script (which must not be the Nomulus Cloud SQL schema). */ - public static class JpaUnitTestRule extends JpaTransactionManagerRule - implements BeforeEachCallback, AfterEachCallback { - private JpaUnitTestRule( + public static class JpaUnitTestExtension extends JpaTransactionManagerRule { + private JpaUnitTestExtension( Clock clock, Optional initScriptPath, ImmutableList extraEntityClasses, @@ -75,13 +76,13 @@ public class JpaTestRules { } @Override - public void beforeEach(ExtensionContext context) throws Exception { - this.before(); + public void before() { + throw EXCEPTION_OF_DISAPPROVAL; } @Override - public void afterEach(ExtensionContext context) throws Exception { - this.after(); + public void after() { + throw EXCEPTION_OF_DISAPPROVAL; } } @@ -157,7 +158,7 @@ public class JpaTestRules { * Sets the SQL script to be used to initialize the database. If not set, * sql/schema/nomulus.golden.sql will be used. * - *

The {@code initScript} is only accepted when building {@link JpaUnitTestRule}. + *

The {@code initScript} is only accepted when building {@link JpaUnitTestExtension}. */ public Builder withInitScript(String initScript) { this.initScript = initScript; @@ -219,13 +220,14 @@ public class JpaTestRules { } /** - * Builds a {@link JpaUnitTestRule} instance that can also be used as an extension for JUnit5. + * Builds a {@link JpaUnitTestExtension} instance that can also be used as an extension for + * JUnit5. */ - public JpaUnitTestRule buildUnitTestRule() { + public JpaUnitTestExtension buildUnitTestRule() { checkState( !Objects.equals(GOLDEN_SCHEMA_SQL_PATH, initScript), "Unit tests must not depend on the Nomulus schema."); - return new JpaUnitTestRule( + return new JpaUnitTestExtension( clock == null ? new FakeClock(DateTime.now(UTC)) : clock, Optional.ofNullable(initScript), ImmutableList.copyOf(extraEntityClasses), diff --git a/core/src/test/java/google/registry/persistence/transaction/JpaTestRulesSqlLoggingTest.java b/core/src/test/java/google/registry/persistence/transaction/JpaTestRulesSqlLoggingTest.java index 558ddefcb..fb7a4aa14 100644 --- a/core/src/test/java/google/registry/persistence/transaction/JpaTestRulesSqlLoggingTest.java +++ b/core/src/test/java/google/registry/persistence/transaction/JpaTestRulesSqlLoggingTest.java @@ -18,7 +18,7 @@ import static com.google.common.truth.Truth.assertThat; import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; import static java.nio.charset.StandardCharsets.UTF_8; -import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestRule; +import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestExtension; import java.io.ByteArrayOutputStream; import java.io.PrintStream; import java.io.UnsupportedEncodingException; @@ -28,23 +28,24 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; /** Unit test for {@link JpaTestRules.Builder#withSqlLogging()}. */ -public class JpaTestRulesSqlLoggingTest { +class JpaTestRulesSqlLoggingTest { // Entity under test: configured to log SQL statements to Stdout. @RegisterExtension - JpaUnitTestRule jpaRule = new JpaTestRules.Builder().withSqlLogging().buildUnitTestRule(); + JpaUnitTestExtension jpaExtension = + new JpaTestRules.Builder().withSqlLogging().buildUnitTestRule(); private PrintStream orgStdout; private ByteArrayOutputStream stdoutBuffer; @BeforeEach - public void beforeEach() { + void beforeEach() { orgStdout = System.out; System.setOut(new PrintStream(stdoutBuffer = new ByteArrayOutputStream())); } @AfterEach - public void afterEach() { + void afterEach() { System.setOut(orgStdout); } diff --git a/core/src/test/java/google/registry/persistence/transaction/JpaTransactionManagerImplTest.java b/core/src/test/java/google/registry/persistence/transaction/JpaTransactionManagerImplTest.java index a1f03dd30..91f604252 100644 --- a/core/src/test/java/google/registry/persistence/transaction/JpaTransactionManagerImplTest.java +++ b/core/src/test/java/google/registry/persistence/transaction/JpaTransactionManagerImplTest.java @@ -22,7 +22,7 @@ import static org.junit.Assert.assertThrows; import com.google.common.collect.ImmutableList; import google.registry.model.ImmutableObject; import google.registry.persistence.VKey; -import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestRule; +import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestExtension; import google.registry.testing.FakeClock; import java.io.Serializable; import java.math.BigInteger; @@ -32,10 +32,8 @@ import javax.persistence.EntityManager; import javax.persistence.Id; import javax.persistence.IdClass; import javax.persistence.RollbackException; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; /** * Unit tests for SQL only APIs defined in {@link JpaTransactionManagerImpl}. Note that the tests @@ -44,8 +42,7 @@ import org.junit.runners.JUnit4; *

TODO(shicong): Remove duplicate tests that covered by TransactionManagerTest by refactoring * the test schema. */ -@RunWith(JUnit4.class) -public class JpaTransactionManagerImplTest { +class JpaTransactionManagerImplTest { private final FakeClock fakeClock = new FakeClock(); private final TestEntity theEntity = new TestEntity("theEntity", "foo"); @@ -60,8 +57,8 @@ public class JpaTransactionManagerImplTest { new TestEntity("entity2", "bar"), new TestEntity("entity3", "qux")); - @Rule - public final JpaUnitTestRule jpaRule = + @RegisterExtension + final JpaUnitTestExtension jpaExtension = new JpaTestRules.Builder() .withInitScript(fileClassPath(getClass(), "test_schema.sql")) .withClock(fakeClock) @@ -69,7 +66,7 @@ public class JpaTransactionManagerImplTest { .buildUnitTestRule(); @Test - public void transact_succeeds() { + void transact_succeeds() { assertPersonEmpty(); assertCompanyEmpty(); jpaTm() @@ -87,7 +84,7 @@ public class JpaTransactionManagerImplTest { } @Test - public void transact_hasNoEffectWithPartialSuccess() { + void transact_hasNoEffectWithPartialSuccess() { assertPersonEmpty(); assertCompanyEmpty(); assertThrows( @@ -105,7 +102,7 @@ public class JpaTransactionManagerImplTest { } @Test - public void transact_reusesExistingTransaction() { + void transact_reusesExistingTransaction() { assertPersonEmpty(); assertCompanyEmpty(); jpaTm() @@ -126,7 +123,7 @@ public class JpaTransactionManagerImplTest { } @Test - public void saveNew_succeeds() { + void saveNew_succeeds() { assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isFalse(); jpaTm().transact(() -> jpaTm().saveNew(theEntity)); assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isTrue(); @@ -134,7 +131,7 @@ public class JpaTransactionManagerImplTest { } @Test - public void saveNew_throwsExceptionIfEntityExists() { + void saveNew_throwsExceptionIfEntityExists() { assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isFalse(); jpaTm().transact(() -> jpaTm().saveNew(theEntity)); assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isTrue(); @@ -143,7 +140,7 @@ public class JpaTransactionManagerImplTest { } @Test - public void createCompoundIdEntity_succeeds() { + void createCompoundIdEntity_succeeds() { assertThat(jpaTm().transact(() -> jpaTm().checkExists(compoundIdEntity))).isFalse(); jpaTm().transact(() -> jpaTm().saveNew(compoundIdEntity)); assertThat(jpaTm().transact(() -> jpaTm().checkExists(compoundIdEntity))).isTrue(); @@ -152,7 +149,7 @@ public class JpaTransactionManagerImplTest { } @Test - public void saveAllNew_succeeds() { + void saveAllNew_succeeds() { moreEntities.forEach( entity -> assertThat(jpaTm().transact(() -> jpaTm().checkExists(entity))).isFalse()); jpaTm().transact(() -> jpaTm().saveAllNew(moreEntities)); @@ -163,7 +160,7 @@ public class JpaTransactionManagerImplTest { } @Test - public void saveAllNew_rollsBackWhenFailure() { + void saveAllNew_rollsBackWhenFailure() { moreEntities.forEach( entity -> assertThat(jpaTm().transact(() -> jpaTm().checkExists(entity))).isFalse()); jpaTm().transact(() -> jpaTm().saveNew(moreEntities.get(0))); @@ -175,7 +172,7 @@ public class JpaTransactionManagerImplTest { } @Test - public void saveNewOrUpdate_persistsNewEntity() { + void saveNewOrUpdate_persistsNewEntity() { assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isFalse(); jpaTm().transact(() -> jpaTm().saveNewOrUpdate(theEntity)); assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isTrue(); @@ -183,7 +180,7 @@ public class JpaTransactionManagerImplTest { } @Test - public void saveNewOrUpdate_updatesExistingEntity() { + void saveNewOrUpdate_updatesExistingEntity() { jpaTm().transact(() -> jpaTm().saveNew(theEntity)); TestEntity persisted = jpaTm().transact(() -> jpaTm().load(theEntityKey)); assertThat(persisted.data).isEqualTo("foo"); @@ -194,7 +191,7 @@ public class JpaTransactionManagerImplTest { } @Test - public void saveNewOrUpdateAll_succeeds() { + void saveNewOrUpdateAll_succeeds() { moreEntities.forEach( entity -> assertThat(jpaTm().transact(() -> jpaTm().checkExists(entity))).isFalse()); jpaTm().transact(() -> jpaTm().saveNewOrUpdateAll(moreEntities)); @@ -205,7 +202,7 @@ public class JpaTransactionManagerImplTest { } @Test - public void update_succeeds() { + void update_succeeds() { jpaTm().transact(() -> jpaTm().saveNew(theEntity)); TestEntity persisted = jpaTm().transact(() -> jpaTm().load(VKey.createSql(TestEntity.class, "theEntity"))); @@ -217,7 +214,7 @@ public class JpaTransactionManagerImplTest { } @Test - public void updateCompoundIdEntity_succeeds() { + void updateCompoundIdEntity_succeeds() { jpaTm().transact(() -> jpaTm().saveNew(compoundIdEntity)); TestCompoundIdEntity persisted = jpaTm().transact(() -> jpaTm().load(compoundIdEntityKey)); assertThat(persisted.data).isEqualTo("foo"); @@ -228,7 +225,7 @@ public class JpaTransactionManagerImplTest { } @Test - public void update_throwsExceptionWhenEntityDoesNotExist() { + void update_throwsExceptionWhenEntityDoesNotExist() { assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isFalse(); assertThrows( IllegalArgumentException.class, () -> jpaTm().transact(() -> jpaTm().update(theEntity))); @@ -236,7 +233,7 @@ public class JpaTransactionManagerImplTest { } @Test - public void updateAll_succeeds() { + void updateAll_succeeds() { jpaTm().transact(() -> jpaTm().saveAllNew(moreEntities)); ImmutableList updated = ImmutableList.of( @@ -249,7 +246,7 @@ public class JpaTransactionManagerImplTest { } @Test - public void updateAll_rollsBackWhenFailure() { + void updateAll_rollsBackWhenFailure() { jpaTm().transact(() -> jpaTm().saveAllNew(moreEntities)); ImmutableList updated = ImmutableList.of( @@ -264,7 +261,7 @@ public class JpaTransactionManagerImplTest { } @Test - public void load_succeeds() { + void load_succeeds() { assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isFalse(); jpaTm().transact(() -> jpaTm().saveNew(theEntity)); TestEntity persisted = jpaTm().transact(() -> jpaTm().load(theEntityKey)); @@ -273,14 +270,14 @@ public class JpaTransactionManagerImplTest { } @Test - public void load_throwsOnMissingElement() { + void load_throwsOnMissingElement() { assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isFalse(); assertThrows( NoSuchElementException.class, () -> jpaTm().transact(() -> jpaTm().load(theEntityKey))); } @Test - public void maybeLoad_succeeds() { + void maybeLoad_succeeds() { assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isFalse(); jpaTm().transact(() -> jpaTm().saveNew(theEntity)); TestEntity persisted = jpaTm().transact(() -> jpaTm().maybeLoad(theEntityKey).get()); @@ -289,13 +286,13 @@ public class JpaTransactionManagerImplTest { } @Test - public void maybeLoad_nonExistentObject() { + void maybeLoad_nonExistentObject() { assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isFalse(); assertThat(jpaTm().transact(() -> jpaTm().maybeLoad(theEntityKey)).isPresent()).isFalse(); } @Test - public void loadCompoundIdEntity_succeeds() { + void loadCompoundIdEntity_succeeds() { assertThat(jpaTm().transact(() -> jpaTm().checkExists(compoundIdEntity))).isFalse(); jpaTm().transact(() -> jpaTm().saveNew(compoundIdEntity)); TestCompoundIdEntity persisted = jpaTm().transact(() -> jpaTm().load(compoundIdEntityKey)); @@ -305,14 +302,14 @@ public class JpaTransactionManagerImplTest { } @Test - public void loadAll_succeeds() { + void loadAll_succeeds() { jpaTm().transact(() -> jpaTm().saveAllNew(moreEntities)); ImmutableList persisted = jpaTm().transact(() -> jpaTm().loadAll(TestEntity.class)); assertThat(persisted).containsExactlyElementsIn(moreEntities); } @Test - public void delete_succeeds() { + void delete_succeeds() { jpaTm().transact(() -> jpaTm().saveNew(theEntity)); assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isTrue(); jpaTm().transact(() -> jpaTm().delete(theEntityKey)); @@ -320,14 +317,14 @@ public class JpaTransactionManagerImplTest { } @Test - public void delete_returnsZeroWhenNoEntity() { + void delete_returnsZeroWhenNoEntity() { assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isFalse(); jpaTm().transact(() -> jpaTm().delete(theEntityKey)); assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isFalse(); } @Test - public void deleteCompoundIdEntity_succeeds() { + void deleteCompoundIdEntity_succeeds() { jpaTm().transact(() -> jpaTm().saveNew(compoundIdEntity)); assertThat(jpaTm().transact(() -> jpaTm().checkExists(compoundIdEntity))).isTrue(); jpaTm().transact(() -> jpaTm().delete(compoundIdEntityKey)); @@ -335,7 +332,7 @@ public class JpaTransactionManagerImplTest { } @Test - public void assertDelete_throwsExceptionWhenEntityNotDeleted() { + void assertDelete_throwsExceptionWhenEntityNotDeleted() { assertThat(jpaTm().transact(() -> jpaTm().checkExists(theEntity))).isFalse(); assertThrows( IllegalArgumentException.class, diff --git a/core/src/test/java/google/registry/persistence/transaction/JpaTransactionManagerRule.java b/core/src/test/java/google/registry/persistence/transaction/JpaTransactionManagerRule.java index 33d01d446..dfd48e327 100644 --- a/core/src/test/java/google/registry/persistence/transaction/JpaTransactionManagerRule.java +++ b/core/src/test/java/google/registry/persistence/transaction/JpaTransactionManagerRule.java @@ -31,6 +31,7 @@ import google.registry.persistence.HibernateSchemaExporter; import google.registry.persistence.NomulusPostgreSql; import google.registry.persistence.PersistenceModule; import google.registry.persistence.PersistenceXmlUtility; +import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestExtension; import google.registry.util.Clock; import java.io.File; import java.io.IOException; @@ -55,6 +56,9 @@ import javax.persistence.EntityManagerFactory; import org.hibernate.cfg.Environment; import org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor; import org.hibernate.jpa.boot.spi.Bootstrap; +import org.junit.jupiter.api.extension.AfterEachCallback; +import org.junit.jupiter.api.extension.BeforeEachCallback; +import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.rules.ExternalResource; import org.testcontainers.containers.JdbcDatabaseContainer; import org.testcontainers.containers.PostgreSQLContainer; @@ -63,14 +67,16 @@ import org.testcontainers.containers.PostgreSQLContainer; * Base class of JUnit Rules to provision {@link JpaTransactionManagerImpl} backed by {@link * PostgreSQLContainer}. This class is not for direct use. Use specialized subclasses, {@link * google.registry.persistence.transaction.JpaTestRules.JpaIntegrationTestRule} or {@link - * JpaTestRules.JpaUnitTestRule} as befits the use case. + * JpaUnitTestExtension} as befits the use case. * *

This rule also replaces the {@link JpaTransactionManagerImpl} provided by {@link * TransactionManagerFactory} with the {@link JpaTransactionManagerImpl} generated by the rule * itself, so that all SQL queries will be sent to the database instance created by {@link * PostgreSQLContainer} to achieve test purpose. */ -abstract class JpaTransactionManagerRule extends ExternalResource { +abstract class JpaTransactionManagerRule extends ExternalResource + implements BeforeEachCallback, AfterEachCallback { + private static final String DB_CLEANUP_SQL_PATH = "google/registry/persistence/transaction/cleanup_database.sql"; private static final String POSTGRES_DB_NAME = "postgres"; @@ -191,7 +197,7 @@ abstract class JpaTransactionManagerRule extends ExternalResource { } @Override - public void before() throws Exception { + public void beforeEach(ExtensionContext context) throws Exception { if (entityHash == emfEntityHash) { checkState(emf != null, "Missing EntityManagerFactory."); resetTablesAndSequences(); @@ -204,11 +210,21 @@ abstract class JpaTransactionManagerRule extends ExternalResource { } @Override - public void after() { + public void afterEach(ExtensionContext context) { TransactionManagerFactory.setJpaTm(Suppliers.ofInstance(cachedTm)); cachedTm = null; } + @Override + public void before() throws Exception { + beforeEach(null); + } + + @Override + public void after() { + afterEach(null); + } + public String getDatabaseUrl() { return database.getJdbcUrl(); } diff --git a/core/src/test/java/google/registry/persistence/transaction/JpaTransactionManagerRuleTest.java b/core/src/test/java/google/registry/persistence/transaction/JpaTransactionManagerRuleTest.java index c70e16f8c..09541af03 100644 --- a/core/src/test/java/google/registry/persistence/transaction/JpaTransactionManagerRuleTest.java +++ b/core/src/test/java/google/registry/persistence/transaction/JpaTransactionManagerRuleTest.java @@ -19,29 +19,26 @@ import static google.registry.persistence.transaction.TransactionManagerFactory. import static org.junit.Assert.assertThrows; import google.registry.model.ImmutableObject; -import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestRule; +import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestExtension; import google.registry.schema.tmch.ClaimsList; import java.util.List; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.PersistenceException; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; -/** JUnit test for {@link JpaTransactionManagerRule}, with {@link JpaUnitTestRule} as proxy. */ -@RunWith(JUnit4.class) +/** JUnit test for {@link JpaTransactionManagerRule}, with {@link JpaUnitTestExtension} as proxy. */ public class JpaTransactionManagerRuleTest { - @Rule - public final JpaUnitTestRule jpaRule = + @RegisterExtension + public final JpaUnitTestExtension jpaExtension = new JpaTestRules.Builder() .withEntityClass(ClaimsList.class, TestEntity.class) .buildUnitTestRule(); @Test - public void verifiesRuleWorks() { + void verifiesRuleWorks() { assertThrows( PersistenceException.class, () -> @@ -65,7 +62,7 @@ public class JpaTransactionManagerRuleTest { } @Test - public void testExtraParameters() { + void testExtraParameters() { // This test verifies that 1) withEntityClass() has registered TestEntity and 2) The table // has been created, implying withProperty(HBM2DDL_AUTO, "update") worked. TestEntity original = new TestEntity("key", "value"); diff --git a/core/src/test/java/google/registry/pricing/PricingEngineProxyTest.java b/core/src/test/java/google/registry/pricing/PricingEngineProxyTest.java index 8779882b4..0132ae149 100644 --- a/core/src/test/java/google/registry/pricing/PricingEngineProxyTest.java +++ b/core/src/test/java/google/registry/pricing/PricingEngineProxyTest.java @@ -33,33 +33,29 @@ import google.registry.testing.FakeClock; import google.registry.util.Clock; import org.joda.money.Money; import org.joda.time.DateTime; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; /** Tests for {@link PricingEngineProxy}. */ -@RunWith(JUnit4.class) public class PricingEngineProxyTest { - @Rule + + @RegisterExtension public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build(); private Clock clock; - @Before - public void before() { - PremiumList premiumList = persistPremiumList( - "rich,USD 100", - "richer,USD 999", - "fraction,USD 20.50"); + @BeforeEach + void beforeEach() { + PremiumList premiumList = + persistPremiumList("rich,USD 100", "richer,USD 999", "fraction,USD 20.50"); createTld("moka"); persistResource(Registry.get("moka").asBuilder().setPremiumList(premiumList).build()); clock = new FakeClock(DateTime.parse("2016-03-17T12:01:00Z")); } @Test - public void test_getDomainCreateCost_multipleYears() { + void test_getDomainCreateCost_multipleYears() { assertThat(getDomainCreateCost("espresso.moka", clock.nowUtc(), 1)) .isEqualTo(Money.parse("USD 13")); assertThat(getDomainCreateCost("espresso.moka", clock.nowUtc(), 5)) @@ -71,7 +67,7 @@ public class PricingEngineProxyTest { } @Test - public void test_getDomainRenewCost_multipleYears() { + void test_getDomainRenewCost_multipleYears() { assertThat(getDomainRenewCost("espresso.moka", clock.nowUtc(), 1)) .isEqualTo(Money.parse("USD 11")); assertThat(getDomainRenewCost("espresso.moka", clock.nowUtc(), 5)) @@ -83,7 +79,7 @@ public class PricingEngineProxyTest { } @Test - public void testIsPremiumDomain() { + void testIsPremiumDomain() { createTld("example"); assertThat(isDomainPremium("poor.example", clock.nowUtc())).isFalse(); assertThat(isDomainPremium("rich.example", clock.nowUtc())).isTrue(); @@ -91,14 +87,12 @@ public class PricingEngineProxyTest { } @Test - public void testGetDomainCreateCost() { + void testGetDomainCreateCost() { // The example tld has a premium price for "rich". createTld("example"); // The default value of 17 is set in createTld(). - assertThat(getDomainCreateCost("poor.example", clock.nowUtc(), 1)) - .isEqualTo(Money.of(USD, 13)); - assertThat(getDomainCreateCost("poor.example", clock.nowUtc(), 2)) - .isEqualTo(Money.of(USD, 26)); + assertThat(getDomainCreateCost("poor.example", clock.nowUtc(), 1)).isEqualTo(Money.of(USD, 13)); + assertThat(getDomainCreateCost("poor.example", clock.nowUtc(), 2)).isEqualTo(Money.of(USD, 26)); assertThat(getDomainCreateCost("rich.example", clock.nowUtc(), 1)) .isEqualTo(Money.of(USD, 100)); assertThat(getDomainCreateCost("rich.example", clock.nowUtc(), 2)) @@ -106,7 +100,7 @@ public class PricingEngineProxyTest { } @Test - public void testGetDomainRenewCost() { + void testGetDomainRenewCost() { // The example tld has a premium price for "rich". createTld("example"); persistResource( @@ -116,32 +110,20 @@ public class PricingEngineProxyTest { ImmutableSortedMap.of( START_OF_TIME, Money.of(USD, 8), clock.nowUtc(), Money.of(USD, 10))) .build()); - assertThat(getDomainRenewCost("poor.example", START_OF_TIME, 1)) - .isEqualTo(Money.of(USD, 8)); - assertThat(getDomainRenewCost("poor.example", START_OF_TIME, 2)) - .isEqualTo(Money.of(USD, 16)); - assertThat(getDomainRenewCost("poor.example", clock.nowUtc(), 1)) - .isEqualTo(Money.of(USD, 10)); - assertThat(getDomainRenewCost("poor.example", clock.nowUtc(), 2)) - .isEqualTo(Money.of(USD, 20)); - assertThat(getDomainRenewCost("rich.example", START_OF_TIME, 1)) - .isEqualTo(Money.of(USD, 100)); - assertThat(getDomainRenewCost("rich.example", START_OF_TIME, 2)) - .isEqualTo(Money.of(USD, 200)); - assertThat(getDomainRenewCost("rich.example", clock.nowUtc(), 1)) - .isEqualTo(Money.of(USD, 100)); - assertThat(getDomainRenewCost("rich.example", clock.nowUtc(), 2)) - .isEqualTo(Money.of(USD, 200)); + assertThat(getDomainRenewCost("poor.example", START_OF_TIME, 1)).isEqualTo(Money.of(USD, 8)); + assertThat(getDomainRenewCost("poor.example", START_OF_TIME, 2)).isEqualTo(Money.of(USD, 16)); + assertThat(getDomainRenewCost("poor.example", clock.nowUtc(), 1)).isEqualTo(Money.of(USD, 10)); + assertThat(getDomainRenewCost("poor.example", clock.nowUtc(), 2)).isEqualTo(Money.of(USD, 20)); + assertThat(getDomainRenewCost("rich.example", START_OF_TIME, 1)).isEqualTo(Money.of(USD, 100)); + assertThat(getDomainRenewCost("rich.example", START_OF_TIME, 2)).isEqualTo(Money.of(USD, 200)); + assertThat(getDomainRenewCost("rich.example", clock.nowUtc(), 1)).isEqualTo(Money.of(USD, 100)); + assertThat(getDomainRenewCost("rich.example", clock.nowUtc(), 2)).isEqualTo(Money.of(USD, 200)); } @Test - public void testFailure_cantLoadPricingEngine() { + void testFailure_cantLoadPricingEngine() { createTld("example"); - persistResource( - Registry.get("example") - .asBuilder() - .setPremiumPricingEngine("fake") - .build()); + persistResource(Registry.get("example").asBuilder().setPremiumPricingEngine("fake").build()); IllegalStateException thrown = assertThrows( IllegalStateException.class, diff --git a/core/src/test/java/google/registry/rdap/AbstractJsonableObjectTest.java b/core/src/test/java/google/registry/rdap/AbstractJsonableObjectTest.java index 9e1059f97..552536825 100644 --- a/core/src/test/java/google/registry/rdap/AbstractJsonableObjectTest.java +++ b/core/src/test/java/google/registry/rdap/AbstractJsonableObjectTest.java @@ -26,12 +26,10 @@ import google.registry.rdap.AbstractJsonableObject.JsonableException; import google.registry.rdap.AbstractJsonableObject.RestrictJsonNames; import java.util.Optional; import org.joda.time.DateTime; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.Test; -@RunWith(JUnit4.class) -public final class AbstractJsonableObjectTest { +/** Unit tests for {@link AbstractJsonableObject}. */ +final class AbstractJsonableObjectTest { private final Gson gson = new Gson(); @@ -40,7 +38,7 @@ public final class AbstractJsonableObjectTest { } @Test - public void testPrimitives() { + void testPrimitives() { Jsonable jsonable = new AbstractJsonableObject() { @JsonableElement String myString = "Hello, world!"; @JsonableElement int myInt = 42; @@ -53,9 +51,8 @@ public final class AbstractJsonableObjectTest { "{'myBoolean':false,'myDouble':3.14,'myInt':42,'myString':'Hello, world!'}")); } - @Test - public void testDateTime() { + void testDateTime() { Jsonable jsonable = new AbstractJsonableObject() { @JsonableElement DateTime dateTime = DateTime.parse("2019-01-02T13:53Z"); }; @@ -63,7 +60,7 @@ public final class AbstractJsonableObjectTest { } @Test - public void testRenaming() { + void testRenaming() { Jsonable jsonable = new AbstractJsonableObject() { @JsonableElement("newName") String myString = "Hello, world!"; }; @@ -71,7 +68,7 @@ public final class AbstractJsonableObjectTest { } @Test - public void testDuplicateNames_fails() { + void testDuplicateNames_fails() { Jsonable jsonable = new AbstractJsonableObject() { @JsonableElement String myString = "A"; @JsonableElement("myString") String anotherString = "B"; @@ -81,7 +78,7 @@ public final class AbstractJsonableObjectTest { } @Test - public void testMethod() { + void testMethod() { Jsonable jsonable = new AbstractJsonableObject() { @JsonableElement String myString() { @@ -92,7 +89,7 @@ public final class AbstractJsonableObjectTest { } @Test - public void testMethodWithArguments_fails() { + void testMethodWithArguments_fails() { Jsonable jsonable = new AbstractJsonableObject() { @JsonableElement String myString(String in) { @@ -103,9 +100,8 @@ public final class AbstractJsonableObjectTest { .hasMessageThat().contains("must have no arguments"); } - @Test - public void testRecursive() { + void testRecursive() { Jsonable myJsonableObject = new AbstractJsonableObject() { @JsonableElement double myDouble = 3.14; @JsonableElement boolean myBoolean = false; @@ -124,7 +120,7 @@ public final class AbstractJsonableObjectTest { } @Test - public void testList() { + void testList() { Jsonable jsonable = new AbstractJsonableObject() { @JsonableElement ImmutableList myList = ImmutableList.of("my", "immutable", "list"); @@ -133,7 +129,7 @@ public final class AbstractJsonableObjectTest { } @Test - public void testMultipleLists() { + void testMultipleLists() { Jsonable jsonable = new AbstractJsonableObject() { @JsonableElement ImmutableList myList = ImmutableList.of("my", "immutable", "list"); @@ -145,7 +141,7 @@ public final class AbstractJsonableObjectTest { } @Test - public void testListElements() { + void testListElements() { Jsonable jsonable = new AbstractJsonableObject() { @JsonableElement ImmutableList myList = ImmutableList.of("my", "immutable", "list"); @@ -159,7 +155,7 @@ public final class AbstractJsonableObjectTest { } @Test - public void testListElementsWithoutList() { + void testListElementsWithoutList() { Jsonable jsonable = new AbstractJsonableObject() { @JsonableElement("myList[]") Integer myListMeaningOfLife = 42; @@ -170,7 +166,7 @@ public final class AbstractJsonableObjectTest { } @Test - public void testListOptionalElements() { + void testListOptionalElements() { Jsonable jsonable = new AbstractJsonableObject() { @JsonableElement ImmutableList myList = ImmutableList.of("my", "immutable", "list"); @@ -183,7 +179,7 @@ public final class AbstractJsonableObjectTest { } @Test - public void testList_sameNameAsElement_failes() { + void testList_sameNameAsElement_failes() { Jsonable jsonable = new AbstractJsonableObject() { @JsonableElement("myList") String myString = "A"; @@ -211,7 +207,7 @@ public final class AbstractJsonableObjectTest { } @Test - public void testRestricted_withAllowedNames() { + void testRestricted_withAllowedNames() { Jsonable jsonable = new AbstractJsonableObject() { @JsonableElement JsonableWithNameRestrictions allowed = new JsonableWithNameRestrictions(); @@ -225,7 +221,7 @@ public final class AbstractJsonableObjectTest { } @Test - public void testRestricted_withWrongName_failes() { + void testRestricted_withWrongName_failes() { Jsonable jsonable = new AbstractJsonableObject() { @JsonableElement JsonableWithNameRestrictions wrong = new JsonableWithNameRestrictions(); @@ -236,7 +232,7 @@ public final class AbstractJsonableObjectTest { } @Test - public void testRestricted_withNoNamesAllowed_fails() { + void testRestricted_withNoNamesAllowed_fails() { Jsonable jsonable = new AbstractJsonableObject() { @JsonableElement JsonableWithNoAllowedNames wrong = new JsonableWithNoAllowedNames(); @@ -252,14 +248,14 @@ public final class AbstractJsonableObjectTest { } @Test - public void testRestricted_withNoNamesAllowed_canBeOutermost() { + void testRestricted_withNoNamesAllowed_canBeOutermost() { Jsonable jsonable = new JsonableObjectWithNoAllowedNames(); assertThat(jsonable.toJson()) .isEqualTo(createJson("{'key':'value'}")); } @Test - public void testRestricted_withNoNamesAllowed_canBeMerged() { + void testRestricted_withNoNamesAllowed_canBeMerged() { Jsonable jsonable = new AbstractJsonableObject() { @JsonableElement("*") final Jsonable inner = new JsonableObjectWithNoAllowedNames(); @JsonableElement final String otherKey = "otherValue"; @@ -283,7 +279,7 @@ public final class AbstractJsonableObjectTest { } @Test - public void testInheritingStaticMembers_works() { + void testInheritingStaticMembers_works() { Jsonable jsonable = new InheritedWithStatic(); assertThat(jsonable.toJson()) .isEqualTo(createJson("{'messages':['message 1','more messages','message 2']}")); @@ -317,7 +313,7 @@ public final class AbstractJsonableObjectTest { } @Test - public void testOverriding_works() { + void testOverriding_works() { Jsonable jsonable = new InheritedOverriding(); assertThat(jsonable.toJson()) .isEqualTo( @@ -330,7 +326,7 @@ public final class AbstractJsonableObjectTest { } @Test - public void testMerge_works() { + void testMerge_works() { Jsonable jsonable = new AbstractJsonableObject() { @JsonableElement String key = "value"; @JsonableElement("*") Object subObject = new AbstractJsonableObject() { @@ -342,7 +338,7 @@ public final class AbstractJsonableObjectTest { } @Test - public void testMerge_joinsArrays_works() { + void testMerge_joinsArrays_works() { Jsonable jsonable = new AbstractJsonableObject() { @JsonableElement("lst[]") String a = "value"; @JsonableElement("*") Object subObject = new AbstractJsonableObject() { @@ -354,7 +350,7 @@ public final class AbstractJsonableObjectTest { } @Test - public void testMerge_multiLayer_works() { + void testMerge_multiLayer_works() { Jsonable jsonable = new AbstractJsonableObject() { @JsonableElement String key = "value"; diff --git a/core/src/test/java/google/registry/rdap/RdapActionBaseTest.java b/core/src/test/java/google/registry/rdap/RdapActionBaseTest.java index 86d8e29e9..d47439c7d 100644 --- a/core/src/test/java/google/registry/rdap/RdapActionBaseTest.java +++ b/core/src/test/java/google/registry/rdap/RdapActionBaseTest.java @@ -32,16 +32,13 @@ import google.registry.rdap.RdapSearchResults.IncompletenessWarningType; import google.registry.request.Action; import google.registry.request.auth.Auth; import java.util.Optional; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** Unit tests for {@link RdapActionBase}. */ -@RunWith(JUnit4.class) -public class RdapActionBaseTest extends RdapActionBaseTestCase { +class RdapActionBaseTest extends RdapActionBaseTestCase { - public RdapActionBaseTest() { + RdapActionBaseTest() { super(RdapTestAction.class); } @@ -72,13 +69,13 @@ public class RdapActionBaseTest extends RdapActionBaseTestCase { +abstract class RdapActionBaseTestCase { - @Rule + @RegisterExtension public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build(); - @Rule - public final InjectRule inject = new InjectRule(); + @RegisterExtension public final InjectRule inject = new InjectRule(); protected static final AuthResult AUTH_RESULT = AuthResult.create( @@ -63,21 +62,21 @@ public abstract class RdapActionBaseTestCase { protected FakeResponse response = new FakeResponse(); protected final FakeClock clock = new FakeClock(DateTime.parse("2000-01-01TZ")); - protected final RdapMetrics rdapMetrics = mock(RdapMetrics.class); + final RdapMetrics rdapMetrics = mock(RdapMetrics.class); - protected RdapAuthorization.Role metricRole = PUBLIC; + RdapAuthorization.Role metricRole = PUBLIC; protected A action; - protected final String actionPath; - protected final Class rdapActionClass; + final String actionPath; + private final Class rdapActionClass; - protected RdapActionBaseTestCase(Class rdapActionClass) { + RdapActionBaseTestCase(Class rdapActionClass) { this.rdapActionClass = rdapActionClass; this.actionPath = Actions.getPathForAction(rdapActionClass); } - @Before - public void baseSetUp() { + @BeforeEach + public void beforeEachRdapActionBaseTestCase() { inject.setStaticField(Ofy.class, "clock", clock); action = TypeUtils.instantiate(rdapActionClass); action.includeDeletedParam = Optional.empty(); @@ -101,29 +100,27 @@ public abstract class RdapActionBaseTestCase { metricRole = PUBLIC; } - protected void loginAsAdmin() { + void loginAsAdmin() { action.rdapAuthorization = RdapAuthorization.ADMINISTRATOR_AUTHORIZATION; action.rdapJsonFormatter.rdapAuthorization = action.rdapAuthorization; metricRole = ADMINISTRATOR; } - protected JsonObject generateActualJson(String domainName) { + JsonObject generateActualJson(String domainName) { action.requestPath = actionPath + domainName; action.requestMethod = GET; action.run(); return RdapTestHelper.parseJsonObject(response.getPayload()); } - protected String generateHeadPayload(String domainName) { + String generateHeadPayload(String domainName) { action.requestPath = actionPath + domainName; action.requestMethod = HEAD; action.run(); return response.getPayload(); } - protected JsonObject generateExpectedJsonError( - String description, - int code) { + JsonObject generateExpectedJsonError(String description, int code) { String title; switch (code) { case 404: @@ -147,12 +144,15 @@ public abstract class RdapActionBaseTestCase { } return RdapTestHelper.loadJsonFile( "rdap_error.json", - "DESCRIPTION", description, - "TITLE", title, - "CODE", String.valueOf(code)); + "DESCRIPTION", + description, + "TITLE", + title, + "CODE", + String.valueOf(code)); } - protected static JsonFileBuilder jsonFileBuilder() { + static JsonFileBuilder jsonFileBuilder() { return new JsonFileBuilder(); } @@ -173,7 +173,7 @@ public abstract class RdapActionBaseTestCase { return put(String.format("%s%d", key, index), value); } - public JsonFileBuilder putNext(String key, String value, String... moreKeyValues) { + JsonFileBuilder putNext(String key, String value, String... moreKeyValues) { checkArgument(moreKeyValues.length % 2 == 0); int index = putNextAndReturnIndex(key, value); for (int i = 0; i < moreKeyValues.length; i += 2) { @@ -182,29 +182,29 @@ public abstract class RdapActionBaseTestCase { return this; } - public JsonFileBuilder addDomain(String name, String handle) { + JsonFileBuilder addDomain(String name, String handle) { return putNext( "DOMAIN_PUNYCODE_NAME_", Idn.toASCII(name), "DOMAIN_UNICODE_NAME_", name, "DOMAIN_HANDLE_", handle); } - public JsonFileBuilder addNameserver(String name, String handle) { + JsonFileBuilder addNameserver(String name, String handle) { return putNext( "NAMESERVER_NAME_", Idn.toASCII(name), "NAMESERVER_UNICODE_NAME_", name, "NAMESERVER_HANDLE_", handle); } - public JsonFileBuilder addRegistrar(String fullName) { + JsonFileBuilder addRegistrar(String fullName) { return putNext("REGISTRAR_FULL_NAME_", fullName); } - public JsonFileBuilder addContact(String handle) { + JsonFileBuilder addContact(String handle) { return putNext("CONTACT_HANDLE_", handle); } - public JsonFileBuilder setNextQuery(String nextQuery) { + JsonFileBuilder setNextQuery(String nextQuery) { return put("NEXT_QUERY", nextQuery); } diff --git a/core/src/test/java/google/registry/rdap/RdapDataStructuresTest.java b/core/src/test/java/google/registry/rdap/RdapDataStructuresTest.java index 20fbd3690..33b069f0e 100644 --- a/core/src/test/java/google/registry/rdap/RdapDataStructuresTest.java +++ b/core/src/test/java/google/registry/rdap/RdapDataStructuresTest.java @@ -30,12 +30,10 @@ import google.registry.rdap.RdapDataStructures.RdapConformance; import google.registry.rdap.RdapDataStructures.RdapStatus; import google.registry.rdap.RdapDataStructures.Remark; import org.joda.time.DateTime; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.Test; -@RunWith(JUnit4.class) -public final class RdapDataStructuresTest { +/** Unit tests for {@link RdapDataStructures}. */ +final class RdapDataStructuresTest { private void assertRestrictedNames(Object object, String... names) { assertThat(AbstractJsonableObject.getNameRestriction(object.getClass()).get()) @@ -43,7 +41,7 @@ public final class RdapDataStructuresTest { } @Test - public void testRdapConformance() { + void testRdapConformance() { assertThat(RdapConformance.INSTANCE.toJson()) .isEqualTo(createJson( "[", @@ -54,7 +52,7 @@ public final class RdapDataStructuresTest { } @Test - public void testLink() { + void testLink() { Link link = Link.builder() .setHref("myHref") @@ -68,7 +66,7 @@ public final class RdapDataStructuresTest { } @Test - public void testNotice() { + void testNotice() { Notice notice = Notice.builder() .setDescription("AAA", "BBB") .setTitle("myTitle") @@ -88,7 +86,7 @@ public final class RdapDataStructuresTest { } @Test - public void testRemark() { + void testRemark() { Remark remark = Remark.builder() .setDescription("AAA", "BBB") .setTitle("myTitle") @@ -108,13 +106,13 @@ public final class RdapDataStructuresTest { } @Test - public void testLanguage() { + void testLanguage() { assertThat(LanguageIdentifier.EN.toJson()).isEqualTo(createJson("'en'")); assertRestrictedNames(LanguageIdentifier.EN, "lang"); } @Test - public void testEvent() { + void testEvent() { Event event = Event.builder() .setEventAction(EventAction.REGISTRATION) @@ -135,7 +133,7 @@ public final class RdapDataStructuresTest { } @Test - public void testEventWithoutActor() { + void testEventWithoutActor() { EventWithoutActor event = EventWithoutActor.builder() .setEventAction(EventAction.REGISTRATION) @@ -154,20 +152,20 @@ public final class RdapDataStructuresTest { } @Test - public void testRdapStatus() { + void testRdapStatus() { assertThat(RdapStatus.ACTIVE.toJson()).isEqualTo(createJson("'active'")); assertRestrictedNames(RdapStatus.ACTIVE, "status[]"); } @Test - public void testPort43() { + void testPort43() { Port43WhoisServer port43 = Port43WhoisServer.create("myServer"); assertThat(port43.toJson()).isEqualTo(createJson("'myServer'")); assertRestrictedNames(port43, "port43"); } @Test - public void testPublicId() { + void testPublicId() { PublicId publicId = PublicId.create(PublicId.Type.IANA_REGISTRAR_ID, "myId"); assertThat(publicId.toJson()) .isEqualTo(createJson("{'identifier':'myId','type':'IANA Registrar ID'}")); @@ -175,7 +173,7 @@ public final class RdapDataStructuresTest { } @Test - public void testObjectClassName() { + void testObjectClassName() { assertThat(ObjectClassName.DOMAIN.toJson()).isEqualTo(createJson("'domain'")); assertRestrictedNames(ObjectClassName.DOMAIN, "objectClassName"); } diff --git a/core/src/test/java/google/registry/rdap/RdapDomainActionTest.java b/core/src/test/java/google/registry/rdap/RdapDomainActionTest.java index 685ecf63e..9bc550c16 100644 --- a/core/src/test/java/google/registry/rdap/RdapDomainActionTest.java +++ b/core/src/test/java/google/registry/rdap/RdapDomainActionTest.java @@ -41,22 +41,19 @@ import google.registry.rdap.RdapMetrics.WildcardType; import google.registry.rdap.RdapSearchResults.IncompletenessWarningType; import google.registry.request.Action; import java.util.Optional; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; /** Unit tests for {@link RdapDomainAction}. */ -@RunWith(JUnit4.class) -public class RdapDomainActionTest extends RdapActionBaseTestCase { +class RdapDomainActionTest extends RdapActionBaseTestCase { - public RdapDomainActionTest() { + RdapDomainActionTest() { super(RdapDomainAction.class); } - @Before - public void setUp() { + @BeforeEach + void beforeEach() { // lol createTld("lol"); Registrar registrarLol = persistResource(makeRegistrar( @@ -246,7 +243,7 @@ public class RdapDomainActionTest extends RdapActionBaseTestCase { +class RdapDomainSearchActionTest extends RdapSearchActionTestCase { - public RdapDomainSearchActionTest() { + RdapDomainSearchActionTest() { super(RdapDomainSearchAction.class); } @@ -140,8 +137,8 @@ public class RdapDomainSearchActionTest extends RdapSearchActionTestCase { +class RdapEntityActionTest extends RdapActionBaseTestCase { - public RdapEntityActionTest() { + RdapEntityActionTest() { super(RdapEntityAction.class); } @@ -60,8 +57,8 @@ public class RdapEntityActionTest extends RdapActionBaseTestCase", "rdap_registrar.json"); } @Test - public void testRegistrarByName_found() { + void testRegistrarByName_found() { assertThat(generateActualJson("IDN%20Registrar")) .isEqualTo( generateExpectedJsonWithTopLevelEntries( @@ -320,28 +317,28 @@ public class RdapEntityActionTest extends RdapActionBaseTestCase { +class RdapEntitySearchActionTest extends RdapSearchActionTestCase { - public RdapEntitySearchActionTest() { + RdapEntitySearchActionTest() { super(RdapEntitySearchAction.class); } @@ -105,8 +102,8 @@ public class RdapEntitySearchActionTest extends RdapSearchActionTestCase", "20", "Yes Virginia