diff --git a/core/src/test/java/google/registry/model/CreateAutoTimestampTest.java b/core/src/test/java/google/registry/model/CreateAutoTimestampTest.java index 8e02b69f3..2b6dc50a5 100644 --- a/core/src/test/java/google/registry/model/CreateAutoTimestampTest.java +++ b/core/src/test/java/google/registry/model/CreateAutoTimestampTest.java @@ -23,16 +23,13 @@ import com.googlecode.objectify.annotation.Entity; import google.registry.model.common.CrossTldSingleton; import google.registry.testing.AppEngineRule; 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 CreateAutoTimestamp}. */ -@RunWith(JUnit4.class) public class CreateAutoTimestampTest { - @Rule + @RegisterExtension public final AppEngineRule appEngine = AppEngineRule.builder() .withDatastoreAndCloudSql() @@ -50,7 +47,7 @@ public class CreateAutoTimestampTest { } @Test - public void testSaveSetsTime() { + void testSaveSetsTime() { DateTime transactionTime = tm() .transact( @@ -65,7 +62,7 @@ public class CreateAutoTimestampTest { } @Test - public void testResavingRespectsOriginalTime() { + void testResavingRespectsOriginalTime() { final DateTime oldCreateTime = DateTime.now(UTC).minusDays(1); tm() .transact( diff --git a/core/src/test/java/google/registry/model/EntityClassesTest.java b/core/src/test/java/google/registry/model/EntityClassesTest.java index 12480df1e..16f0de64e 100644 --- a/core/src/test/java/google/registry/model/EntityClassesTest.java +++ b/core/src/test/java/google/registry/model/EntityClassesTest.java @@ -26,13 +26,10 @@ import com.googlecode.objectify.Key; import com.googlecode.objectify.annotation.Entity; import com.googlecode.objectify.annotation.EntitySubclass; import java.util.Set; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.Test; /** Unit tests for {@link EntityClasses}. */ -@RunWith(JUnit4.class) -public class EntityClassesTest { +class EntityClassesTest { // This implements the manual ordering we've been using for the EntityClasses class lists. private static final Ordering> QUALIFIED_CLASS_NAME_ORDERING = @@ -41,12 +38,12 @@ public class EntityClassesTest { clazz -> clazz.getCanonicalName().substring(clazz.getPackage().getName().length())); @Test - public void testEntityClasses_inAlphabeticalOrder() { + void testEntityClasses_inAlphabeticalOrder() { assertThat(ALL_CLASSES).isInStrictOrder(QUALIFIED_CLASS_NAME_ORDERING); } @Test - public void testEntityClasses_baseEntitiesHaveUniqueKinds() { + void testEntityClasses_baseEntitiesHaveUniqueKinds() { assertWithMessage("base entity kinds") .about(streams()) .that(ALL_CLASSES.stream().filter(hasAnnotation(Entity.class)).map(Key::getKind)) @@ -54,7 +51,7 @@ public class EntityClassesTest { } @Test - public void testEntityClasses_entitySubclassesHaveKindsMatchingBaseEntities() { + void testEntityClasses_entitySubclassesHaveKindsMatchingBaseEntities() { Set baseEntityKinds = ALL_CLASSES .stream() @@ -73,7 +70,7 @@ public class EntityClassesTest { } @Test - public void testEntityClasses_eitherBaseEntityOrEntitySubclass() { + void testEntityClasses_eitherBaseEntityOrEntitySubclass() { for (Class clazz : ALL_CLASSES) { boolean isEntityXorEntitySubclass = clazz.isAnnotationPresent(Entity.class) ^ clazz.isAnnotationPresent(EntitySubclass.class); diff --git a/core/src/test/java/google/registry/model/EntityTestCase.java b/core/src/test/java/google/registry/model/EntityTestCase.java index c9c43f2b2..188c828d7 100644 --- a/core/src/test/java/google/registry/model/EntityTestCase.java +++ b/core/src/test/java/google/registry/model/EntityTestCase.java @@ -41,8 +41,6 @@ import java.lang.reflect.Type; import java.util.Collection; import java.util.Set; import org.joda.time.DateTime; -import org.junit.Before; -import org.junit.Rule; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.RegisterExtension; @@ -61,9 +59,9 @@ public abstract class EntityTestCase { protected FakeClock fakeClock = new FakeClock(DateTime.now(UTC)); - @Rule @RegisterExtension public final AppEngineRule appEngine; + @RegisterExtension public final AppEngineRule appEngine; - @Rule @RegisterExtension public InjectRule inject = new InjectRule(); + @RegisterExtension public InjectRule inject = new InjectRule(); protected EntityTestCase() { this(JpaEntityCoverageCheck.DISABLED); @@ -78,7 +76,6 @@ public abstract class EntityTestCase { .build(); } - @Before @BeforeEach public void injectClock() { inject.setStaticField(Ofy.class, "clock", fakeClock); diff --git a/core/src/test/java/google/registry/model/EppResourceTest.java b/core/src/test/java/google/registry/model/EppResourceTest.java index 1c223dca1..4608c7b47 100644 --- a/core/src/test/java/google/registry/model/EppResourceTest.java +++ b/core/src/test/java/google/registry/model/EppResourceTest.java @@ -26,18 +26,18 @@ import google.registry.model.contact.ContactResource; import google.registry.model.host.HostResource; import google.registry.testing.TestCacheRule; import org.joda.time.Duration; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; /** Unit tests for {@link EppResource}. */ public class EppResourceTest extends EntityTestCase { - @Rule + @RegisterExtension public final TestCacheRule testCacheRule = new TestCacheRule.Builder().withEppResourceCache(Duration.standardDays(1)).build(); @Test - public void test_loadCached_ignoresContactChange() { + void test_loadCached_ignoresContactChange() { ContactResource originalContact = persistActiveContact("contact123"); assertThat(EppResource.loadCached(ImmutableList.of(originalContact.createVKey()))) .containsExactly(originalContact.createVKey(), originalContact); @@ -50,7 +50,7 @@ public class EppResourceTest extends EntityTestCase { } @Test - public void test_loadCached_ignoresHostChange() { + void test_loadCached_ignoresHostChange() { HostResource originalHost = persistActiveHost("ns1.example.com"); assertThat(EppResource.loadCached(ImmutableList.of(originalHost.createVKey()))) .containsExactly(originalHost.createVKey(), originalHost); diff --git a/core/src/test/java/google/registry/model/EppResourceUtilsTest.java b/core/src/test/java/google/registry/model/EppResourceUtilsTest.java index 5c2301c20..0ed3f4024 100644 --- a/core/src/test/java/google/registry/model/EppResourceUtilsTest.java +++ b/core/src/test/java/google/registry/model/EppResourceUtilsTest.java @@ -30,33 +30,29 @@ import google.registry.testing.FakeClock; import google.registry.testing.InjectRule; import org.joda.time.DateTime; import org.joda.time.Duration; -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 EppResourceUtils}. */ -@RunWith(JUnit4.class) public class EppResourceUtilsTest { - @Rule + @RegisterExtension public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().withTaskQueue().build(); - @Rule - public final InjectRule inject = new InjectRule(); + @RegisterExtension public final InjectRule inject = new InjectRule(); private final FakeClock clock = new FakeClock(DateTime.now(UTC)); - @Before - public void init() { + @BeforeEach + void beforeEach() { createTld("tld"); inject.setStaticField(Ofy.class, "clock", clock); } @Test - public void testLoadAtPointInTime_beforeCreated_returnsNull() { + void testLoadAtPointInTime_beforeCreated_returnsNull() { clock.advanceOneMilli(); // Don't save a commit log, we shouldn't need one. HostResource host = persistResource( @@ -67,7 +63,7 @@ public class EppResourceUtilsTest { } @Test - public void testLoadAtPointInTime_atOrAfterLastAutoUpdateTime_returnsResource() { + void testLoadAtPointInTime_atOrAfterLastAutoUpdateTime_returnsResource() { clock.advanceOneMilli(); // Don't save a commit log, we shouldn't need one. HostResource host = persistResource( @@ -78,7 +74,7 @@ public class EppResourceUtilsTest { } @Test - public void testLoadAtPointInTime_usingIntactRevisionHistory_returnsMutationValue() { + void testLoadAtPointInTime_usingIntactRevisionHistory_returnsMutationValue() { clock.advanceOneMilli(); // Save resource with a commit log that we can read in later as a revisions map value. HostResource oldHost = persistResourceWithCommitLog( @@ -99,7 +95,7 @@ public class EppResourceUtilsTest { } @Test - public void testLoadAtPointInTime_brokenRevisionHistory_returnsResourceAsIs() { + void testLoadAtPointInTime_brokenRevisionHistory_returnsResourceAsIs() { // Don't save a commit log since we want to test the handling of a broken revisions key. HostResource oldHost = persistResource( newHostResource("ns1.cat.tld").asBuilder() @@ -119,7 +115,7 @@ public class EppResourceUtilsTest { } @Test - public void testLoadAtPointInTime_fallback_returnsMutationValueForOldestRevision() { + void testLoadAtPointInTime_fallback_returnsMutationValueForOldestRevision() { clock.advanceOneMilli(); // Save a commit log that we can fall back to. HostResource oldHost = persistResourceWithCommitLog( @@ -141,7 +137,7 @@ public class EppResourceUtilsTest { } @Test - public void testLoadAtPointInTime_ultimateFallback_onlyOneRevision_returnsCurrentResource() { + void testLoadAtPointInTime_ultimateFallback_onlyOneRevision_returnsCurrentResource() { clock.advanceOneMilli(); // Don't save a commit log; we want to test that we load from the current resource. HostResource host = persistResource( @@ -156,7 +152,7 @@ public class EppResourceUtilsTest { } @Test - public void testLoadAtPointInTime_moreThanThirtyDaysInPast_historyIsPurged() { + void testLoadAtPointInTime_moreThanThirtyDaysInPast_historyIsPurged() { clock.advanceOneMilli(); HostResource host = persistResourceWithCommitLog(newHostResource("ns1.example.net")); diff --git a/core/src/test/java/google/registry/model/ImmutableObjectTest.java b/core/src/test/java/google/registry/model/ImmutableObjectTest.java index 508eb886f..ac25ee636 100644 --- a/core/src/test/java/google/registry/model/ImmutableObjectTest.java +++ b/core/src/test/java/google/registry/model/ImmutableObjectTest.java @@ -38,16 +38,13 @@ import java.util.List; import java.util.Map; import java.util.Set; 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 ImmutableObject}. */ -@RunWith(JUnit4.class) public class ImmutableObjectTest { - @Rule + @RegisterExtension public final AppEngineRule appEngine = AppEngineRule.builder() .withDatastoreAndCloudSql() @@ -59,14 +56,14 @@ public class ImmutableObjectTest { String a; String b; - public SimpleObject(String a, String b) { + SimpleObject(String a, String b) { this.a = a; this.b = b; } } @Test - public void testToString_simpleClass() { + void testToString_simpleClass() { SimpleObject object = new SimpleObject("foo", null); assertThat(object.toString()).isEqualTo("" + "SimpleObject (@" + System.identityHashCode(object) + "): {\n" @@ -76,7 +73,7 @@ public class ImmutableObjectTest { } @Test - public void testToDiffableFieldMap_simpleClass() { + void testToDiffableFieldMap_simpleClass() { SimpleObject object = new SimpleObject("foo", null); assertThat(object.toDiffableFieldMap()).containsEntry("a", "foo"); assertThat(object.toDiffableFieldMap()).containsEntry("b", null); @@ -92,7 +89,7 @@ public class ImmutableObjectTest { } @Test - public void testToDiffableFieldMap_typesClass() { + void testToDiffableFieldMap_typesClass() { TypesObject object = new TypesObject(); object.bool = true; object.boolObject = true; @@ -110,13 +107,13 @@ public class ImmutableObjectTest { public static class NestedObject extends ImmutableObject { ImmutableObject nested; - public NestedObject(ImmutableObject nested) { + NestedObject(ImmutableObject nested) { this.nested = nested; } } @Test - public void testToDiffableFieldMap_nestedObjectClass() { + void testToDiffableFieldMap_nestedObjectClass() { SimpleObject innermostObject = new SimpleObject("foo", "bar"); NestedObject innerObject = new NestedObject(innermostObject); NestedObject object = new NestedObject(innerObject); @@ -135,7 +132,7 @@ public class ImmutableObjectTest { } @Test - public void testToDiffableFieldMap_nestedObjectCollectionsClass() { + void testToDiffableFieldMap_nestedObjectCollectionsClass() { SimpleObject obj1 = new SimpleObject("foo", "bar"); SimpleObject obj2 = new SimpleObject("bax", "bar"); Map obj1map = obj1.toDiffableFieldMap(); @@ -158,19 +155,19 @@ public class ImmutableObjectTest { public static class IterableObject extends ImmutableObject { Iterable iterable; - public IterableObject(Iterable iterable) { + IterableObject(Iterable iterable) { this.iterable = iterable; } } @Test - public void testToDiffableFieldMap_iterableField_notExpanded() { + void testToDiffableFieldMap_iterableField_notExpanded() { IterableObject iterableObject = new IterableObject(new CidrAddressBlock("127.0.0.1/32")); assertThat(iterableObject.toDiffableFieldMap()).containsEntry("iterable", "127.0.0.1/32"); } @Test - public void testToDiffableFieldMap_infiniteIterableField_notExpanded() { + void testToDiffableFieldMap_infiniteIterableField_notExpanded() { IterableObject iterableObject = new IterableObject(Iterables.cycle("na")); assertThat(iterableObject.toDiffableFieldMap()).containsEntry("iterable", "[na] (cycled)"); } @@ -202,7 +199,7 @@ public class ImmutableObjectTest { Map immutableObjectMap = newHashMap(); Map heterogenousMap = newHashMap(); - public EmptyableObject() { + EmptyableObject() { stringMap.put("a", ""); stringMap.put("b", null); immutableObjectMap.put("a", new SimpleObject("", "")); @@ -213,7 +210,7 @@ public class ImmutableObjectTest { } @Test - public void testCloneEmptyToNull() { + void testCloneEmptyToNull() { EmptyableObject cloned = cloneEmptyToNull(new EmptyableObject()); assertThat(cloned.nullString).isNull(); assertThat(cloned.emptyString).isNull(); @@ -253,13 +250,13 @@ public class ImmutableObjectTest { Set set = newHashSet((Object) null); Map map = newHashMap(); - public NullInContainersObject() { + NullInContainersObject() { map.put("a", null); } } @Test - public void testToDiffableFieldMap_withEmptyAndNulls() { + void testToDiffableFieldMap_withEmptyAndNulls() { Map diffableFieldMap = new NullInContainersObject().toDiffableFieldMap(); assertThat((List) diffableFieldMap.get("array")).containsExactly((Object) null); assertThat((List) diffableFieldMap.get("list")).containsExactly((Object) null); @@ -297,7 +294,7 @@ public class ImmutableObjectTest { } @Test - public void testToHydratedString_skipsDoNotHydrate() { + void testToHydratedString_skipsDoNotHydrate() { RootObject root = new RootObject(); root.hydrateMe = Key.create(persistResource(ValueObject.create(1, "foo"))); root.skipMe = Key.create(persistResource(ValueObject.create(2, "bar"))); @@ -307,7 +304,7 @@ public class ImmutableObjectTest { } @Test - public void testToHydratedString_expandsMaps() { + void testToHydratedString_expandsMaps() { RootObject root = new RootObject(); root.map = ImmutableMap.of("foo", Key.create(persistResource(ValueObject.create(1, "bar")))); String hydratedString = root.toHydratedString(); @@ -316,7 +313,7 @@ public class ImmutableObjectTest { } @Test - public void testToHydratedString_expandsCollections() { + void testToHydratedString_expandsCollections() { RootObject root = new RootObject(); root.set = ImmutableSet.of(Key.create(persistResource(ValueObject.create(1, "foo")))); assertThat(root.toHydratedString()).contains("foo"); diff --git a/core/src/test/java/google/registry/model/ModelUtilsTest.java b/core/src/test/java/google/registry/model/ModelUtilsTest.java index fb96c4c22..d20d61d5a 100644 --- a/core/src/test/java/google/registry/model/ModelUtilsTest.java +++ b/core/src/test/java/google/registry/model/ModelUtilsTest.java @@ -21,18 +21,14 @@ import com.googlecode.objectify.annotation.Id; import google.registry.testing.AppEngineRule; import java.lang.reflect.Field; import java.util.Map; -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; /** Unit tests for {@link ModelUtils}. */ -@RunWith(JUnit4.class) public class ModelUtilsTest { - @Rule - public AppEngineRule appEngineRule = new AppEngineRule.Builder().build(); + @RegisterExtension public AppEngineRule appEngineRule = new AppEngineRule.Builder().build(); /** Test class for reflection methods. */ public static class TestClass extends ImmutableObject implements Buildable { @@ -79,13 +75,13 @@ public class ModelUtilsTest { } } - @Before - public void resetCaches() { + @BeforeEach + void resetCaches() { ModelUtils.resetCaches(); } @Test - public void testGetAllFields() throws Exception { + void testGetAllFields() throws Exception { Map expected = ImmutableMap.of( "id", TestClass.class.getDeclaredField("id"), "a", TestClass.class.getDeclaredField("a"), @@ -101,7 +97,7 @@ public class ModelUtilsTest { } @Test - public void testGetFieldValues() throws Exception { + void testGetFieldValues() throws Exception { TestClass testInstance = new TestClass(); testInstance.id = "foo"; testInstance.a = "a"; @@ -125,7 +121,7 @@ public class ModelUtilsTest { } @Test - public void testBuildingResetsHashCode() { + void testBuildingResetsHashCode() { TestClass original = new TestClass(); original.id = "foo"; TestClass cloned = original.asBuilder().setId("bar").build(); diff --git a/core/src/test/java/google/registry/model/OteAccountBuilderTest.java b/core/src/test/java/google/registry/model/OteAccountBuilderTest.java index 9265e5755..21936820e 100644 --- a/core/src/test/java/google/registry/model/OteAccountBuilderTest.java +++ b/core/src/test/java/google/registry/model/OteAccountBuilderTest.java @@ -40,20 +40,17 @@ import org.joda.money.Money; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import org.joda.time.Duration; -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; -@RunWith(JUnit4.class) public final class OteAccountBuilderTest { - @Rule + @RegisterExtension public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build(); @Test - public void testGetRegistrarToTldMap() { + void testGetRegistrarToTldMap() { assertThat(OteAccountBuilder.forClientId("myclientid").getClientIdToTldMap()) .containsExactly( "myclientid-1", "myclientid-sunrise", @@ -62,8 +59,8 @@ public final class OteAccountBuilderTest { "myclientid-5", "myclientid-eap"); } - @Before - public void setUp() { + @BeforeEach + void beforeEach() { persistPremiumList("default_sandbox_list", "sandbox,USD 1000"); } @@ -105,7 +102,7 @@ public final class OteAccountBuilderTest { } @Test - public void testCreateOteEntities_success() { + void testCreateOteEntities_success() { OteAccountBuilder.forClientId("myclientid").addContact("email@example.com").buildAndPersist(); assertTldExists("myclientid-sunrise", START_DATE_SUNRISE, Money.zero(USD)); @@ -122,7 +119,7 @@ public final class OteAccountBuilderTest { } @Test - public void testCreateOteEntities_multipleContacts_success() { + void testCreateOteEntities_multipleContacts_success() { OteAccountBuilder.forClientId("myclientid") .addContact("email@example.com") .addContact("other@example.com") @@ -151,7 +148,7 @@ public final class OteAccountBuilderTest { } @Test - public void testCreateOteEntities_setPassword() { + void testCreateOteEntities_setPassword() { OteAccountBuilder.forClientId("myclientid").setPassword("myPassword").buildAndPersist(); assertThat(Registrar.loadByClientId("myclientid-3").get().verifyPassword("myPassword")) @@ -159,7 +156,7 @@ public final class OteAccountBuilderTest { } @Test - public void testCreateOteEntities_setCertificateHash() { + void testCreateOteEntities_setCertificateHash() { OteAccountBuilder.forClientId("myclientid") .setCertificateHash(SAMPLE_CERT_HASH) .buildAndPersist(); @@ -169,7 +166,7 @@ public final class OteAccountBuilderTest { } @Test - public void testCreateOteEntities_setCertificate() { + void testCreateOteEntities_setCertificate() { OteAccountBuilder.forClientId("myclientid") .setCertificate(SAMPLE_CERT, new SystemClock().nowUtc()) .buildAndPersist(); @@ -181,7 +178,7 @@ public final class OteAccountBuilderTest { } @Test - public void testCreateOteEntities_setIpAllowList() { + void testCreateOteEntities_setIpAllowList() { OteAccountBuilder.forClientId("myclientid") .setIpAllowList(ImmutableList.of("1.1.1.0/24")) .buildAndPersist(); @@ -191,7 +188,7 @@ public final class OteAccountBuilderTest { } @Test - public void testCreateOteEntities_invalidClientId_fails() { + void testCreateOteEntities_invalidClientId_fails() { assertThat( assertThrows( IllegalArgumentException.class, () -> OteAccountBuilder.forClientId("3blo-bio"))) @@ -200,7 +197,7 @@ public final class OteAccountBuilderTest { } @Test - public void testCreateOteEntities_clientIdTooShort_fails() { + void testCreateOteEntities_clientIdTooShort_fails() { assertThat( assertThrows(IllegalArgumentException.class, () -> OteAccountBuilder.forClientId("bl"))) .hasMessageThat() @@ -208,7 +205,7 @@ public final class OteAccountBuilderTest { } @Test - public void testCreateOteEntities_clientIdTooLong_fails() { + void testCreateOteEntities_clientIdTooLong_fails() { assertThat( assertThrows( IllegalArgumentException.class, @@ -218,7 +215,7 @@ public final class OteAccountBuilderTest { } @Test - public void testCreateOteEntities_clientIdBadCharacter_fails() { + void testCreateOteEntities_clientIdBadCharacter_fails() { assertThat( assertThrows( IllegalArgumentException.class, () -> OteAccountBuilder.forClientId("blo#bio"))) @@ -227,7 +224,7 @@ public final class OteAccountBuilderTest { } @Test - public void testCreateOteEntities_registrarExists_failsWhenNotReplaceExisting() { + void testCreateOteEntities_registrarExists_failsWhenNotReplaceExisting() { persistSimpleResource(makeRegistrar1().asBuilder().setClientId("myclientid-1").build()); OteAccountBuilder oteSetupHelper = OteAccountBuilder.forClientId("myclientid"); @@ -238,7 +235,7 @@ public final class OteAccountBuilderTest { } @Test - public void testCreateOteEntities_tldExists_failsWhenNotReplaceExisting() { + void testCreateOteEntities_tldExists_failsWhenNotReplaceExisting() { createTld("myclientid-ga", START_DATE_SUNRISE); OteAccountBuilder oteSetupHelper = OteAccountBuilder.forClientId("myclientid"); @@ -249,7 +246,7 @@ public final class OteAccountBuilderTest { } @Test - public void testCreateOteEntities_entitiesExist_succeedsWhenReplaceExisting() { + void testCreateOteEntities_entitiesExist_succeedsWhenReplaceExisting() { persistSimpleResource(makeRegistrar1().asBuilder().setClientId("myclientid-1").build()); // we intentionally create the -ga TLD with the wrong state, to make sure it's overwritten. createTld("myclientid-ga", START_DATE_SUNRISE); @@ -264,7 +261,7 @@ public final class OteAccountBuilderTest { } @Test - public void testCreateOteEntities_doubleCreation_actuallyReplaces() { + void testCreateOteEntities_doubleCreation_actuallyReplaces() { OteAccountBuilder.forClientId("myclientid") .setPassword("oldPassword") .addContact("email@example.com") @@ -286,7 +283,7 @@ public final class OteAccountBuilderTest { } @Test - public void testCreateOteEntities_doubleCreation_keepsOldContacts() { + void testCreateOteEntities_doubleCreation_keepsOldContacts() { OteAccountBuilder.forClientId("myclientid").addContact("email@example.com").buildAndPersist(); assertContactExists("myclientid-3", "email@example.com"); @@ -301,7 +298,7 @@ public final class OteAccountBuilderTest { } @Test - public void testCreateClientIdToTldMap_validEntries() { + void testCreateClientIdToTldMap_validEntries() { assertThat(OteAccountBuilder.createClientIdToTldMap("myclientid")) .containsExactly( "myclientid-1", "myclientid-sunrise", @@ -311,7 +308,7 @@ public final class OteAccountBuilderTest { } @Test - public void testCreateClientIdToTldMap_invalidId() { + void testCreateClientIdToTldMap_invalidId() { IllegalArgumentException exception = assertThrows( IllegalArgumentException.class, () -> OteAccountBuilder.createClientIdToTldMap("a")); @@ -319,12 +316,12 @@ public final class OteAccountBuilderTest { } @Test - public void testGetBaseClientId_validOteId() { + void testGetBaseClientId_validOteId() { assertThat(OteAccountBuilder.getBaseClientId("myclientid-4")).isEqualTo("myclientid"); } @Test - public void testGetBaseClientId_invalidInput_malformed() { + void testGetBaseClientId_invalidInput_malformed() { assertThat( assertThrows( IllegalArgumentException.class, @@ -334,7 +331,7 @@ public final class OteAccountBuilderTest { } @Test - public void testGetBaseClientId_invalidInput_wrongForBase() { + void testGetBaseClientId_invalidInput_wrongForBase() { assertThat( assertThrows( IllegalArgumentException.class, diff --git a/core/src/test/java/google/registry/model/OteStatsTest.java b/core/src/test/java/google/registry/model/OteStatsTest.java index 01ff91dd6..719085653 100644 --- a/core/src/test/java/google/registry/model/OteStatsTest.java +++ b/core/src/test/java/google/registry/model/OteStatsTest.java @@ -18,19 +18,16 @@ import static com.google.common.truth.Truth.assertThat; import google.registry.model.OteStats.StatType; import google.registry.testing.AppEngineRule; -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; -@RunWith(JUnit4.class) public final class OteStatsTest { - @Rule + @RegisterExtension public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build(); @Test - public void testSuccess_allPass() throws Exception { + void testSuccess_allPass() throws Exception { OteStatsTestHelper.setupCompleteOte("blobio"); OteStats stats = OteStats.getFromRegistrar("blobio"); assertThat(stats.getFailures()).isEmpty(); @@ -38,7 +35,7 @@ public final class OteStatsTest { } @Test - public void testSuccess_incomplete() throws Exception { + void testSuccess_incomplete() throws Exception { OteStatsTestHelper.setupIncompleteOte("blobio"); OteStats stats = OteStats.getFromRegistrar("blobio"); assertThat(stats.getFailures()) @@ -49,7 +46,7 @@ public final class OteStatsTest { } @Test - public void testSuccess_toString() throws Exception { + void testSuccess_toString() throws Exception { OteStatsTestHelper.setupCompleteOte("blobio"); OteStats stats = OteStats.getFromRegistrar("blobio"); String expected = @@ -90,7 +87,7 @@ public final class OteStatsTest { } @Test - public void testIncomplete_toString() throws Exception { + void testIncomplete_toString() throws Exception { OteStatsTestHelper.setupIncompleteOte("blobio"); OteStats stats = OteStats.getFromRegistrar("blobio"); String expected = diff --git a/core/src/test/java/google/registry/model/SchemaVersionTest.java b/core/src/test/java/google/registry/model/SchemaVersionTest.java index 289314af3..c6831e15a 100644 --- a/core/src/test/java/google/registry/model/SchemaVersionTest.java +++ b/core/src/test/java/google/registry/model/SchemaVersionTest.java @@ -16,24 +16,21 @@ package google.registry.model; import google.registry.testing.AppEngineRule; import google.registry.testing.GoldenFileTestHelper; -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 SchemaVersion}. * *

If the test breaks, the instructions below will be printed. */ -@RunWith(JUnit4.class) public class SchemaVersionTest { - @Rule + @RegisterExtension public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build(); @Test - public void testGoldenSchemaFile() { + void testGoldenSchemaFile() { GoldenFileTestHelper.assertThat(SchemaVersion.getSchema()) .describedAs("Datastore schema") .createdByNomulusCommand("get_schema") diff --git a/core/src/test/java/google/registry/model/UpdateAutoTimestampTest.java b/core/src/test/java/google/registry/model/UpdateAutoTimestampTest.java index ee87b4d02..4102b1b18 100644 --- a/core/src/test/java/google/registry/model/UpdateAutoTimestampTest.java +++ b/core/src/test/java/google/registry/model/UpdateAutoTimestampTest.java @@ -23,39 +23,35 @@ import com.googlecode.objectify.annotation.Entity; import google.registry.model.common.CrossTldSingleton; import google.registry.testing.AppEngineRule; 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 UpdateAutoTimestamp}. */ -@RunWith(JUnit4.class) public class UpdateAutoTimestampTest { - @Rule + @RegisterExtension public final AppEngineRule appEngine = AppEngineRule.builder() .withDatastoreAndCloudSql() - .withOfyTestEntities(TestObject.class) + .withOfyTestEntities(UpdateAutoTimestampTestObject.class) .build(); /** Timestamped class. */ @Entity(name = "UatTestEntity") - public static class TestObject extends CrossTldSingleton { + public static class UpdateAutoTimestampTestObject extends CrossTldSingleton { UpdateAutoTimestamp updateTime = UpdateAutoTimestamp.create(null); } - private TestObject reload() { - return ofy().load().entity(new TestObject()).now(); + private UpdateAutoTimestampTestObject reload() { + return ofy().load().entity(new UpdateAutoTimestampTestObject()).now(); } @Test - public void testSaveSetsTime() { + void testSaveSetsTime() { DateTime transactionTime = - tm() - .transact( + tm().transact( () -> { - TestObject object = new TestObject(); + UpdateAutoTimestampTestObject object = new UpdateAutoTimestampTestObject(); assertThat(object.updateTime.timestamp).isNull(); ofy().save().entity(object); return tm().getTransactionTime(); @@ -65,12 +61,11 @@ public class UpdateAutoTimestampTest { } @Test - public void testResavingOverwritesOriginalTime() { + void testResavingOverwritesOriginalTime() { DateTime transactionTime = - tm() - .transact( + tm().transact( () -> { - TestObject object = new TestObject(); + UpdateAutoTimestampTestObject object = new UpdateAutoTimestampTestObject(); object.updateTime = UpdateAutoTimestamp.create(DateTime.now(UTC).minusDays(1)); ofy().save().entity(object); return tm().getTransactionTime(); diff --git a/core/src/test/java/google/registry/model/billing/BillingEventTest.java b/core/src/test/java/google/registry/model/billing/BillingEventTest.java index b83dce387..8275617fd 100644 --- a/core/src/test/java/google/registry/model/billing/BillingEventTest.java +++ b/core/src/test/java/google/registry/model/billing/BillingEventTest.java @@ -50,23 +50,23 @@ import org.junit.jupiter.api.Test; public class BillingEventTest extends EntityTestCase { private final DateTime now = DateTime.now(UTC); - public BillingEventTest() { + BillingEventTest() { super(JpaEntityCoverageCheck.ENABLED); } - HistoryEntry historyEntry; - HistoryEntry historyEntry2; - DomainBase domain; - BillingEvent.OneTime sqlOneTime; - BillingEvent.OneTime oneTime; - BillingEvent.OneTime oneTimeSynthetic; - BillingEvent.Recurring recurring; - BillingEvent.Cancellation cancellationOneTime; - BillingEvent.Cancellation cancellationRecurring; - BillingEvent.Modification modification; + private HistoryEntry historyEntry; + private HistoryEntry historyEntry2; + private DomainBase domain; + private BillingEvent.OneTime sqlOneTime; + private BillingEvent.OneTime oneTime; + private BillingEvent.OneTime oneTimeSynthetic; + private BillingEvent.Recurring recurring; + private BillingEvent.Cancellation cancellationOneTime; + private BillingEvent.Cancellation cancellationRecurring; + private BillingEvent.Modification modification; @BeforeEach - public void setUp() { + void setUp() { createTld("tld"); domain = persistActiveDomain("foo.tld"); historyEntry = persistResource( @@ -184,7 +184,7 @@ public class BillingEventTest extends EntityTestCase { } @Test - public void testCloudSqlPersistence_OneTime() { + void testCloudSqlPersistence_OneTime() { saveRegistrar("a registrar"); saveNewBillingEvent(sqlOneTime); @@ -203,7 +203,7 @@ public class BillingEventTest extends EntityTestCase { } @Test - public void testCloudSqlPersistence_Cancellation() { + void testCloudSqlPersistence_Cancellation() { saveRegistrar("a registrar"); saveNewBillingEvent(sqlOneTime); VKey sqlVKey = VKey.createSql(BillingEvent.OneTime.class, sqlOneTime.id); @@ -235,7 +235,7 @@ public class BillingEventTest extends EntityTestCase { } @Test - public void testCloudSqlPersistence_Recurring() { + void testCloudSqlPersistence_Recurring() { saveRegistrar("a registrar"); BillingEvent.Recurring sqlRecurring = recurring @@ -256,7 +256,7 @@ public class BillingEventTest extends EntityTestCase { } @Test - public void testPersistence() { + void testPersistence() { assertThat(ofy().load().entity(oneTime).now()).isEqualTo(oneTime); assertThat(ofy().load().entity(oneTimeSynthetic).now()).isEqualTo(oneTimeSynthetic); assertThat(ofy().load().entity(recurring).now()).isEqualTo(recurring); @@ -266,7 +266,7 @@ public class BillingEventTest extends EntityTestCase { } @Test - public void testParenting() { + void testParenting() { // Note that these are all tested separately because BillingEvent is an abstract base class that // lacks the @Entity annotation, and thus we cannot call .type(BillingEvent.class) assertThat(ofy().load().type(BillingEvent.OneTime.class).ancestor(domain).list()) @@ -288,7 +288,7 @@ public class BillingEventTest extends EntityTestCase { } @Test - public void testCancellationMatching() { + void testCancellationMatching() { Key recurringKey = ofy() .load() @@ -300,7 +300,7 @@ public class BillingEventTest extends EntityTestCase { } @Test - public void testIndexing() throws Exception { + void testIndexing() throws Exception { verifyIndexing( oneTime, "clientId", @@ -322,7 +322,7 @@ public class BillingEventTest extends EntityTestCase { } @Test - public void testFailure_syntheticFlagWithoutCreationTime() { + void testFailure_syntheticFlagWithoutCreationTime() { IllegalStateException thrown = assertThrows( IllegalStateException.class, @@ -338,7 +338,7 @@ public class BillingEventTest extends EntityTestCase { } @Test - public void testFailure_syntheticCreationTimeWithoutFlag() { + void testFailure_syntheticCreationTimeWithoutFlag() { IllegalStateException thrown = assertThrows( IllegalStateException.class, @@ -349,7 +349,7 @@ public class BillingEventTest extends EntityTestCase { } @Test - public void testFailure_syntheticFlagWithoutCancellationMatchingKey() { + void testFailure_syntheticFlagWithoutCancellationMatchingKey() { IllegalStateException thrown = assertThrows( IllegalStateException.class, @@ -367,7 +367,7 @@ public class BillingEventTest extends EntityTestCase { } @Test - public void testFailure_cancellationMatchingKeyWithoutFlag() { + void testFailure_cancellationMatchingKeyWithoutFlag() { IllegalStateException thrown = assertThrows( IllegalStateException.class, @@ -384,7 +384,7 @@ public class BillingEventTest extends EntityTestCase { } @Test - public void testSuccess_cancellation_forGracePeriod_withOneTime() { + void testSuccess_cancellation_forGracePeriod_withOneTime() { BillingEvent.Cancellation newCancellation = BillingEvent.Cancellation.forGracePeriod( GracePeriod.forBillingEvent(GracePeriodStatus.ADD, oneTime), historyEntry2, @@ -395,7 +395,7 @@ public class BillingEventTest extends EntityTestCase { } @Test - public void testSuccess_cancellation_forGracePeriod_withRecurring() { + void testSuccess_cancellation_forGracePeriod_withRecurring() { BillingEvent.Cancellation newCancellation = BillingEvent.Cancellation.forGracePeriod( GracePeriod.createForRecurring( GracePeriodStatus.AUTO_RENEW, @@ -410,7 +410,7 @@ public class BillingEventTest extends EntityTestCase { } @Test - public void testFailure_cancellation_forGracePeriodWithoutBillingEvent() { + void testFailure_cancellation_forGracePeriodWithoutBillingEvent() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -424,7 +424,7 @@ public class BillingEventTest extends EntityTestCase { } @Test - public void testFailure_cancellationWithNoBillingEvent() { + void testFailure_cancellationWithNoBillingEvent() { IllegalStateException thrown = assertThrows( IllegalStateException.class, @@ -438,7 +438,7 @@ public class BillingEventTest extends EntityTestCase { } @Test - public void testFailure_cancellationWithBothBillingEvents() { + void testFailure_cancellationWithBothBillingEvents() { IllegalStateException thrown = assertThrows( IllegalStateException.class, @@ -452,7 +452,7 @@ public class BillingEventTest extends EntityTestCase { } @Test - public void testDeadCodeThatDeletedScrapCommandsReference() { + void testDeadCodeThatDeletedScrapCommandsReference() { assertThat(recurring.getParentKey()).isEqualTo(Key.create(historyEntry)); new BillingEvent.OneTime.Builder().setParent(Key.create(historyEntry)); } diff --git a/core/src/test/java/google/registry/model/common/CursorTest.java b/core/src/test/java/google/registry/model/common/CursorTest.java index 5d427dce1..65d2ae593 100644 --- a/core/src/test/java/google/registry/model/common/CursorTest.java +++ b/core/src/test/java/google/registry/model/common/CursorTest.java @@ -31,19 +31,19 @@ import google.registry.model.domain.DomainBase; import google.registry.model.registry.Registry; import google.registry.schema.cursor.CursorDao; import org.joda.time.DateTime; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** Unit tests for {@link Cursor}. */ -public class CursorTest extends EntityTestCase { +class CursorTest extends EntityTestCase { - @Before - public void setUp() { + @BeforeEach + void setUp() { fakeClock.setTo(DateTime.parse("2010-10-17TZ")); } @Test - public void testSuccess_persistScopedCursor() { + void testSuccess_persistScopedCursor() { createTld("tld"); this.fakeClock.advanceOneMilli(); final DateTime time = DateTime.parse("2012-07-12T03:30:00.000Z"); @@ -61,7 +61,7 @@ public class CursorTest extends EntityTestCase { } @Test - public void testSuccess_persistGlobalCursor() { + void testSuccess_persistGlobalCursor() { final DateTime time = DateTime.parse("2012-07-12T03:30:00.000Z"); CursorDao.saveCursor(Cursor.createGlobal(RECURRING_BILLING, time), GLOBAL); assertThat(ofy().load().key(Cursor.createGlobalKey(RECURRING_BILLING)).now().getCursorTime()) @@ -70,7 +70,7 @@ public class CursorTest extends EntityTestCase { } @Test - public void testIndexing() throws Exception { + void testIndexing() throws Exception { final DateTime time = DateTime.parse("2012-07-12T03:30:00.000Z"); CursorDao.saveCursor(Cursor.createGlobal(RECURRING_BILLING, time), GLOBAL); Cursor cursor = ofy().load().key(Cursor.createGlobalKey(RECURRING_BILLING)).now(); @@ -79,7 +79,7 @@ public class CursorTest extends EntityTestCase { } @Test - public void testFailure_invalidScopeOnCreate() { + void testFailure_invalidScopeOnCreate() { createTld("tld"); this.fakeClock.advanceOneMilli(); final DateTime time = DateTime.parse("2012-07-12T03:30:00.000Z"); @@ -94,7 +94,7 @@ public class CursorTest extends EntityTestCase { } @Test - public void testFailure_invalidScopeOnKeyCreate() { + void testFailure_invalidScopeOnKeyCreate() { createTld("tld"); IllegalArgumentException thrown = assertThrows( @@ -106,14 +106,14 @@ public class CursorTest extends EntityTestCase { } @Test - public void testFailure_createGlobalKeyForScopedCursorType() { + void testFailure_createGlobalKeyForScopedCursorType() { IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () -> Cursor.createGlobalKey(RDE_UPLOAD)); assertThat(thrown).hasMessageThat().contains("Cursor type is not a global cursor"); } @Test - public void testFailure_invalidScopeOnGlobalKeyCreate() { + void testFailure_invalidScopeOnGlobalKeyCreate() { createTld("tld"); IllegalArgumentException thrown = assertThrows( @@ -125,7 +125,7 @@ public class CursorTest extends EntityTestCase { } @Test - public void testFailure_nullScope() { + void testFailure_nullScope() { NullPointerException thrown = assertThrows( NullPointerException.class, @@ -134,7 +134,7 @@ public class CursorTest extends EntityTestCase { } @Test - public void testFailure_nullCursorType() { + void testFailure_nullCursorType() { createTld("tld"); NullPointerException thrown = assertThrows( @@ -144,7 +144,7 @@ public class CursorTest extends EntityTestCase { } @Test - public void testFailure_nullTime() { + void testFailure_nullTime() { createTld("tld"); NullPointerException thrown = assertThrows( diff --git a/core/src/test/java/google/registry/model/common/GaeUserIdConverterTest.java b/core/src/test/java/google/registry/model/common/GaeUserIdConverterTest.java index 5095aa6f1..ed0dafd55 100644 --- a/core/src/test/java/google/registry/model/common/GaeUserIdConverterTest.java +++ b/core/src/test/java/google/registry/model/common/GaeUserIdConverterTest.java @@ -19,32 +19,29 @@ import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.persistence.transaction.TransactionManagerFactory.tm; import google.registry.testing.AppEngineRule; -import org.junit.After; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; /** Unit tests for {@link GaeUserIdConverter}. */ -@RunWith(JUnit4.class) public class GaeUserIdConverterTest { - @Rule + @RegisterExtension public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build(); - @After - public void verifyNoLingeringEntities() { + @AfterEach + void verifyNoLingeringEntities() { assertThat(ofy().load().type(GaeUserIdConverter.class).count()).isEqualTo(0); } @Test - public void testSuccess() { + void testSuccess() { assertThat(GaeUserIdConverter.convertEmailAddressToGaeUserId("example@example.com")) .matches("[0-9]+"); } @Test - public void testSuccess_inTransaction() { + void testSuccess_inTransaction() { tm() .transactNew( () -> diff --git a/core/src/test/java/google/registry/model/common/TimeOfYearTest.java b/core/src/test/java/google/registry/model/common/TimeOfYearTest.java index a66774b07..c44f33e88 100644 --- a/core/src/test/java/google/registry/model/common/TimeOfYearTest.java +++ b/core/src/test/java/google/registry/model/common/TimeOfYearTest.java @@ -21,27 +21,24 @@ import static google.registry.util.DateTimeUtils.START_OF_TIME; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Range; 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; /** Unit tests for {@link TimeOfYear}. */ -@RunWith(JUnit4.class) -public class TimeOfYearTest { +class TimeOfYearTest { private static final DateTime february28 = DateTime.parse("2012-02-28T01:02:03.0Z"); private static final DateTime february29 = DateTime.parse("2012-02-29T01:02:03.0Z"); private static final DateTime march1 = DateTime.parse("2012-03-01T01:02:03.0Z"); @Test - public void testSuccess_fromDateTime() { + void testSuccess_fromDateTime() { // We intentionally don't allow leap years in TimeOfYear, so February 29 should be February 28. assertThat(TimeOfYear.fromDateTime(february28)).isEqualTo(TimeOfYear.fromDateTime(february29)); assertThat(TimeOfYear.fromDateTime(february29)).isNotEqualTo(TimeOfYear.fromDateTime(march1)); } @Test - public void testSuccess_nextAfter() { + void testSuccess_nextAfter() { // This should be lossless because atOrAfter includes an exact match. assertThat(TimeOfYear.fromDateTime(march1).getNextInstanceAtOrAfter(march1)).isEqualTo(march1); // This should be a year later because we stepped forward a millisecond @@ -50,7 +47,7 @@ public class TimeOfYearTest { } @Test - public void testSuccess_nextBefore() { + void testSuccess_nextBefore() { // This should be lossless because beforeOrAt includes an exact match. assertThat(TimeOfYear.fromDateTime(march1).getLastInstanceBeforeOrAt(march1)).isEqualTo(march1); // This should be a year earlier because we stepped backward a millisecond @@ -59,7 +56,7 @@ public class TimeOfYearTest { } @Test - public void testSuccess_getInstancesInRange_closed() { + void testSuccess_getInstancesInRange_closed() { DateTime startDate = DateTime.parse("2012-05-01T00:00:00Z"); DateTime endDate = DateTime.parse("2016-05-01T00:00:00Z"); TimeOfYear timeOfYear = TimeOfYear.fromDateTime(DateTime.parse("2012-05-01T00:00:00Z")); @@ -74,7 +71,7 @@ public class TimeOfYearTest { } @Test - public void testSuccess_getInstancesInRange_openClosed() { + void testSuccess_getInstancesInRange_openClosed() { DateTime startDate = DateTime.parse("2012-05-01T00:00:00Z"); DateTime endDate = DateTime.parse("2016-05-01T00:00:00Z"); TimeOfYear timeOfYear = TimeOfYear.fromDateTime(DateTime.parse("2012-05-01T00:00:00Z")); @@ -88,7 +85,7 @@ public class TimeOfYearTest { } @Test - public void testSuccess_getInstancesInRange_closedOpen() { + void testSuccess_getInstancesInRange_closedOpen() { DateTime startDate = DateTime.parse("2012-05-01T00:00:00Z"); DateTime endDate = DateTime.parse("2016-05-01T00:00:00Z"); TimeOfYear timeOfYear = TimeOfYear.fromDateTime(DateTime.parse("2012-05-01T00:00:00Z")); @@ -102,7 +99,7 @@ public class TimeOfYearTest { } @Test - public void testSuccess_getInstancesInRange_open() { + void testSuccess_getInstancesInRange_open() { DateTime startDate = DateTime.parse("2012-05-01T00:00:00Z"); DateTime endDate = DateTime.parse("2016-05-01T00:00:00Z"); TimeOfYear timeOfYear = TimeOfYear.fromDateTime(DateTime.parse("2012-05-01T00:00:00Z")); @@ -115,7 +112,7 @@ public class TimeOfYearTest { } @Test - public void testSuccess_getInstancesInRange_normalizedLowerBound() { + void testSuccess_getInstancesInRange_normalizedLowerBound() { TimeOfYear timeOfYear = TimeOfYear.fromDateTime(START_OF_TIME); ImmutableSet expected = ImmutableSet.of(START_OF_TIME, START_OF_TIME.plusYears(1), START_OF_TIME.plusYears(2)); @@ -124,7 +121,7 @@ public class TimeOfYearTest { } @Test - public void testSuccess_getInstancesInRange_normalizedUpperBound() { + void testSuccess_getInstancesInRange_normalizedUpperBound() { TimeOfYear timeOfYear = TimeOfYear.fromDateTime(END_OF_TIME); ImmutableSet expected = ImmutableSet.of(END_OF_TIME.minusYears(2), END_OF_TIME.minusYears(1), END_OF_TIME); @@ -133,7 +130,7 @@ public class TimeOfYearTest { } @Test - public void testSuccess_getInstancesOfTimeOfYearInRange_empty() { + void testSuccess_getInstancesOfTimeOfYearInRange_empty() { DateTime startDate = DateTime.parse("2012-05-01T00:00:00Z"); DateTime endDate = DateTime.parse("2013-02-01T00:00:00Z"); TimeOfYear timeOfYear = TimeOfYear.fromDateTime(DateTime.parse("2012-03-01T00:00:00Z")); diff --git a/core/src/test/java/google/registry/model/common/TimedTransitionPropertyTest.java b/core/src/test/java/google/registry/model/common/TimedTransitionPropertyTest.java index d8f785f28..3421c536c 100644 --- a/core/src/test/java/google/registry/model/common/TimedTransitionPropertyTest.java +++ b/core/src/test/java/google/registry/model/common/TimedTransitionPropertyTest.java @@ -26,14 +26,11 @@ import com.google.common.collect.ImmutableSortedMap; import java.util.Map; import java.util.Set; import org.joda.time.DateTime; -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 TimedTransitionProperty}. */ -@RunWith(JUnit4.class) -public class TimedTransitionPropertyTest { +class TimedTransitionPropertyTest { private static final DateTime A_LONG_TIME_AGO = new DateTime(Long.MIN_VALUE, UTC); private static final DateTime DATE_1 = DateTime.parse("2001-01-01T00:00:00.0Z"); @@ -64,15 +61,15 @@ public class TimedTransitionPropertyTest { DATE_2, "2", DATE_3, "3"); - TimedTransitionProperty timedString; + private TimedTransitionProperty timedString; - @Before - public void init() { + @BeforeEach + void init() { timedString = TimedTransitionProperty.fromValueMap(values, StringTimedTransition.class); } @Test - public void testSuccess_toValueMap() { + void testSuccess_toValueMap() { assertThat(timedString.toValueMap()).isEqualTo(values); } @@ -94,12 +91,12 @@ public class TimedTransitionPropertyTest { } @Test - public void testSuccess_getValueAtTime() { + void testSuccess_getValueAtTime() { testGetValueAtTime(timedString); } @Test - public void testSuccess_getNextTransitionAfter() { + void testSuccess_getNextTransitionAfter() { assertThat(timedString.getNextTransitionAfter(A_LONG_TIME_AGO)).isEqualTo(DATE_1); assertThat(timedString.getNextTransitionAfter(START_OF_TIME.plusMillis(1))).isEqualTo(DATE_1); assertThat(timedString.getNextTransitionAfter(DATE_1.minusMillis(1))).isEqualTo(DATE_1); @@ -110,7 +107,7 @@ public class TimedTransitionPropertyTest { } @Test - public void testSuccess_simulatedLoad() { + void testSuccess_simulatedLoad() { // Just for testing, don't extract transitions from a TimedTransitionProperty in real code. Set> transitions = timedString.entrySet(); timedString = forMapify("0", StringTimedTransition.class); @@ -124,7 +121,7 @@ public class TimedTransitionPropertyTest { } @Test - public void testFailure_valueMapNotChronologicallyOrdered() { + void testFailure_valueMapNotChronologicallyOrdered() { assertThrows( IllegalArgumentException.class, () -> @@ -134,7 +131,7 @@ public class TimedTransitionPropertyTest { } @Test - public void testFailure_transitionTimeBeforeStartOfTime() { + void testFailure_transitionTimeBeforeStartOfTime() { assertThrows( IllegalArgumentException.class, () -> @@ -143,7 +140,7 @@ public class TimedTransitionPropertyTest { } @Test - public void testFailure_noValues() { + void testFailure_noValues() { assertThrows( IllegalArgumentException.class, () -> @@ -152,7 +149,7 @@ public class TimedTransitionPropertyTest { } @Test - public void testFailure_noValueAtStartOfTime() { + void testFailure_noValueAtStartOfTime() { assertThrows( IllegalArgumentException.class, () -> @@ -161,7 +158,7 @@ public class TimedTransitionPropertyTest { } @Test - public void testFailure_noValuesAfterSimulatedEmptyLoad() { + void testFailure_noValuesAfterSimulatedEmptyLoad() { timedString = forMapify("0", StringTimedTransition.class); // Simulate a load from Datastore by clearing, but don't insert any transitions. timedString.clear(); @@ -169,7 +166,7 @@ public class TimedTransitionPropertyTest { } @Test - public void testFailure_noValueAtStartOfTimeAfterSimulatedLoad() { + void testFailure_noValueAtStartOfTimeAfterSimulatedLoad() { // Just for testing, don't extract transitions from a TimedTransitionProperty in real code. StringTimedTransition transition1 = timedString.get(DATE_1); timedString = forMapify("0", StringTimedTransition.class); diff --git a/core/src/test/java/google/registry/model/contact/ContactCommandTest.java b/core/src/test/java/google/registry/model/contact/ContactCommandTest.java index 7cc5a0910..847b45f3b 100644 --- a/core/src/test/java/google/registry/model/contact/ContactCommandTest.java +++ b/core/src/test/java/google/registry/model/contact/ContactCommandTest.java @@ -22,16 +22,13 @@ import static java.nio.charset.StandardCharsets.UTF_8; import google.registry.testing.AppEngineRule; import google.registry.testing.EppLoader; -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 xml roundtripping of commands. */ -@RunWith(JUnit4.class) public class ContactCommandTest { - @Rule + @RegisterExtension public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build(); private void doXmlRoundtripTest(String inputFilename) throws Exception { @@ -49,52 +46,52 @@ public class ContactCommandTest { } @Test - public void testCreate() throws Exception { + void testCreate() throws Exception { doXmlRoundtripTest("contact_create.xml"); } @Test - public void testDelete() throws Exception { + void testDelete() throws Exception { doXmlRoundtripTest("contact_delete.xml"); } @Test - public void testUpdate() throws Exception { + void testUpdate() throws Exception { doXmlRoundtripTest("contact_update.xml"); } @Test - public void testInfo() throws Exception { + void testInfo() throws Exception { doXmlRoundtripTest("contact_info.xml"); } @Test - public void testCheck() throws Exception { + void testCheck() throws Exception { doXmlRoundtripTest("contact_check.xml"); } @Test - public void testTransferApprove() throws Exception { + void testTransferApprove() throws Exception { doXmlRoundtripTest("contact_transfer_approve.xml"); } @Test - public void testTransferReject() throws Exception { + void testTransferReject() throws Exception { doXmlRoundtripTest("contact_transfer_reject.xml"); } @Test - public void testTransferCancel() throws Exception { + void testTransferCancel() throws Exception { doXmlRoundtripTest("contact_transfer_cancel.xml"); } @Test - public void testTransferQuery() throws Exception { + void testTransferQuery() throws Exception { doXmlRoundtripTest("contact_transfer_query.xml"); } @Test - public void testTransferRequest() throws Exception { + void testTransferRequest() throws Exception { doXmlRoundtripTest("contact_transfer_request.xml"); } } diff --git a/core/src/test/java/google/registry/model/contact/ContactResourceTest.java b/core/src/test/java/google/registry/model/contact/ContactResourceTest.java index 9259ead89..b4043357e 100644 --- a/core/src/test/java/google/registry/model/contact/ContactResourceTest.java +++ b/core/src/test/java/google/registry/model/contact/ContactResourceTest.java @@ -45,15 +45,15 @@ import org.junit.jupiter.api.Test; /** Unit tests for {@link ContactResource}. */ public class ContactResourceTest extends EntityTestCase { - ContactResource originalContact; - ContactResource contactResource; + private ContactResource originalContact; + private ContactResource contactResource; - public ContactResourceTest() { + ContactResourceTest() { super(JpaEntityCoverageCheck.ENABLED); } @BeforeEach - public void setUp() { + void setUp() { createTld("foobar"); originalContact = new ContactResource.Builder() @@ -124,12 +124,12 @@ public class ContactResourceTest extends EntityTestCase { } @Test - public void testCloudSqlPersistence_failWhenViolateForeignKeyConstraint() { + void testCloudSqlPersistence_failWhenViolateForeignKeyConstraint() { assertThrowForeignKeyViolation(() -> jpaTm().transact(() -> jpaTm().saveNew(originalContact))); } @Test - public void testCloudSqlPersistence_succeed() { + void testCloudSqlPersistence_succeed() { saveRegistrar("registrar1"); saveRegistrar("registrar2"); saveRegistrar("registrar3"); @@ -158,7 +158,7 @@ public class ContactResourceTest extends EntityTestCase { } @Test - public void testPersistence() { + void testPersistence() { assertThat( loadByForeignKey( ContactResource.class, contactResource.getForeignKey(), fakeClock.nowUtc())) @@ -166,12 +166,12 @@ public class ContactResourceTest extends EntityTestCase { } @Test - public void testIndexing() throws Exception { + void testIndexing() throws Exception { verifyIndexing(contactResource, "deletionTime", "currentSponsorClientId", "searchName"); } @Test - public void testEmptyStringsBecomeNull() { + void testEmptyStringsBecomeNull() { assertThat(new ContactResource.Builder().setContactId(null).build().getContactId()).isNull(); assertThat(new ContactResource.Builder().setContactId("").build().getContactId()).isNull(); assertThat(new ContactResource.Builder().setContactId(" ").build().getContactId()).isNotNull(); @@ -203,7 +203,7 @@ public class ContactResourceTest extends EntityTestCase { } @Test - public void testEmptyTransferDataBecomesNull() { + void testEmptyTransferDataBecomesNull() { ContactResource withNull = new ContactResource.Builder().setTransferData(null).build(); ContactResource withEmpty = withNull.asBuilder().setTransferData(ContactTransferData.EMPTY).build(); @@ -212,7 +212,7 @@ public class ContactResourceTest extends EntityTestCase { } @Test - public void testImplicitStatusValues() { + void testImplicitStatusValues() { // OK is implicit if there's no other statuses. assertAboutContacts() .that(new ContactResource.Builder().build()) @@ -234,7 +234,7 @@ public class ContactResourceTest extends EntityTestCase { } @Test - public void testExpiredTransfer() { + void testExpiredTransfer() { ContactResource afterTransfer = contactResource .asBuilder() @@ -255,7 +255,7 @@ public class ContactResourceTest extends EntityTestCase { } @Test - public void testSetCreationTime_cantBeCalledTwice() { + void testSetCreationTime_cantBeCalledTwice() { IllegalStateException thrown = assertThrows( IllegalStateException.class, @@ -264,7 +264,7 @@ public class ContactResourceTest extends EntityTestCase { } @Test - public void testToHydratedString_notCircular() { + void testToHydratedString_notCircular() { // If there are circular references, this will overflow the stack. contactResource.toHydratedString(); } diff --git a/core/src/test/java/google/registry/model/domain/DomainBaseSqlTest.java b/core/src/test/java/google/registry/model/domain/DomainBaseSqlTest.java index 9e415cfe9..94ea45bc6 100644 --- a/core/src/test/java/google/registry/model/domain/DomainBaseSqlTest.java +++ b/core/src/test/java/google/registry/model/domain/DomainBaseSqlTest.java @@ -55,16 +55,16 @@ public class DomainBaseSqlTest { JpaIntegrationWithCoverageExtension jpa = new JpaTestRules.Builder().withClock(fakeClock).buildIntegrationWithCoverageExtension(); - DomainBase domain; - VKey contactKey; - VKey contact2Key; - VKey host1VKey; - HostResource host; - ContactResource contact; - ContactResource contact2; + private DomainBase domain; + private VKey contactKey; + private VKey contact2Key; + private VKey host1VKey; + private HostResource host; + private ContactResource contact; + private ContactResource contact2; @BeforeEach - public void setUp() { + void setUp() { saveRegistrar("registrar1"); saveRegistrar("registrar2"); saveRegistrar("registrar3"); @@ -114,7 +114,7 @@ public class DomainBaseSqlTest { } @Test - public void testDomainBasePersistence() { + void testDomainBasePersistence() { jpaTm() .transact( () -> { @@ -159,7 +159,7 @@ public class DomainBaseSqlTest { } @Test - public void testHostForeignKeyConstraints() { + void testHostForeignKeyConstraints() { assertThrowForeignKeyViolation( () -> { jpaTm() @@ -174,7 +174,7 @@ public class DomainBaseSqlTest { } @Test - public void testContactForeignKeyConstraints() { + void testContactForeignKeyConstraints() { assertThrowForeignKeyViolation( () -> { jpaTm() @@ -187,7 +187,7 @@ public class DomainBaseSqlTest { }); } - public static ContactResource makeContact(String repoId) { + static ContactResource makeContact(String repoId) { return new ContactResource.Builder() .setRepoId(repoId) .setCreationClientId("registrar1") diff --git a/core/src/test/java/google/registry/model/domain/DomainBaseTest.java b/core/src/test/java/google/registry/model/domain/DomainBaseTest.java index 578541df9..e1db6b079 100644 --- a/core/src/test/java/google/registry/model/domain/DomainBaseTest.java +++ b/core/src/test/java/google/registry/model/domain/DomainBaseTest.java @@ -57,8 +57,8 @@ import google.registry.model.transfer.TransferStatus; import google.registry.persistence.VKey; import org.joda.money.Money; import org.joda.time.DateTime; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** Unit tests for {@link DomainBase}. */ public class DomainBaseTest extends EntityTestCase { @@ -68,8 +68,8 @@ public class DomainBaseTest extends EntityTestCase { private Key recurringBillKey; private Key domainKey; - @Before - public void setUp() { + @BeforeEach + void setUp() { createTld("com"); domainKey = Key.create(null, DomainBase.class, "4-COM"); VKey hostKey = @@ -163,13 +163,13 @@ public class DomainBaseTest extends EntityTestCase { } @Test - public void testPersistence() { + void testPersistence() { assertThat(loadByForeignKey(DomainBase.class, domain.getForeignKey(), fakeClock.nowUtc())) .hasValue(domain); } @Test - public void testIndexing() throws Exception { + void testIndexing() throws Exception { verifyIndexing( domain, "allContacts.contact", @@ -181,7 +181,7 @@ public class DomainBaseTest extends EntityTestCase { } @Test - public void testEmptyStringsBecomeNull() { + void testEmptyStringsBecomeNull() { assertThat( newDomainBase("example.com") .asBuilder() @@ -206,7 +206,7 @@ public class DomainBaseTest extends EntityTestCase { } @Test - public void testEmptySetsAndArraysBecomeNull() { + void testEmptySetsAndArraysBecomeNull() { assertThat( newDomainBase("example.com") .asBuilder() @@ -262,7 +262,7 @@ public class DomainBaseTest extends EntityTestCase { } @Test - public void testEmptyTransferDataBecomesNull() { + void testEmptyTransferDataBecomesNull() { DomainBase withNull = newDomainBase("example.com").asBuilder().setTransferData(null).build(); DomainBase withEmpty = withNull.asBuilder().setTransferData(DomainTransferData.EMPTY).build(); assertThat(withNull).isEqualTo(withEmpty); @@ -270,7 +270,7 @@ public class DomainBaseTest extends EntityTestCase { } @Test - public void testImplicitStatusValues() { + void testImplicitStatusValues() { ImmutableSet> nameservers = ImmutableSet.of(newHostResource("foo.example.tld").createVKey()); StatusValue[] statuses = {StatusValue.OK}; @@ -402,12 +402,12 @@ public class DomainBaseTest extends EntityTestCase { } @Test - public void testExpiredTransfer() { + void testExpiredTransfer() { doExpiredTransferTest(fakeClock.nowUtc().plusMonths(1)); } @Test - public void testExpiredTransfer_autoRenewBeforeTransfer() { + void testExpiredTransfer_autoRenewBeforeTransfer() { // Since transfer swallows a preceding autorenew, this should be identical to the regular // transfer case (and specifically, the new expiration and grace periods will be the same as if // there was no autorenew). @@ -434,7 +434,7 @@ public class DomainBaseTest extends EntityTestCase { } @Test - public void testEppLastUpdateTimeAndClientId_autoRenewBeforeTransferSuccess() { + void testEppLastUpdateTimeAndClientId_autoRenewBeforeTransferSuccess() { DateTime now = fakeClock.nowUtc(); DateTime transferRequestDateTime = now.plusDays(1); DateTime autorenewDateTime = now.plusDays(3); @@ -453,7 +453,7 @@ public class DomainBaseTest extends EntityTestCase { } @Test - public void testEppLastUpdateTimeAndClientId_autoRenewAfterTransferSuccess() { + void testEppLastUpdateTimeAndClientId_autoRenewAfterTransferSuccess() { DateTime now = fakeClock.nowUtc(); DateTime transferRequestDateTime = now.plusDays(1); DateTime autorenewDateTime = now.plusDays(3); @@ -483,7 +483,7 @@ public class DomainBaseTest extends EntityTestCase { } @Test - public void testEppLastUpdateTimeAndClientId_isSetCorrectlyWithNullPreviousValue() { + void testEppLastUpdateTimeAndClientId_isSetCorrectlyWithNullPreviousValue() { DateTime now = fakeClock.nowUtc(); DateTime autorenewDateTime = now.plusDays(3); setupUnmodifiedDomain(autorenewDateTime); @@ -498,7 +498,7 @@ public class DomainBaseTest extends EntityTestCase { } @Test - public void testStackedGracePeriods() { + void testStackedGracePeriods() { ImmutableList gracePeriods = ImmutableList.of( GracePeriod.create(GracePeriodStatus.ADD, fakeClock.nowUtc().plusDays(3), "foo", null), @@ -512,7 +512,7 @@ public class DomainBaseTest extends EntityTestCase { } @Test - public void testGracePeriodsByType() { + void testGracePeriodsByType() { ImmutableSet addGracePeriods = ImmutableSet.of( GracePeriod.create(GracePeriodStatus.ADD, fakeClock.nowUtc().plusDays(3), "foo", null), @@ -536,7 +536,7 @@ public class DomainBaseTest extends EntityTestCase { } @Test - public void testRenewalsHappenAtExpiration() { + void testRenewalsHappenAtExpiration() { DomainBase renewed = domain.cloneProjectedAtTime(domain.getRegistrationExpirationTime()); assertThat(renewed.getRegistrationExpirationTime()) .isEqualTo(domain.getRegistrationExpirationTime().plusYears(1)); @@ -546,14 +546,14 @@ public class DomainBaseTest extends EntityTestCase { } @Test - public void testTldGetsSet() { + void testTldGetsSet() { createTld("tld"); domain = newDomainBase("foo.tld"); assertThat(domain.getTld()).isEqualTo("tld"); } @Test - public void testRenewalsDontHappenOnFebruary29() { + void testRenewalsDontHappenOnFebruary29() { domain = domain .asBuilder() @@ -565,7 +565,7 @@ public class DomainBaseTest extends EntityTestCase { } @Test - public void testMultipleAutoRenews() { + void testMultipleAutoRenews() { // Change the registry so that renewal costs change every year to make sure we are using the // autorenew time as the lookup time for the cost. DateTime oldExpirationTime = domain.getRegistrationExpirationTime(); @@ -599,12 +599,12 @@ public class DomainBaseTest extends EntityTestCase { } @Test - public void testToHydratedString_notCircular() { + void testToHydratedString_notCircular() { domain.toHydratedString(); // If there are circular references, this will overflow the stack. } @Test - public void testFailure_uppercaseDomainName() { + void testFailure_uppercaseDomainName() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, () -> domain.asBuilder().setDomainName("AAA.BBB")); @@ -614,7 +614,7 @@ public class DomainBaseTest extends EntityTestCase { } @Test - public void testFailure_utf8DomainName() { + void testFailure_utf8DomainName() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, () -> domain.asBuilder().setDomainName("みんな.みんな")); @@ -624,7 +624,7 @@ public class DomainBaseTest extends EntityTestCase { } @Test - public void testClone_doNotExtendExpirationOnDeletedDomain() { + void testClone_doNotExtendExpirationOnDeletedDomain() { DateTime now = DateTime.now(UTC); domain = persistResource( @@ -639,7 +639,7 @@ public class DomainBaseTest extends EntityTestCase { } @Test - public void testClone_doNotExtendExpirationOnFutureDeletedDomain() { + void testClone_doNotExtendExpirationOnFutureDeletedDomain() { // if a domain is in pending deletion (StatusValue.PENDING_DELETE), don't extend expiration DateTime now = DateTime.now(UTC); domain = @@ -655,7 +655,7 @@ public class DomainBaseTest extends EntityTestCase { } @Test - public void testClone_extendsExpirationForExpiredTransferredDomain() { + void testClone_extendsExpirationForExpiredTransferredDomain() { // If the transfer implicitly succeeded, the expiration time should be extended DateTime now = DateTime.now(UTC); DateTime transferExpirationTime = now.minusDays(1); @@ -682,7 +682,7 @@ public class DomainBaseTest extends EntityTestCase { } @Test - public void testClone_extendsExpirationForNonExpiredTransferredDomain() { + void testClone_extendsExpirationForNonExpiredTransferredDomain() { // If the transfer implicitly succeeded, the expiration time should be extended even if it // hadn't already expired DateTime now = DateTime.now(UTC); @@ -710,7 +710,7 @@ public class DomainBaseTest extends EntityTestCase { } @Test - public void testClone_doesNotExtendExpirationForPendingTransfer() { + void testClone_doesNotExtendExpirationForPendingTransfer() { // Pending transfers shouldn't affect the expiration time DateTime now = DateTime.now(UTC); DateTime transferExpirationTime = now.plusDays(1); @@ -735,7 +735,7 @@ public class DomainBaseTest extends EntityTestCase { } @Test - public void testClone_transferDuringAutorenew() { + void testClone_transferDuringAutorenew() { // When the domain is an an autorenew grace period, we should not extend the registration // expiration by a further year--it should just be whatever the autorenew was DateTime now = DateTime.now(UTC); diff --git a/core/src/test/java/google/registry/model/domain/DomainCommandTest.java b/core/src/test/java/google/registry/model/domain/DomainCommandTest.java index e043f2262..68dc42a3f 100644 --- a/core/src/test/java/google/registry/model/domain/DomainCommandTest.java +++ b/core/src/test/java/google/registry/model/domain/DomainCommandTest.java @@ -22,60 +22,60 @@ import google.registry.model.eppinput.EppInput; import google.registry.model.eppinput.EppInput.ResourceCommandWrapper; import google.registry.model.eppinput.ResourceCommand; import google.registry.testing.EppLoader; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** Tests for DomainCommand. */ -public class DomainCommandTest extends ResourceCommandTestCase { +class DomainCommandTest extends ResourceCommandTestCase { @Test - public void testCreate() throws Exception { + void testCreate() throws Exception { doXmlRoundtripTest("domain_create.xml"); } @Test - public void testCreate_sunriseSignedMark() throws Exception { + void testCreate_sunriseSignedMark() throws Exception { doXmlRoundtripTest("domain_create_sunrise_signed_mark.xml"); } @Test - public void testCreate_sunriseCode() throws Exception { + void testCreate_sunriseCode() throws Exception { doXmlRoundtripTest("domain_create_sunrise_code.xml"); } @Test - public void testCreate_sunriseMark() throws Exception { + void testCreate_sunriseMark() throws Exception { doXmlRoundtripTest("domain_create_sunrise_mark.xml"); } @Test - public void testCreate_sunriseCodeWithMark() throws Exception { + void testCreate_sunriseCodeWithMark() throws Exception { doXmlRoundtripTest("domain_create_sunrise_code_with_mark.xml"); } @Test - public void testCreate_sunriseEncodedSignedMark() throws Exception { + void testCreate_sunriseEncodedSignedMark() throws Exception { doXmlRoundtripTest("domain_create_sunrise_encoded_signed_mark.xml"); } @Test - public void testCreate_fee() throws Exception { + void testCreate_fee() throws Exception { doXmlRoundtripTest("domain_create_fee.xml"); } @Test - public void testCreate_emptyCommand() throws Exception { + void testCreate_emptyCommand() throws Exception { // This EPP command wouldn't be allowed for policy reasons, but should marshal/unmarshal fine. doXmlRoundtripTest("domain_create_empty.xml"); } @Test - public void testCreate_missingNonRegistrantContacts() throws Exception { + void testCreate_missingNonRegistrantContacts() throws Exception { // This EPP command wouldn't be allowed for policy reasons, but should marshal/unmarshal fine. doXmlRoundtripTest("domain_create_missing_non_registrant_contacts.xml"); } @Test - public void testCreate_cloneAndLinkReferences() throws Exception { + void testCreate_cloneAndLinkReferences() throws Exception { persistActiveHost("ns1.example.net"); persistActiveHost("ns2.example.net"); persistActiveContact("sh8013"); @@ -86,7 +86,7 @@ public class DomainCommandTest extends ResourceCommandTestCase { } @Test - public void testCreate_emptyCommand_cloneAndLinkReferences() throws Exception { + void testCreate_emptyCommand_cloneAndLinkReferences() throws Exception { // This EPP command wouldn't be allowed for policy reasons, but should clone-and-link fine. DomainCommand.Create create = (DomainCommand.Create) loadEppResourceCommand("domain_create_empty.xml"); @@ -94,7 +94,7 @@ public class DomainCommandTest extends ResourceCommandTestCase { } @Test - public void testCreate_missingNonRegistrantContacts_cloneAndLinkReferences() throws Exception { + void testCreate_missingNonRegistrantContacts_cloneAndLinkReferences() throws Exception { persistActiveContact("jd1234"); // This EPP command wouldn't be allowed for policy reasons, but should clone-and-link fine. DomainCommand.Create create = @@ -104,28 +104,28 @@ public class DomainCommandTest extends ResourceCommandTestCase { } @Test - public void testDelete() throws Exception { + void testDelete() throws Exception { doXmlRoundtripTest("domain_delete.xml"); } @Test - public void testUpdate() throws Exception { + void testUpdate() throws Exception { doXmlRoundtripTest("domain_update.xml"); } @Test - public void testUpdate_fee() throws Exception { + void testUpdate_fee() throws Exception { doXmlRoundtripTest("domain_update_fee.xml"); } @Test - public void testUpdate_emptyCommand() throws Exception { + void testUpdate_emptyCommand() throws Exception { // This EPP command wouldn't be allowed for policy reasons, but should marshal/unmarshal fine. doXmlRoundtripTest("domain_update_empty.xml"); } @Test - public void testUpdate_cloneAndLinkReferences() throws Exception { + void testUpdate_cloneAndLinkReferences() throws Exception { persistActiveHost("ns1.example.com"); persistActiveHost("ns2.example.com"); persistActiveContact("mak21"); @@ -136,7 +136,7 @@ public class DomainCommandTest extends ResourceCommandTestCase { } @Test - public void testUpdate_emptyCommand_cloneAndLinkReferences() throws Exception { + void testUpdate_emptyCommand_cloneAndLinkReferences() throws Exception { // This EPP command wouldn't be allowed for policy reasons, but should clone-and-link fine. DomainCommand.Update update = (DomainCommand.Update) loadEppResourceCommand("domain_update_empty.xml"); @@ -144,77 +144,77 @@ public class DomainCommandTest extends ResourceCommandTestCase { } @Test - public void testInfo() throws Exception { + void testInfo() throws Exception { doXmlRoundtripTest("domain_info.xml"); } @Test - public void testInfo_sunrise() throws Exception { + void testInfo_sunrise() throws Exception { doXmlRoundtripTest("domain_info_sunrise.xml"); } @Test - public void testInfo_feeExtension() throws Exception { + void testInfo_feeExtension() throws Exception { doXmlRoundtripTest("domain_info_fee.xml"); } @Test - public void testCheck() throws Exception { + void testCheck() throws Exception { doXmlRoundtripTest("domain_check.xml"); } @Test - public void testCheck_avail() throws Exception { + void testCheck_avail() throws Exception { doXmlRoundtripTest("domain_check_avail.xml"); } @Test - public void testCheck_claims() throws Exception { + void testCheck_claims() throws Exception { doXmlRoundtripTest("domain_check_claims.xml"); } @Test - public void testCheck_fee() throws Exception { + void testCheck_fee() throws Exception { doXmlRoundtripTest("domain_check_fee.xml"); } @Test - public void testTransferApprove() throws Exception { + void testTransferApprove() throws Exception { doXmlRoundtripTest("domain_transfer_approve.xml"); } @Test - public void testTransferReject() throws Exception { + void testTransferReject() throws Exception { doXmlRoundtripTest("domain_transfer_reject.xml"); } @Test - public void testTransferCancel() throws Exception { + void testTransferCancel() throws Exception { doXmlRoundtripTest("domain_transfer_cancel.xml"); } @Test - public void testTransferQuery() throws Exception { + void testTransferQuery() throws Exception { doXmlRoundtripTest("domain_transfer_query.xml"); } @Test - public void testTransferRequest() throws Exception { + void testTransferRequest() throws Exception { doXmlRoundtripTest("domain_transfer_request.xml"); } @Test - public void testTransferRequest_fee() throws Exception { + void testTransferRequest_fee() throws Exception { doXmlRoundtripTest("domain_transfer_request_fee.xml"); } @Test - public void testRenew() throws Exception { + void testRenew() throws Exception { doXmlRoundtripTest("domain_renew.xml"); } @Test - public void testRenew_fee() throws Exception { + void testRenew_fee() throws Exception { doXmlRoundtripTest("domain_renew_fee.xml"); } diff --git a/core/src/test/java/google/registry/model/domain/GracePeriodTest.java b/core/src/test/java/google/registry/model/domain/GracePeriodTest.java index c2b81dd8a..3c49a9c3c 100644 --- a/core/src/test/java/google/registry/model/domain/GracePeriodTest.java +++ b/core/src/test/java/google/registry/model/domain/GracePeriodTest.java @@ -28,17 +28,14 @@ import google.registry.testing.AppEngineRule; import org.joda.money.CurrencyUnit; 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; /** Unit tests for {@link GracePeriod}. */ -@RunWith(JUnit4.class) public class GracePeriodTest { - @Rule + @RegisterExtension public final AppEngineRule appEngine = AppEngineRule.builder() .withDatastoreAndCloudSql() // Needed to be able to construct Keys. @@ -47,8 +44,8 @@ public class GracePeriodTest { private final DateTime now = DateTime.now(UTC); private BillingEvent.OneTime onetime; - @Before - public void before() { + @BeforeEach + void before() { onetime = new BillingEvent.OneTime.Builder() .setEventTime(now) .setBillingTime(now.plusDays(1)) @@ -62,7 +59,7 @@ public class GracePeriodTest { } @Test - public void testSuccess_forBillingEvent() { + void testSuccess_forBillingEvent() { GracePeriod gracePeriod = GracePeriod.forBillingEvent(GracePeriodStatus.ADD, onetime); assertThat(gracePeriod.getType()).isEqualTo(GracePeriodStatus.ADD); assertThat(gracePeriod.getOneTimeBillingEvent()).isEqualTo(Key.create(onetime)); @@ -73,7 +70,7 @@ public class GracePeriodTest { } @Test - public void testSuccess_createWithoutBillingEvent() { + void testSuccess_createWithoutBillingEvent() { GracePeriod gracePeriod = GracePeriod.createWithoutBillingEvent( GracePeriodStatus.REDEMPTION, now, "TheRegistrar"); assertThat(gracePeriod.getType()).isEqualTo(GracePeriodStatus.REDEMPTION); @@ -85,7 +82,7 @@ public class GracePeriodTest { } @Test - public void testFailure_forBillingEvent_autoRenew() { + void testFailure_forBillingEvent_autoRenew() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -94,7 +91,7 @@ public class GracePeriodTest { } @Test - public void testFailure_createForRecurring_notAutoRenew() { + void testFailure_createForRecurring_notAutoRenew() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, diff --git a/core/src/test/java/google/registry/model/domain/token/AllocationTokenTest.java b/core/src/test/java/google/registry/model/domain/token/AllocationTokenTest.java index c99508fb5..69a9b03b7 100644 --- a/core/src/test/java/google/registry/model/domain/token/AllocationTokenTest.java +++ b/core/src/test/java/google/registry/model/domain/token/AllocationTokenTest.java @@ -37,19 +37,19 @@ import google.registry.model.domain.token.AllocationToken.TokenStatus; import google.registry.model.domain.token.AllocationToken.TokenType; import google.registry.model.reporting.HistoryEntry; import org.joda.time.DateTime; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** Unit tests for {@link AllocationToken}. */ -public class AllocationTokenTest extends EntityTestCase { +class AllocationTokenTest extends EntityTestCase { - @Before - public void setup() { + @BeforeEach + void setup() { createTld("foo"); } @Test - public void testPersistence() { + void testPersistence() { AllocationToken unlimitedUseToken = persistResource( new AllocationToken.Builder() @@ -81,7 +81,7 @@ public class AllocationTokenTest extends EntityTestCase { } @Test - public void testIndexing() throws Exception { + void testIndexing() throws Exception { verifyIndexing( persistResource( new AllocationToken.Builder() @@ -97,7 +97,7 @@ public class AllocationTokenTest extends EntityTestCase { } @Test - public void testCreationTime_autoPopulates() { + void testCreationTime_autoPopulates() { AllocationToken tokenBeforePersisting = new AllocationToken.Builder().setToken("abc123").setTokenType(SINGLE_USE).build(); assertThat(tokenBeforePersisting.getCreationTime()).isEmpty(); @@ -106,7 +106,7 @@ public class AllocationTokenTest extends EntityTestCase { } @Test - public void testSetCreationTime_cantCallMoreThanOnce() { + void testSetCreationTime_cantCallMoreThanOnce() { AllocationToken.Builder builder = new AllocationToken.Builder() .setToken("foobar") @@ -120,7 +120,7 @@ public class AllocationTokenTest extends EntityTestCase { } @Test - public void testSetToken_cantCallMoreThanOnce() { + void testSetToken_cantCallMoreThanOnce() { AllocationToken.Builder builder = new AllocationToken.Builder().setToken("foobar"); IllegalStateException thrown = assertThrows(IllegalStateException.class, () -> builder.setToken("barfoo")); @@ -128,7 +128,7 @@ public class AllocationTokenTest extends EntityTestCase { } @Test - public void testSetTokenType_cantCallMoreThanOnce() { + void testSetTokenType_cantCallMoreThanOnce() { AllocationToken.Builder builder = new AllocationToken.Builder().setTokenType(TokenType.UNLIMITED_USE); IllegalStateException thrown = @@ -137,7 +137,7 @@ public class AllocationTokenTest extends EntityTestCase { } @Test - public void testBuild_DomainNameWithLessThanTwoParts() { + void testBuild_DomainNameWithLessThanTwoParts() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -155,7 +155,7 @@ public class AllocationTokenTest extends EntityTestCase { } @Test - public void testBuild_invalidTLD() { + void testBuild_invalidTLD() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -173,7 +173,7 @@ public class AllocationTokenTest extends EntityTestCase { } @Test - public void testBuild_domainNameOnlyOnSingleUse() { + void testBuild_domainNameOnlyOnSingleUse() { AllocationToken.Builder builder = new AllocationToken.Builder() .setToken("foobar") @@ -186,7 +186,7 @@ public class AllocationTokenTest extends EntityTestCase { } @Test - public void testBuild_redemptionHistoryEntryOnlyInSingleUse() { + void testBuild_redemptionHistoryEntryOnlyInSingleUse() { AllocationToken.Builder builder = new AllocationToken.Builder() .setToken("foobar") @@ -199,7 +199,7 @@ public class AllocationTokenTest extends EntityTestCase { } @Test - public void testSetTransitions_notStartOfTime() { + void testSetTransitions_notStartOfTime() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -217,7 +217,7 @@ public class AllocationTokenTest extends EntityTestCase { } @Test - public void testSetTransitions_badInitialValue() { + void testSetTransitions_badInitialValue() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -234,14 +234,14 @@ public class AllocationTokenTest extends EntityTestCase { } @Test - public void testSetTransitions_invalidInitialTransitions() { + void testSetTransitions_invalidInitialTransitions() { // NOT_STARTED can only go to VALID or CANCELLED assertBadInitialTransition(NOT_STARTED); assertBadInitialTransition(ENDED); } @Test - public void testSetTransitions_badTransitionsFromValid() { + void testSetTransitions_badTransitionsFromValid() { // VALID can only go to ENDED or CANCELLED assertBadTransition( ImmutableSortedMap.naturalOrder() @@ -262,14 +262,14 @@ public class AllocationTokenTest extends EntityTestCase { } @Test - public void testSetTransitions_terminalTransitions() { + void testSetTransitions_terminalTransitions() { // both ENDED and CANCELLED are terminal assertTerminal(ENDED); assertTerminal(CANCELLED); } @Test - public void testBuild_noTokenType() { + void testBuild_noTokenType() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -278,7 +278,7 @@ public class AllocationTokenTest extends EntityTestCase { } @Test - public void testBuild_noToken() { + void testBuild_noToken() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -287,7 +287,7 @@ public class AllocationTokenTest extends EntityTestCase { } @Test - public void testBuild_emptyToken() { + void testBuild_emptyToken() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, diff --git a/core/src/test/java/google/registry/model/eppcommon/AddressTest.java b/core/src/test/java/google/registry/model/eppcommon/AddressTest.java index a85029a86..ac9406285 100644 --- a/core/src/test/java/google/registry/model/eppcommon/AddressTest.java +++ b/core/src/test/java/google/registry/model/eppcommon/AddressTest.java @@ -17,15 +17,13 @@ package google.registry.model.eppcommon; import static com.google.common.truth.Truth.assertThat; import com.google.common.collect.ImmutableList; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.Test; /** Tests for {@link Address}. */ -@RunWith(JUnit4.class) -public class AddressTest { +class AddressTest { + @Test - public void onLoad_setsIndividualStreetLinesSuccessfully() { + void onLoad_setsIndividualStreetLinesSuccessfully() { Address address = new Address(); address.onLoad(ImmutableList.of("line1", "line2", "line3")); assertThat(address.streetLine1).isEqualTo("line1"); @@ -34,7 +32,7 @@ public class AddressTest { } @Test - public void onLoad_setsOnlyNonNullStreetLines() { + void onLoad_setsOnlyNonNullStreetLines() { Address address = new Address(); address.onLoad(ImmutableList.of("line1", "line2")); assertThat(address.streetLine1).isEqualTo("line1"); @@ -43,7 +41,7 @@ public class AddressTest { } @Test - public void onLoad_doNothingIfInputIsNull() { + void onLoad_doNothingIfInputIsNull() { Address address = new Address(); address.onLoad(null); assertThat(address.streetLine1).isNull(); @@ -52,7 +50,7 @@ public class AddressTest { } @Test - public void postLoad_setsStreetListSuccessfully() { + void postLoad_setsStreetListSuccessfully() { Address address = new Address(); address.streetLine1 = "line1"; address.streetLine2 = "line2"; @@ -62,7 +60,7 @@ public class AddressTest { } @Test - public void postLoad_setsOnlyNonNullStreetLines() { + void postLoad_setsOnlyNonNullStreetLines() { Address address = new Address(); address.streetLine1 = "line1"; address.streetLine2 = "line2"; @@ -71,7 +69,7 @@ public class AddressTest { } @Test - public void postLoad_doNothingIfInputIsNull() { + void postLoad_doNothingIfInputIsNull() { Address address = new Address(); address.postLoad(); assertThat(address.street).isNull(); diff --git a/core/src/test/java/google/registry/model/eppcommon/EppXmlTransformerTest.java b/core/src/test/java/google/registry/model/eppcommon/EppXmlTransformerTest.java index b9e2aff90..558d46ecc 100644 --- a/core/src/test/java/google/registry/model/eppcommon/EppXmlTransformerTest.java +++ b/core/src/test/java/google/registry/model/eppcommon/EppXmlTransformerTest.java @@ -21,22 +21,19 @@ import static org.junit.Assert.assertThrows; import google.registry.model.eppinput.EppInput; import google.registry.model.eppoutput.EppOutput; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.Test; /** Tests for {@link EppXmlTransformer}. */ -@RunWith(JUnit4.class) -public class EppXmlTransformerTest { +class EppXmlTransformerTest { @Test - public void testUnmarshalingEppInput() throws Exception { + void testUnmarshalingEppInput() throws Exception { EppInput input = unmarshal(EppInput.class, loadBytes(getClass(), "contact_info.xml").read()); assertThat(input.getCommandType()).isEqualTo("info"); } @Test - public void testUnmarshalingWrongClassThrows() { + void testUnmarshalingWrongClassThrows() { assertThrows( ClassCastException.class, () -> unmarshal(EppOutput.class, loadBytes(getClass(), "contact_info.xml").read())); diff --git a/core/src/test/java/google/registry/model/eppinput/EppInputTest.java b/core/src/test/java/google/registry/model/eppinput/EppInputTest.java index b0b39bf2e..a7c45e6b2 100644 --- a/core/src/test/java/google/registry/model/eppinput/EppInputTest.java +++ b/core/src/test/java/google/registry/model/eppinput/EppInputTest.java @@ -25,16 +25,13 @@ import google.registry.model.domain.DomainBaseTest; import google.registry.model.eppinput.EppInput.InnerCommand; import google.registry.model.eppinput.EppInput.Login; import google.registry.xml.XmlException; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.Test; /** Unit tests for {@link EppInput}. */ -@RunWith(JUnit4.class) -public class EppInputTest { +class EppInputTest { @Test - public void testUnmarshalling_contactInfo() throws Exception { + void testUnmarshalling_contactInfo() throws Exception { EppInput input = unmarshal(EppInput.class, loadBytes(ContactResourceTest.class, "contact_info.xml").read()); assertThat(input.getCommandWrapper().getClTrid()).hasValue("ABC-12345"); @@ -45,7 +42,7 @@ public class EppInputTest { } @Test - public void testUnmarshalling_domainCheck() throws Exception { + void testUnmarshalling_domainCheck() throws Exception { EppInput input = unmarshal(EppInput.class, loadBytes(DomainBaseTest.class, "domain_check.xml").read()); assertThat(input.getCommandWrapper().getClTrid()).hasValue("ABC-12345"); @@ -56,7 +53,7 @@ public class EppInputTest { } @Test - public void testUnmarshalling_login() throws Exception { + void testUnmarshalling_login() throws Exception { EppInput input = unmarshal(EppInput.class, loadBytes(getClass(), "login_valid.xml").read()); assertThat(input.getCommandWrapper().getClTrid()).hasValue("ABC-12345"); assertThat(input.getCommandType()).isEqualTo("login"); @@ -81,7 +78,7 @@ public class EppInputTest { } @Test - public void testUnmarshalling_loginTagInWrongCase_throws() { + void testUnmarshalling_loginTagInWrongCase_throws() { assertThrows( XmlException.class, () -> unmarshal(EppInput.class, loadBytes(getClass(), "login_wrong_case.xml").read())); diff --git a/core/src/test/java/google/registry/model/eppoutput/ResultTest.java b/core/src/test/java/google/registry/model/eppoutput/ResultTest.java index 017bf0d65..f77eb606c 100644 --- a/core/src/test/java/google/registry/model/eppoutput/ResultTest.java +++ b/core/src/test/java/google/registry/model/eppoutput/ResultTest.java @@ -16,16 +16,13 @@ package google.registry.model.eppoutput; import static com.google.common.truth.Truth.assertThat; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.Test; /** Unit tests for {@link Result}. */ -@RunWith(JUnit4.class) -public final class ResultTest { +final class ResultTest { @Test - public void testDeadCodeWeDontWantToDelete() { + void testDeadCodeWeDontWantToDelete() { Result result = new Result(); result.msg = "hello"; assertThat(result.getMsg()).isEqualTo("hello"); diff --git a/core/src/test/java/google/registry/model/history/ContactHistoryTest.java b/core/src/test/java/google/registry/model/history/ContactHistoryTest.java index 1cf1365dc..8e060adbd 100644 --- a/core/src/test/java/google/registry/model/history/ContactHistoryTest.java +++ b/core/src/test/java/google/registry/model/history/ContactHistoryTest.java @@ -31,12 +31,12 @@ import org.junit.jupiter.api.Test; /** Tests for {@link ContactHistory}. */ public class ContactHistoryTest extends EntityTestCase { - public ContactHistoryTest() { + ContactHistoryTest() { super(JpaEntityCoverageCheck.ENABLED); } @Test - public void testPersistence() { + void testPersistence() { saveRegistrar("registrar1"); ContactResource contact = diff --git a/core/src/test/java/google/registry/model/history/HostHistoryTest.java b/core/src/test/java/google/registry/model/history/HostHistoryTest.java index 0a3b5edc9..df6e268e5 100644 --- a/core/src/test/java/google/registry/model/history/HostHistoryTest.java +++ b/core/src/test/java/google/registry/model/history/HostHistoryTest.java @@ -31,12 +31,12 @@ import org.junit.jupiter.api.Test; /** Tests for {@link HostHistory}. */ public class HostHistoryTest extends EntityTestCase { - public HostHistoryTest() { + HostHistoryTest() { super(JpaEntityCoverageCheck.ENABLED); } @Test - public void testPersistence() { + void testPersistence() { saveRegistrar("registrar1"); HostResource host = diff --git a/core/src/test/java/google/registry/model/host/HostCommandTest.java b/core/src/test/java/google/registry/model/host/HostCommandTest.java index d34cfd66e..ef19a4c4a 100644 --- a/core/src/test/java/google/registry/model/host/HostCommandTest.java +++ b/core/src/test/java/google/registry/model/host/HostCommandTest.java @@ -15,33 +15,33 @@ package google.registry.model.host; import google.registry.model.ResourceCommandTestCase; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** Test xml roundtripping of commands. */ -public class HostCommandTest extends ResourceCommandTestCase { +class HostCommandTest extends ResourceCommandTestCase { @Test - public void testCreate() throws Exception { + void testCreate() throws Exception { doXmlRoundtripTest("host_create.xml"); } @Test - public void testDelete() throws Exception { + void testDelete() throws Exception { doXmlRoundtripTest("host_delete.xml"); } @Test - public void testUpdate() throws Exception { + void testUpdate() throws Exception { doXmlRoundtripTest("host_update.xml"); } @Test - public void testInfo() throws Exception { + void testInfo() throws Exception { doXmlRoundtripTest("host_info.xml"); } @Test - public void testCheck() throws Exception { + void testCheck() throws Exception { doXmlRoundtripTest("host_check.xml"); } } diff --git a/core/src/test/java/google/registry/model/host/HostResourceTest.java b/core/src/test/java/google/registry/model/host/HostResourceTest.java index ae4d62164..4b1beb341 100644 --- a/core/src/test/java/google/registry/model/host/HostResourceTest.java +++ b/core/src/test/java/google/registry/model/host/HostResourceTest.java @@ -35,21 +35,21 @@ import google.registry.model.transfer.DomainTransferData; import google.registry.model.transfer.TransferStatus; import google.registry.persistence.VKey; import org.joda.time.DateTime; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** Unit tests for {@link HostResource}. */ -public class HostResourceTest extends EntityTestCase { +class HostResourceTest extends EntityTestCase { - final DateTime day3 = fakeClock.nowUtc(); - final DateTime day2 = day3.minusDays(1); - final DateTime day1 = day2.minusDays(1); + private final DateTime day3 = fakeClock.nowUtc(); + private final DateTime day2 = day3.minusDays(1); + private final DateTime day1 = day2.minusDays(1); - DomainBase domain; - HostResource host; + private DomainBase domain; + private HostResource host; - @Before - public void setUp() { + @BeforeEach + void setUp() { createTld("com"); // Set up a new persisted registrar entity. domain = @@ -86,13 +86,13 @@ public class HostResourceTest extends EntityTestCase { } @Test - public void testPersistence() { + void testPersistence() { assertThat(loadByForeignKey(HostResource.class, host.getForeignKey(), fakeClock.nowUtc())) .hasValue(host); } @Test - public void testIndexing() throws Exception { + void testIndexing() throws Exception { // Clone it and save it before running the indexing test so that its transferData fields are // populated from the superordinate domain. verifyIndexing( @@ -105,7 +105,7 @@ public class HostResourceTest extends EntityTestCase { } @Test - public void testEmptyStringsBecomeNull() { + void testEmptyStringsBecomeNull() { assertThat( new HostResource.Builder() .setPersistedCurrentSponsorClientId(null) @@ -127,7 +127,7 @@ public class HostResourceTest extends EntityTestCase { } @Test - public void testEmptySetsBecomeNull() { + void testEmptySetsBecomeNull() { assertThat(new HostResource.Builder().setInetAddresses(null).build().inetAddresses).isNull(); assertThat(new HostResource.Builder().setInetAddresses(ImmutableSet.of()).build().inetAddresses) .isNull(); @@ -140,7 +140,7 @@ public class HostResourceTest extends EntityTestCase { } @Test - public void testImplicitStatusValues() { + void testImplicitStatusValues() { // OK is implicit if there's no other statuses. assertAboutHosts() .that(new HostResource.Builder().build()) @@ -162,13 +162,13 @@ public class HostResourceTest extends EntityTestCase { } @Test - public void testToHydratedString_notCircular() { + void testToHydratedString_notCircular() { // If there are circular references, this will overflow the stack. host.toHydratedString(); } @Test - public void testFailure_uppercaseHostName() { + void testFailure_uppercaseHostName() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, () -> host.asBuilder().setHostName("AAA.BBB.CCC")); @@ -178,7 +178,7 @@ public class HostResourceTest extends EntityTestCase { } @Test - public void testFailure_utf8HostName() { + void testFailure_utf8HostName() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, () -> host.asBuilder().setHostName("みんな.みんな.みんな")); @@ -188,14 +188,14 @@ public class HostResourceTest extends EntityTestCase { } @Test - public void testComputeLastTransferTime_hostNeverSwitchedDomains_domainWasNeverTransferred() { + void testComputeLastTransferTime_hostNeverSwitchedDomains_domainWasNeverTransferred() { domain = domain.asBuilder().setLastTransferTime(null).build(); host = host.asBuilder().setLastTransferTime(null).setLastSuperordinateChange(null).build(); assertThat(host.computeLastTransferTime(domain)).isNull(); } @Test - public void testComputeLastTransferTime_hostNeverSwitchedDomains_domainWasTransferred() { + void testComputeLastTransferTime_hostNeverSwitchedDomains_domainWasTransferred() { // Host was created on Day 1. // Domain was transferred on Day 2. // Host was always subordinate to domain (and was created before the transfer). @@ -210,7 +210,7 @@ public class HostResourceTest extends EntityTestCase { } @Test - public void testComputeLastTransferTime_hostCreatedAfterDomainWasTransferred() { + void testComputeLastTransferTime_hostCreatedAfterDomainWasTransferred() { // Domain was transferred on Day 1. // Host was created subordinate to domain on Day 2. domain = domain.asBuilder().setLastTransferTime(day1).build(); @@ -232,7 +232,7 @@ public class HostResourceTest extends EntityTestCase { } @Test - public void testComputeLastTransferTime_hostWasTransferred_domainWasNeverTransferred() { + void testComputeLastTransferTime_hostWasTransferred_domainWasNeverTransferred() { // Host was transferred on Day 1. // Host was made subordinate to domain on Day 2. // Domain was never transferred. @@ -242,7 +242,7 @@ public class HostResourceTest extends EntityTestCase { } @Test - public void testComputeLastTransferTime_domainWasTransferredBeforeHostBecameSubordinate() { + void testComputeLastTransferTime_domainWasTransferredBeforeHostBecameSubordinate() { // Host was transferred on Day 1. // Domain was transferred on Day 2. // Host was made subordinate to domain on Day 3. @@ -252,7 +252,7 @@ public class HostResourceTest extends EntityTestCase { } @Test - public void testComputeLastTransferTime_domainWasTransferredAfterHostBecameSubordinate() { + void testComputeLastTransferTime_domainWasTransferredAfterHostBecameSubordinate() { // Host was transferred on Day 1. // Host was made subordinate to domain on Day 2. // Domain was transferred on Day 3. diff --git a/core/src/test/java/google/registry/model/index/EppResourceIndexTest.java b/core/src/test/java/google/registry/model/index/EppResourceIndexTest.java index 9da824515..57ac331f1 100644 --- a/core/src/test/java/google/registry/model/index/EppResourceIndexTest.java +++ b/core/src/test/java/google/registry/model/index/EppResourceIndexTest.java @@ -26,34 +26,34 @@ import com.google.common.collect.Iterables; import com.googlecode.objectify.Key; import google.registry.model.EntityTestCase; import google.registry.model.contact.ContactResource; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** Unit tests for {@link EppResourceIndex}. */ -public class EppResourceIndexTest extends EntityTestCase { +class EppResourceIndexTest extends EntityTestCase { - ContactResource contact; + private ContactResource contact; - @Before - public void setUp() { + @BeforeEach + void setUp() { createTld("tld"); // The DatastoreHelper here creates the EppResourceIndex for us. contact = persistActiveContact("abcd1357"); } @Test - public void testPersistence() { + void testPersistence() { EppResourceIndex loadedIndex = Iterables.getOnlyElement(getEppResourceIndexObjects()); assertThat(ofy().load().key(loadedIndex.reference).now()).isEqualTo(contact); } @Test - public void testIndexing() throws Exception { + void testIndexing() throws Exception { verifyIndexing(Iterables.getOnlyElement(getEppResourceIndexObjects()), "kind"); } @Test - public void testIdempotentOnUpdate() { + void testIdempotentOnUpdate() { contact = persistResource(contact.asBuilder().setEmailAddress("abc@def.fake").build()); EppResourceIndex loadedIndex = Iterables.getOnlyElement(getEppResourceIndexObjects()); assertThat(ofy().load().key(loadedIndex.reference).now()).isEqualTo(contact); diff --git a/core/src/test/java/google/registry/model/index/ForeignKeyIndexTest.java b/core/src/test/java/google/registry/model/index/ForeignKeyIndexTest.java index 372d273fe..4d65cdb75 100644 --- a/core/src/test/java/google/registry/model/index/ForeignKeyIndexTest.java +++ b/core/src/test/java/google/registry/model/index/ForeignKeyIndexTest.java @@ -33,24 +33,24 @@ import google.registry.model.host.HostResource; import google.registry.model.index.ForeignKeyIndex.ForeignKeyHostIndex; import google.registry.testing.TestCacheRule; import org.joda.time.Duration; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; /** Unit tests for {@link ForeignKeyIndex}. */ public class ForeignKeyIndexTest extends EntityTestCase { - @Rule + @RegisterExtension public final TestCacheRule testCacheRule = new TestCacheRule.Builder().withForeignIndexKeyCache(Duration.standardDays(1)).build(); - @Before - public void setUp() { + @BeforeEach + void setUp() { createTld("com"); } @Test - public void testPersistence() { + void testPersistence() { // Persist a host and implicitly persist a ForeignKeyIndex for it. HostResource host = persistActiveHost("ns1.example.com"); ForeignKeyIndex fki = @@ -60,7 +60,7 @@ public class ForeignKeyIndexTest extends EntityTestCase { } @Test - public void testIndexing() throws Exception { + void testIndexing() throws Exception { // Persist a host and implicitly persist a ForeignKeyIndex for it. persistActiveHost("ns1.example.com"); verifyIndexing( @@ -69,13 +69,13 @@ public class ForeignKeyIndexTest extends EntityTestCase { } @Test - public void testLoadForNonexistentForeignKey_returnsNull() { + void testLoadForNonexistentForeignKey_returnsNull() { assertThat(ForeignKeyIndex.load(HostResource.class, "ns1.example.com", fakeClock.nowUtc())) .isNull(); } @Test - public void testLoadForDeletedForeignKey_returnsNull() { + void testLoadForDeletedForeignKey_returnsNull() { HostResource host = persistActiveHost("ns1.example.com"); persistResource(ForeignKeyIndex.create(host, fakeClock.nowUtc().minusDays(1))); assertThat(ForeignKeyIndex.load(HostResource.class, "ns1.example.com", fakeClock.nowUtc())) @@ -83,7 +83,7 @@ public class ForeignKeyIndexTest extends EntityTestCase { } @Test - public void testLoad_newerKeyHasBeenSoftDeleted() { + void testLoad_newerKeyHasBeenSoftDeleted() { HostResource host1 = persistActiveHost("ns1.example.com"); fakeClock.advanceOneMilli(); ForeignKeyHostIndex fki = new ForeignKeyHostIndex(); @@ -96,7 +96,7 @@ public class ForeignKeyIndexTest extends EntityTestCase { } @Test - public void testBatchLoad_skipsDeletedAndNonexistent() { + void testBatchLoad_skipsDeletedAndNonexistent() { persistActiveHost("ns1.example.com"); HostResource host = persistActiveHost("ns2.example.com"); persistResource(ForeignKeyIndex.create(host, fakeClock.nowUtc().minusDays(1))); @@ -110,7 +110,7 @@ public class ForeignKeyIndexTest extends EntityTestCase { } @Test - public void testDeadCodeThatDeletedScrapCommandsReference() { + void testDeadCodeThatDeletedScrapCommandsReference() { persistActiveHost("omg"); assertThat(ForeignKeyIndex.load(HostResource.class, "omg", fakeClock.nowUtc()).getForeignKey()) .isEqualTo("omg"); @@ -125,7 +125,7 @@ public class ForeignKeyIndexTest extends EntityTestCase { } @Test - public void test_loadCached_cachesNonexistenceOfHosts() { + void test_loadCached_cachesNonexistenceOfHosts() { assertThat( ForeignKeyIndex.loadCached( HostResource.class, @@ -145,7 +145,7 @@ public class ForeignKeyIndexTest extends EntityTestCase { } @Test - public void test_loadCached_cachesExistenceOfHosts() { + void test_loadCached_cachesExistenceOfHosts() { HostResource host1 = persistActiveHost("ns1.example.com"); HostResource host2 = persistActiveHost("ns2.example.com"); assertThat( @@ -173,7 +173,7 @@ public class ForeignKeyIndexTest extends EntityTestCase { } @Test - public void test_loadCached_doesntSeeHostChangesWhileCacheIsValid() { + void test_loadCached_doesntSeeHostChangesWhileCacheIsValid() { HostResource originalHost = persistActiveHost("ns1.example.com"); ForeignKeyIndex originalFki = loadHostFki("ns1.example.com"); fakeClock.advanceOneMilli(); @@ -196,7 +196,7 @@ public class ForeignKeyIndexTest extends EntityTestCase { } @Test - public void test_loadCached_filtersOutSoftDeletedHosts() { + void test_loadCached_filtersOutSoftDeletedHosts() { persistActiveHost("ns1.example.com"); persistDeletedHost("ns2.example.com", fakeClock.nowUtc().minusDays(1)); assertThat( @@ -208,7 +208,7 @@ public class ForeignKeyIndexTest extends EntityTestCase { } @Test - public void test_loadCached_cachesContactFkis() { + void test_loadCached_cachesContactFkis() { persistActiveContact("contactid1"); ForeignKeyIndex fki1 = loadContactFki("contactid1"); assertThat( diff --git a/core/src/test/java/google/registry/model/mark/MarkContactTest.java b/core/src/test/java/google/registry/model/mark/MarkContactTest.java index 4db060de2..a0ee74b7e 100644 --- a/core/src/test/java/google/registry/model/mark/MarkContactTest.java +++ b/core/src/test/java/google/registry/model/mark/MarkContactTest.java @@ -16,16 +16,13 @@ package google.registry.model.mark; import static com.google.common.truth.Truth.assertThat; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.Test; /** Unit tests for {@link MarkContact}. */ -@RunWith(JUnit4.class) -public final class MarkContactTest { +final class MarkContactTest { @Test - public void testDeadCodeWeDontWantToDelete() { + void testDeadCodeWeDontWantToDelete() { MarkContact mc = new MarkContact(); mc.type = MarkContact.ContactType.OWNER; assertThat(mc.getType()).isEqualTo(MarkContact.ContactType.OWNER); diff --git a/core/src/test/java/google/registry/model/mark/MarkHolderTest.java b/core/src/test/java/google/registry/model/mark/MarkHolderTest.java index 5a511a5a9..875891a8f 100644 --- a/core/src/test/java/google/registry/model/mark/MarkHolderTest.java +++ b/core/src/test/java/google/registry/model/mark/MarkHolderTest.java @@ -16,16 +16,13 @@ package google.registry.model.mark; import static com.google.common.truth.Truth.assertThat; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.Test; /** Unit tests for {@link MarkHolder}. */ -@RunWith(JUnit4.class) -public final class MarkHolderTest { +final class MarkHolderTest { @Test - public void testDeadCodeWeDontWantToDelete() { + void testDeadCodeWeDontWantToDelete() { MarkHolder mc = new MarkHolder(); mc.entitlement = MarkHolder.EntitlementType.OWNER; assertThat(mc.getEntitlementType()).isEqualTo(MarkHolder.EntitlementType.OWNER); diff --git a/core/src/test/java/google/registry/model/mark/MarkProtectionTest.java b/core/src/test/java/google/registry/model/mark/MarkProtectionTest.java index e39c488b3..fc97ca3a2 100644 --- a/core/src/test/java/google/registry/model/mark/MarkProtectionTest.java +++ b/core/src/test/java/google/registry/model/mark/MarkProtectionTest.java @@ -17,16 +17,13 @@ package google.registry.model.mark; import static com.google.common.truth.Truth.assertThat; import com.google.common.collect.ImmutableList; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.Test; /** Unit tests for {@link MarkProtection}. */ -@RunWith(JUnit4.class) -public final class MarkProtectionTest { +final class MarkProtectionTest { @Test - public void testDeadCodeWeDontWantToDelete() { + void testDeadCodeWeDontWantToDelete() { MarkProtection mp = new MarkProtection(); mp.countryCode = "US"; assertThat(mp.getCountryCode()).isEqualTo("US"); diff --git a/core/src/test/java/google/registry/model/ofy/CommitLogBucketTest.java b/core/src/test/java/google/registry/model/ofy/CommitLogBucketTest.java index 105d77eaf..ea4bc057e 100644 --- a/core/src/test/java/google/registry/model/ofy/CommitLogBucketTest.java +++ b/core/src/test/java/google/registry/model/ofy/CommitLogBucketTest.java @@ -27,25 +27,21 @@ import com.google.common.collect.ImmutableSet; import com.googlecode.objectify.annotation.Cache; import google.registry.testing.AppEngineRule; import google.registry.testing.InjectRule; -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 CommitLogBucket}. */ -@RunWith(JUnit4.class) public class CommitLogBucketTest { - @Rule + @RegisterExtension public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build(); - @Rule - public final InjectRule inject = new InjectRule(); - CommitLogBucket bucket; + @RegisterExtension public final InjectRule inject = new InjectRule(); + private CommitLogBucket bucket; - @Before - public void before() { + @BeforeEach + void before() { // Save the bucket with some non-default properties set so that we can distinguish a correct // load from one that returns a newly created bucket instance. bucket = persistResource( @@ -56,27 +52,27 @@ public class CommitLogBucketTest { } @Test - public void test_getBucketKey_createsBucketKeyInDefaultNamespace() { + void test_getBucketKey_createsBucketKeyInDefaultNamespace() { // Key.getNamespace() returns the empty string for the default namespace, not null. assertThat(getBucketKey(1).getRaw().getNamespace()).isEmpty(); } @Test - public void test_getBucketKey_bucketNumberTooLow_throws() { + void test_getBucketKey_bucketNumberTooLow_throws() { IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () -> getBucketKey(0)); assertThat(thrown).hasMessageThat().contains("0 not in ["); } @Test - public void test_getBucketKey_bucketNumberTooHigh_throws() { + void test_getBucketKey_bucketNumberTooHigh_throws() { IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () -> getBucketKey(11)); assertThat(thrown).hasMessageThat().contains("11 not in ["); } @Test - public void test_getArbitraryBucketId_withSupplierOverridden() { + void test_getArbitraryBucketId_withSupplierOverridden() { inject.setStaticField( CommitLogBucket.class, "bucketIdSupplier", Suppliers.ofInstance(4)); // xkcd.com/221 // Try multiple times just in case it's actually still random. If it is, the probability of @@ -87,18 +83,18 @@ public class CommitLogBucketTest { } @Test - public void test_loadBucket_loadsTheBucket() { + void test_loadBucket_loadsTheBucket() { assertThat(loadBucket(getBucketKey(1))).isEqualTo(bucket); } @Test - public void test_loadBucket_forNonexistentBucket_returnsNewBucket() { + void test_loadBucket_forNonexistentBucket_returnsNewBucket() { assertThat(loadBucket(getBucketKey(3))).isEqualTo( new CommitLogBucket.Builder().setBucketNum(3).build()); } @Test - public void test_loadAllBuckets_loadsExistingBuckets_orNewOnesIfNonexistent() { + void test_loadAllBuckets_loadsExistingBuckets_orNewOnesIfNonexistent() { ImmutableSet buckets = loadAllBuckets(); assertThat(buckets).hasSize(3); assertThat(buckets).contains(bucket); @@ -107,7 +103,7 @@ public class CommitLogBucketTest { } @Test - public void test_noCacheAnnotation() { + void test_noCacheAnnotation() { // Don't ever put @Cache on CommitLogBucket; it could mess up the checkpointing algorithm. assertThat(CommitLogBucket.class.isAnnotationPresent(Cache.class)).isFalse(); } diff --git a/core/src/test/java/google/registry/model/ofy/CommitLogCheckpointTest.java b/core/src/test/java/google/registry/model/ofy/CommitLogCheckpointTest.java index 3ff7411cc..e2ed10d09 100644 --- a/core/src/test/java/google/registry/model/ofy/CommitLogCheckpointTest.java +++ b/core/src/test/java/google/registry/model/ofy/CommitLogCheckpointTest.java @@ -22,16 +22,13 @@ import static org.junit.Assert.assertThrows; import com.google.common.collect.ImmutableMap; import google.registry.testing.AppEngineRule; 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; /** Tests for {@link CommitLogCheckpoint}. */ -@RunWith(JUnit4.class) public class CommitLogCheckpointTest { - @Rule + @RegisterExtension public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build(); private static final DateTime T1 = START_OF_TIME; @@ -39,7 +36,7 @@ public class CommitLogCheckpointTest { private static final DateTime T3 = START_OF_TIME.plusMillis(2); @Test - public void test_getCheckpointTime() { + void test_getCheckpointTime() { DateTime now = DateTime.now(UTC); CommitLogCheckpoint checkpoint = CommitLogCheckpoint.create(now, ImmutableMap.of(1, T1, 2, T2, 3, T3)); @@ -47,14 +44,14 @@ public class CommitLogCheckpointTest { } @Test - public void test_getBucketTimestamps() { + void test_getBucketTimestamps() { CommitLogCheckpoint checkpoint = CommitLogCheckpoint.create(DateTime.now(UTC), ImmutableMap.of(1, T1, 2, T2, 3, T3)); assertThat(checkpoint.getBucketTimestamps()).containsExactly(1, T1, 2, T2, 3, T3); } @Test - public void test_create_notEnoughBucketTimestamps_throws() { + void test_create_notEnoughBucketTimestamps_throws() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -63,7 +60,7 @@ public class CommitLogCheckpointTest { } @Test - public void test_create_tooManyBucketTimestamps_throws() { + void test_create_tooManyBucketTimestamps_throws() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -74,7 +71,7 @@ public class CommitLogCheckpointTest { } @Test - public void test_create_wrongBucketIds_throws() { + void test_create_wrongBucketIds_throws() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -85,7 +82,7 @@ public class CommitLogCheckpointTest { } @Test - public void test_create_wrongBucketIdOrder_throws() { + void test_create_wrongBucketIdOrder_throws() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, diff --git a/core/src/test/java/google/registry/model/ofy/CommitLogMutationTest.java b/core/src/test/java/google/registry/model/ofy/CommitLogMutationTest.java index bc5d29ab5..1c3a599c8 100644 --- a/core/src/test/java/google/registry/model/ofy/CommitLogMutationTest.java +++ b/core/src/test/java/google/registry/model/ofy/CommitLogMutationTest.java @@ -28,17 +28,14 @@ import google.registry.model.registry.Registry; import google.registry.testing.AppEngineRule; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; -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 CommitLogMutation}. */ -@RunWith(JUnit4.class) public class CommitLogMutationTest { - @Rule + @RegisterExtension public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build(); private static final DateTime NOW = DateTime.now(DateTimeZone.UTC); @@ -46,8 +43,8 @@ public class CommitLogMutationTest { private Key manifestKey; private ImmutableObject someObject; - @Before - public void before() { + @BeforeEach + void before() { // Initialize this late to avoid dependency on NamespaceManager prior to AppEngineRule. manifestKey = CommitLogManifest.createKey(CommitLogBucket.getBucketKey(1), NOW); createTld("tld"); @@ -55,7 +52,7 @@ public class CommitLogMutationTest { } @Test - public void test_createKey_createsKeyWithWebsafeKeystring() { + void test_createKey_createsKeyWithWebsafeKeystring() { Key mutationKey = CommitLogMutation.createKey(manifestKey, Key.create(someObject)); assertThat(mutationKey.getParent()).isEqualTo(manifestKey); @@ -64,7 +61,7 @@ public class CommitLogMutationTest { } @Test - public void test_create_createsExpectedMutation() { + void test_create_createsExpectedMutation() { Entity rawEntity = convertToEntityInTxn(someObject); // Needs to be in a transaction so that registry-saving-to-entity will work. CommitLogMutation mutation = @@ -77,7 +74,7 @@ public class CommitLogMutationTest { } @Test - public void test_createRaw_createsExpectedMutation() { + void test_createRaw_createsExpectedMutation() { Entity rawEntity = convertToEntityInTxn(someObject); CommitLogMutation mutation = CommitLogMutation.createFromRaw(manifestKey, rawEntity); assertThat(Key.create(mutation)) diff --git a/core/src/test/java/google/registry/model/ofy/ObjectifyServiceTest.java b/core/src/test/java/google/registry/model/ofy/ObjectifyServiceTest.java index 2a68c78d4..77a7d1102 100644 --- a/core/src/test/java/google/registry/model/ofy/ObjectifyServiceTest.java +++ b/core/src/test/java/google/registry/model/ofy/ObjectifyServiceTest.java @@ -15,20 +15,17 @@ package google.registry.model.ofy; import google.registry.testing.AppEngineRule; -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; /** Tests for our replacement for ObjectifyService. */ -@RunWith(JUnit4.class) public class ObjectifyServiceTest { - @Rule + @RegisterExtension public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build(); @Test - public void test_initOfy_canBeCalledTwice() { + void test_initOfy_canBeCalledTwice() { ObjectifyService.initOfy(); ObjectifyService.initOfy(); } diff --git a/core/src/test/java/google/registry/model/ofy/OfyCommitLogTest.java b/core/src/test/java/google/registry/model/ofy/OfyCommitLogTest.java index c325c2b6a..0b9502758 100644 --- a/core/src/test/java/google/registry/model/ofy/OfyCommitLogTest.java +++ b/core/src/test/java/google/registry/model/ofy/OfyCommitLogTest.java @@ -35,41 +35,37 @@ import google.registry.testing.FakeClock; import google.registry.testing.InjectRule; import google.registry.testing.TestObject.TestVirtualObject; 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; /** Unit tests ensuring {@link Ofy} saves transactions to {@link CommitLogManifest}. */ -@RunWith(JUnit4.class) public class OfyCommitLogTest { - @Rule + @RegisterExtension public final AppEngineRule appEngine = AppEngineRule.builder() .withDatastoreAndCloudSql() .withOfyTestEntities(TestVirtualObject.class, Root.class, Child.class) .build(); - @Rule - public final InjectRule inject = new InjectRule(); + @RegisterExtension public final InjectRule inject = new InjectRule(); private final FakeClock clock = new FakeClock(DateTime.parse("2000-01-01TZ")); - @Before - public void before() { + @BeforeEach + void beforeEach() { inject.setStaticField(Ofy.class, "clock", clock); } @Test - public void testTransact_doesNothing_noCommitLogIsSaved() { + void testTransact_doesNothing_noCommitLogIsSaved() { tm().transact(() -> {}); assertThat(ofy().load().type(CommitLogManifest.class)).isEmpty(); } @Test - public void testTransact_savesDataAndCommitLog() { + void testTransact_savesDataAndCommitLog() { tm().transact(() -> ofy().save().entity(Root.create(1, getCrossTldKey())).now()); assertThat(ofy().load().key(Key.create(getCrossTldKey(), Root.class, 1)).now().value) .isEqualTo("value"); @@ -78,7 +74,7 @@ public class OfyCommitLogTest { } @Test - public void testTransact_saveWithoutBackup_noCommitLogIsSaved() { + void testTransact_saveWithoutBackup_noCommitLogIsSaved() { tm().transact(() -> ofy().saveWithoutBackup().entity(Root.create(1, getCrossTldKey())).now()); assertThat(ofy().load().key(Key.create(getCrossTldKey(), Root.class, 1)).now().value) .isEqualTo("value"); @@ -87,7 +83,7 @@ public class OfyCommitLogTest { } @Test - public void testTransact_deleteWithoutBackup_noCommitLogIsSaved() { + void testTransact_deleteWithoutBackup_noCommitLogIsSaved() { tm().transact(() -> ofy().saveWithoutBackup().entity(Root.create(1, getCrossTldKey())).now()); tm().transact(() -> ofy().deleteWithoutBackup().key(Key.create(Root.class, 1))); assertThat(ofy().load().key(Key.create(Root.class, 1)).now()).isNull(); @@ -96,7 +92,7 @@ public class OfyCommitLogTest { } @Test - public void testTransact_savesEntity_itsProtobufFormIsStoredInCommitLog() { + void testTransact_savesEntity_itsProtobufFormIsStoredInCommitLog() { tm().transact(() -> ofy().save().entity(Root.create(1, getCrossTldKey())).now()); final byte[] entityProtoBytes = ofy().load().type(CommitLogMutation.class).first().now().entityProtoBytes; @@ -112,7 +108,7 @@ public class OfyCommitLogTest { } @Test - public void testTransact_savesEntity_mutationIsChildOfManifest() { + void testTransact_savesEntity_mutationIsChildOfManifest() { tm().transact(() -> ofy().save().entity(Root.create(1, getCrossTldKey())).now()); assertThat( ofy() @@ -123,7 +119,7 @@ public class OfyCommitLogTest { } @Test - public void testTransactNew_savesDataAndCommitLog() { + void testTransactNew_savesDataAndCommitLog() { tm().transactNew(() -> ofy().save().entity(Root.create(1, getCrossTldKey())).now()); assertThat(ofy().load().key(Key.create(getCrossTldKey(), Root.class, 1)).now().value) .isEqualTo("value"); @@ -132,7 +128,7 @@ public class OfyCommitLogTest { } @Test - public void testTransact_multipleSaves_logsMultipleMutations() { + void testTransact_multipleSaves_logsMultipleMutations() { tm() .transact( () -> { @@ -144,7 +140,7 @@ public class OfyCommitLogTest { } @Test - public void testTransact_deletion_deletesAndLogsWithoutMutation() { + void testTransact_deletion_deletesAndLogsWithoutMutation() { tm().transact(() -> ofy().saveWithoutBackup().entity(Root.create(1, getCrossTldKey())).now()); clock.advanceOneMilli(); final Key otherTldKey = Key.create(getCrossTldKey(), Root.class, 1); @@ -157,7 +153,7 @@ public class OfyCommitLogTest { } @Test - public void testTransactNew_deleteNotBackedUpKind_throws() { + void testTransactNew_deleteNotBackedUpKind_throws() { final CommitLogManifest backupsArentAllowedOnMe = CommitLogManifest.create(getBucketKey(1), clock.nowUtc(), ImmutableSet.of()); IllegalArgumentException thrown = @@ -168,7 +164,7 @@ public class OfyCommitLogTest { } @Test - public void testTransactNew_saveNotBackedUpKind_throws() { + void testTransactNew_saveNotBackedUpKind_throws() { final CommitLogManifest backupsArentAllowedOnMe = CommitLogManifest.create(getBucketKey(1), clock.nowUtc(), ImmutableSet.of()); IllegalArgumentException thrown = @@ -179,7 +175,7 @@ public class OfyCommitLogTest { } @Test - public void testTransactNew_deleteVirtualEntityKey_throws() { + void testTransactNew_deleteVirtualEntityKey_throws() { final Key virtualEntityKey = TestVirtualObject.createKey("virtual"); IllegalArgumentException thrown = assertThrows( @@ -189,7 +185,7 @@ public class OfyCommitLogTest { } @Test - public void testTransactNew_saveVirtualEntity_throws() { + void testTransactNew_saveVirtualEntity_throws() { final TestVirtualObject virtualEntity = TestVirtualObject.create("virtual"); IllegalArgumentException thrown = assertThrows( @@ -199,7 +195,7 @@ public class OfyCommitLogTest { } @Test - public void test_deleteWithoutBackup_withVirtualEntityKey_throws() { + void test_deleteWithoutBackup_withVirtualEntityKey_throws() { final Key virtualEntityKey = TestVirtualObject.createKey("virtual"); IllegalArgumentException thrown = assertThrows( @@ -209,7 +205,7 @@ public class OfyCommitLogTest { } @Test - public void test_saveWithoutBackup_withVirtualEntity_throws() { + void test_saveWithoutBackup_withVirtualEntity_throws() { final TestVirtualObject virtualEntity = TestVirtualObject.create("virtual"); IllegalArgumentException thrown = assertThrows( @@ -218,7 +214,7 @@ public class OfyCommitLogTest { } @Test - public void testTransact_twoSavesOnSameKey_throws() { + void testTransact_twoSavesOnSameKey_throws() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -233,7 +229,7 @@ public class OfyCommitLogTest { } @Test - public void testTransact_saveAndDeleteSameKey_throws() { + void testTransact_saveAndDeleteSameKey_throws() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -248,7 +244,7 @@ public class OfyCommitLogTest { } @Test - public void testSavingRootAndChild_updatesTimestampOnBackupGroupRoot() { + void testSavingRootAndChild_updatesTimestampOnBackupGroupRoot() { tm().transact(() -> ofy().save().entity(Root.create(1, getCrossTldKey()))); ofy().clearSessionCache(); assertThat(ofy().load().key(Key.create(getCrossTldKey(), Root.class, 1)).now() @@ -266,7 +262,7 @@ public class OfyCommitLogTest { } @Test - public void testSavingOnlyChild_updatesTimestampOnBackupGroupRoot() { + void testSavingOnlyChild_updatesTimestampOnBackupGroupRoot() { tm().transact(() -> ofy().save().entity(Root.create(1, getCrossTldKey()))); ofy().clearSessionCache(); assertThat(ofy().load().key(Key.create(getCrossTldKey(), Root.class, 1)).now() @@ -279,7 +275,7 @@ public class OfyCommitLogTest { } @Test - public void testDeletingChild_updatesTimestampOnBackupGroupRoot() { + void testDeletingChild_updatesTimestampOnBackupGroupRoot() { tm().transact(() -> ofy().save().entity(Root.create(1, getCrossTldKey()))); ofy().clearSessionCache(); assertThat(ofy().load().key(Key.create(getCrossTldKey(), Root.class, 1)).now() @@ -293,7 +289,7 @@ public class OfyCommitLogTest { } @Test - public void testReadingRoot_doesntUpdateTimestamp() { + void testReadingRoot_doesntUpdateTimestamp() { tm().transact(() -> ofy().save().entity(Root.create(1, getCrossTldKey()))); ofy().clearSessionCache(); assertThat(ofy().load().key(Key.create(getCrossTldKey(), Root.class, 1)).now() @@ -313,7 +309,7 @@ public class OfyCommitLogTest { } @Test - public void testReadingChild_doesntUpdateTimestampOnBackupGroupRoot() { + void testReadingChild_doesntUpdateTimestampOnBackupGroupRoot() { tm().transact(() -> ofy().save().entity(Root.create(1, getCrossTldKey()))); ofy().clearSessionCache(); assertThat(ofy().load().key(Key.create(getCrossTldKey(), Root.class, 1)).now() @@ -333,7 +329,7 @@ public class OfyCommitLogTest { } @Test - public void testSavingAcrossBackupGroupRoots_updatesCorrectTimestamps() { + void testSavingAcrossBackupGroupRoots_updatesCorrectTimestamps() { // Create three roots. tm() .transact( diff --git a/core/src/test/java/google/registry/model/ofy/OfyFilterTest.java b/core/src/test/java/google/registry/model/ofy/OfyFilterTest.java index 2286a795d..212d25a61 100644 --- a/core/src/test/java/google/registry/model/ofy/OfyFilterTest.java +++ b/core/src/test/java/google/registry/model/ofy/OfyFilterTest.java @@ -28,23 +28,20 @@ import com.googlecode.objectify.ObjectifyService; import com.googlecode.objectify.annotation.Entity; import com.googlecode.objectify.annotation.Id; import google.registry.model.contact.ContactResource; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** Tests for our replacement Objectify filter. */ -@RunWith(JUnit4.class) -public class OfyFilterTest { +class OfyFilterTest { private LocalServiceTestHelper helper; private ObjectifyFactory factory; // We can't use AppEngineRule, because it triggers the precise behavior that we are testing. - @Before - public void before() { + @BeforeEach + void beforeEach() { helper = new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig()).setUp(); // Clear out the factory so that it requires re-registration on each test method. // Otherwise, static registration of types in one method would persist across methods. @@ -53,8 +50,8 @@ public class OfyFilterTest { ObjectifyService.setFactory(new ObjectifyFactory(false)); } - @After - public void after() { + @AfterEach + void afterEach() { ObjectifyFilter.complete(); ObjectifyService.setFactory(factory); ObjectifyFilter.complete(); @@ -65,12 +62,12 @@ public class OfyFilterTest { * Key.create looks up kind metadata for the class of the object it is given. If this happens * before the first reference to ObjectifyService, which statically triggers type registrations, * then the create will fail. Note that this is only a problem if the type in question doesn't - * call ObjectifyService.allocateId() inside its own builder or create method, since if it - * does that would trigger the statics as well. In this example, Registrar has a string id, so - * the bug occurs, were it not for OfyFilter. + * call ObjectifyService.allocateId() inside its own builder or create method, since if it does + * that would trigger the statics as well. In this example, Registrar has a string id, so the bug + * occurs, were it not for OfyFilter. */ @Test - public void testFilterRegistersTypes() { + void testFilterRegistersTypes() { UnregisteredEntity entity = new UnregisteredEntity(5L); IllegalStateException e = assertThrows(IllegalStateException.class, () -> Key.create(entity)); assertThat(e) @@ -82,7 +79,7 @@ public class OfyFilterTest { /** The filter should register all types for us. */ @Test - public void testKeyCreateAfterFilter() { + void testKeyCreateAfterFilter() { new OfyFilter().init(null); ContactResource contact = newContactResource("contact1234"); Key.create(contact); diff --git a/core/src/test/java/google/registry/model/ofy/OfyTest.java b/core/src/test/java/google/registry/model/ofy/OfyTest.java index 33b0b68e3..b84ef0f2d 100644 --- a/core/src/test/java/google/registry/model/ofy/OfyTest.java +++ b/core/src/test/java/google/registry/model/ofy/OfyTest.java @@ -52,23 +52,21 @@ import google.registry.util.SystemClock; import java.util.ConcurrentModificationException; import java.util.function.Supplier; 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 our wrapper around Objectify. */ -@RunWith(JUnit4.class) public class OfyTest { - @Rule + @RegisterExtension public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build(); + /** An entity to use in save and delete tests. */ private HistoryEntry someObject; - @Before - public void init() { + @BeforeEach + void beforeEach() { createTld("tld"); someObject = new HistoryEntry.Builder() .setClientId("client id") @@ -97,17 +95,17 @@ public class OfyTest { } @Test - public void testBackupGroupRootTimestampsMustIncreaseOnSave() { + void testBackupGroupRootTimestampsMustIncreaseOnSave() { doBackupGroupRootTimestampInversionTest(() -> ofy().save().entity(someObject)); } @Test - public void testBackupGroupRootTimestampsMustIncreaseOnDelete() { + void testBackupGroupRootTimestampsMustIncreaseOnDelete() { doBackupGroupRootTimestampInversionTest(() -> ofy().delete().entity(someObject)); } @Test - public void testSavingKeyTwice() { + void testSavingKeyTwice() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -122,7 +120,7 @@ public class OfyTest { } @Test - public void testDeletingKeyTwice() { + void testDeletingKeyTwice() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -137,7 +135,7 @@ public class OfyTest { } @Test - public void testSaveDeleteKey() { + void testSaveDeleteKey() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -152,7 +150,7 @@ public class OfyTest { } @Test - public void testDeleteSaveKey() { + void testDeleteSaveKey() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -167,7 +165,7 @@ public class OfyTest { } @Test - public void testSavingKeyTwiceInOneCall() { + void testSavingKeyTwiceInOneCall() { assertThrows( IllegalArgumentException.class, () -> tm().transact(() -> ofy().save().entities(someObject, someObject))); @@ -198,7 +196,7 @@ public class OfyTest { } @Test - public void testLifecycleCallbacks_loadFromEntity() { + void testLifecycleCallbacks_loadFromEntity() { ofy().factory().register(LifecycleObject.class); LifecycleObject object = new LifecycleObject(); Entity entity = ofy().save().toEntity(object); @@ -207,7 +205,7 @@ public class OfyTest { } @Test - public void testLifecycleCallbacks_loadFromDatastore() { + void testLifecycleCallbacks_loadFromDatastore() { ofy().factory().register(LifecycleObject.class); final LifecycleObject object = new LifecycleObject(); tm().transact(() -> ofy().save().entity(object).now()); @@ -218,7 +216,7 @@ public class OfyTest { /** Avoid regressions of b/21309102 where transaction time did not change on each retry. */ @Test - public void testTransact_getsNewTimestampOnEachTry() { + void testTransact_getsNewTimestampOnEachTry() { tm().transact(new Runnable() { DateTime firstAttemptTime; @@ -236,7 +234,7 @@ public class OfyTest { } @Test - public void testTransact_transientFailureException_retries() { + void testTransact_transientFailureException_retries() { assertThat( tm().transact( new Supplier() { @@ -256,7 +254,7 @@ public class OfyTest { } @Test - public void testTransact_datastoreTimeoutException_noManifest_retries() { + void testTransact_datastoreTimeoutException_noManifest_retries() { assertThat( tm().transact( new Supplier() { @@ -279,7 +277,7 @@ public class OfyTest { } @Test - public void testTransact_datastoreTimeoutException_manifestNotWrittenToDatastore_retries() { + void testTransact_datastoreTimeoutException_manifestNotWrittenToDatastore_retries() { assertThat( tm().transact( new Supplier() { @@ -302,7 +300,7 @@ public class OfyTest { } @Test - public void testTransact_datastoreTimeoutException_manifestWrittenToDatastore_returnsSuccess() { + void testTransact_datastoreTimeoutException_manifestWrittenToDatastore_returnsSuccess() { // A work unit that throws if it is ever retried. Supplier work = new Supplier() { @@ -356,22 +354,22 @@ public class OfyTest { } @Test - public void testTransactNewReadOnly_transientFailureException_retries() { + void testTransactNewReadOnly_transientFailureException_retries() { doReadOnlyRetryTest(new TransientFailureException("")); } @Test - public void testTransactNewReadOnly_datastoreTimeoutException_retries() { + void testTransactNewReadOnly_datastoreTimeoutException_retries() { doReadOnlyRetryTest(new DatastoreTimeoutException("")); } @Test - public void testTransactNewReadOnly_datastoreFailureException_retries() { + void testTransactNewReadOnly_datastoreFailureException_retries() { doReadOnlyRetryTest(new DatastoreFailureException("")); } @Test - public void test_getBaseEntityClassFromEntityOrKey_regularEntity() { + void test_getBaseEntityClassFromEntityOrKey_regularEntity() { ContactResource contact = newContactResource("testcontact"); assertThat(getBaseEntityClassFromEntityOrKey(contact)).isEqualTo(ContactResource.class); assertThat(getBaseEntityClassFromEntityOrKey(Key.create(contact))) @@ -379,7 +377,7 @@ public class OfyTest { } @Test - public void test_getBaseEntityClassFromEntityOrKey_subclassEntity() { + void test_getBaseEntityClassFromEntityOrKey_subclassEntity() { DomainBase domain = DatastoreHelper.newDomainBase("test.tld"); assertThat(getBaseEntityClassFromEntityOrKey(domain)).isEqualTo(DomainBase.class); assertThat(getBaseEntityClassFromEntityOrKey(Key.create(domain))) @@ -387,7 +385,7 @@ public class OfyTest { } @Test - public void test_getBaseEntityClassFromEntityOrKey_unregisteredEntity() { + void test_getBaseEntityClassFromEntityOrKey_unregisteredEntity() { IllegalStateException thrown = assertThrows( IllegalStateException.class, @@ -396,7 +394,7 @@ public class OfyTest { } @Test - public void test_getBaseEntityClassFromEntityOrKey_unregisteredEntityKey() { + void test_getBaseEntityClassFromEntityOrKey_unregisteredEntityKey() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -409,7 +407,7 @@ public class OfyTest { } @Test - public void test_doWithFreshSessionCache() { + void test_doWithFreshSessionCache() { ofy().saveWithoutBackup().entity(someObject).now(); final HistoryEntry modifiedObject = someObject.asBuilder().setModificationTime(END_OF_TIME).build(); diff --git a/core/src/test/java/google/registry/model/poll/PollMessageExternalKeyConverterTest.java b/core/src/test/java/google/registry/model/poll/PollMessageExternalKeyConverterTest.java index f25d2e4b1..c586e5264 100644 --- a/core/src/test/java/google/registry/model/poll/PollMessageExternalKeyConverterTest.java +++ b/core/src/test/java/google/registry/model/poll/PollMessageExternalKeyConverterTest.java @@ -35,27 +35,23 @@ import google.registry.testing.AppEngineRule; import google.registry.testing.FakeClock; import google.registry.testing.InjectRule; 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; /** Unit tests for {@link PollMessageExternalKeyConverter}. */ -@RunWith(JUnit4.class) public class PollMessageExternalKeyConverterTest { - @Rule + @RegisterExtension public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build(); - @Rule - public InjectRule inject = new InjectRule(); + @RegisterExtension public InjectRule inject = new InjectRule(); - HistoryEntry historyEntry; - FakeClock clock = new FakeClock(DateTime.parse("2007-07-07T01:01:01Z")); + private HistoryEntry historyEntry; + private FakeClock clock = new FakeClock(DateTime.parse("2007-07-07T01:01:01Z")); - @Before - public void setUp() { + @BeforeEach + void beforeEach() { inject.setStaticField(Ofy.class, "clock", clock); createTld("foobar"); historyEntry = persistResource(new HistoryEntry.Builder() @@ -73,7 +69,7 @@ public class PollMessageExternalKeyConverterTest { } @Test - public void testSuccess_domain() { + void testSuccess_domain() { PollMessage.OneTime pollMessage = persistResource( new PollMessage.OneTime.Builder() @@ -88,7 +84,7 @@ public class PollMessageExternalKeyConverterTest { } @Test - public void testSuccess_contact() { + void testSuccess_contact() { historyEntry = persistResource(historyEntry.asBuilder().setParent(persistActiveContact("tim")).build()); PollMessage.OneTime pollMessage = @@ -104,7 +100,7 @@ public class PollMessageExternalKeyConverterTest { } @Test - public void testSuccess_host() { + void testSuccess_host() { historyEntry = persistResource(historyEntry.asBuilder().setParent(persistActiveHost("time.zyx")).build()); PollMessage.OneTime pollMessage = @@ -120,14 +116,14 @@ public class PollMessageExternalKeyConverterTest { } @Test - public void testFailure_missingYearField() { + void testFailure_missingYearField() { assertThrows( PollMessageExternalKeyParseException.class, () -> parsePollMessageExternalId("1-2-FOOBAR-4-5")); } @Test - public void testFailure_invalidEppResourceTypeId() { + void testFailure_invalidEppResourceTypeId() { // Populate the testdata correctly as for 1-2-FOOBAR-4-5 so we know that the only thing that // is wrong here is the EppResourceTypeId. testSuccess_domain(); @@ -137,22 +133,21 @@ public class PollMessageExternalKeyConverterTest { } @Test - public void testFailure_tooFewComponentParts() { + void testFailure_tooFewComponentParts() { assertThrows( PollMessageExternalKeyParseException.class, () -> parsePollMessageExternalId("1-3-EXAMPLE")); } @Test - public void testFailure_tooManyComponentParts() { + void testFailure_tooManyComponentParts() { assertThrows( PollMessageExternalKeyParseException.class, () -> parsePollMessageExternalId("1-3-EXAMPLE-4-5-2007-2009")); } - @Test - public void testFailure_nonNumericIds() { + void testFailure_nonNumericIds() { assertThrows( PollMessageExternalKeyParseException.class, () -> parsePollMessageExternalId("A-B-FOOBAR-D-E-F")); diff --git a/core/src/test/java/google/registry/model/poll/PollMessageTest.java b/core/src/test/java/google/registry/model/poll/PollMessageTest.java index 3dfea9b63..787966114 100644 --- a/core/src/test/java/google/registry/model/poll/PollMessageTest.java +++ b/core/src/test/java/google/registry/model/poll/PollMessageTest.java @@ -34,16 +34,16 @@ import org.junit.jupiter.api.Test; /** Unit tests for {@link PollMessage}. */ public class PollMessageTest extends EntityTestCase { - HistoryEntry historyEntry; - PollMessage.OneTime oneTime; - PollMessage.Autorenew autoRenew; + private HistoryEntry historyEntry; + private PollMessage.OneTime oneTime; + private PollMessage.Autorenew autoRenew; - public PollMessageTest() { + PollMessageTest() { super(JpaEntityCoverageCheck.ENABLED); } @BeforeEach - public void setUp() { + void setUp() { createTld("foobar"); historyEntry = persistResource( @@ -123,7 +123,7 @@ public class PollMessageTest extends EntityTestCase { } @Test - public void testPersistenceOneTime() { + void testPersistenceOneTime() { PollMessage.OneTime pollMessage = persistResource( new PollMessage.OneTime.Builder() @@ -136,7 +136,7 @@ public class PollMessageTest extends EntityTestCase { } @Test - public void testPersistenceAutorenew() { + void testPersistenceAutorenew() { PollMessage.Autorenew pollMessage = persistResource( new PollMessage.Autorenew.Builder() @@ -151,7 +151,7 @@ public class PollMessageTest extends EntityTestCase { } @Test - public void testIndexingAutorenew() throws Exception { + void testIndexingAutorenew() throws Exception { PollMessage.Autorenew pollMessage = persistResource( new PollMessage.Autorenew.Builder() diff --git a/core/src/test/java/google/registry/model/registrar/RegistrarTest.java b/core/src/test/java/google/registry/model/registrar/RegistrarTest.java index 1191f05e5..e851d7658 100644 --- a/core/src/test/java/google/registry/model/registrar/RegistrarTest.java +++ b/core/src/test/java/google/registry/model/registrar/RegistrarTest.java @@ -44,16 +44,16 @@ import google.registry.model.registrar.Registrar.Type; import google.registry.model.registry.Registries; import google.registry.util.CidrAddressBlock; import org.joda.money.CurrencyUnit; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** Unit tests for {@link Registrar}. */ -public class RegistrarTest extends EntityTestCase { +class RegistrarTest extends EntityTestCase { private Registrar registrar; private RegistrarContact abuseAdminContact; - @Before - public void setUp() { + @BeforeEach + void setUp() { createTld("xn--q9jyb4c"); // Set up a new persisted registrar entity. registrar = @@ -127,7 +127,7 @@ public class RegistrarTest extends EntityTestCase { } @Test - public void testPersistence() { + void testPersistence() { assertThat(registrar) .isEqualTo( ofy() @@ -139,12 +139,12 @@ public class RegistrarTest extends EntityTestCase { } @Test - public void testIndexing() throws Exception { + void testIndexing() throws Exception { verifyIndexing(registrar, "registrarName", "ianaIdentifier"); } @Test - public void testFailure_passwordNull() { + void testFailure_passwordNull() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, () -> new Registrar.Builder().setPassword(null)); @@ -152,7 +152,7 @@ public class RegistrarTest extends EntityTestCase { } @Test - public void testFailure_passwordTooShort() { + void testFailure_passwordTooShort() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, () -> new Registrar.Builder().setPassword("abcde")); @@ -160,7 +160,7 @@ public class RegistrarTest extends EntityTestCase { } @Test - public void testFailure_passwordTooLong() { + void testFailure_passwordTooLong() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -169,7 +169,7 @@ public class RegistrarTest extends EntityTestCase { } @Test - public void testSuccess_clientId_bounds() { + void testSuccess_clientId_bounds() { registrar = registrar.asBuilder().setClientId("abc").build(); assertThat(registrar.getClientId()).isEqualTo("abc"); registrar = registrar.asBuilder().setClientId("abcdefghijklmnop").build(); @@ -177,19 +177,19 @@ public class RegistrarTest extends EntityTestCase { } @Test - public void testFailure_clientId_tooShort() { + void testFailure_clientId_tooShort() { assertThrows(IllegalArgumentException.class, () -> new Registrar.Builder().setClientId("ab")); } @Test - public void testFailure_clientId_tooLong() { + void testFailure_clientId_tooLong() { assertThrows( IllegalArgumentException.class, () -> new Registrar.Builder().setClientId("abcdefghijklmnopq")); } @Test - public void testSetCertificateHash_alsoSetsHash() { + void testSetCertificateHash_alsoSetsHash() { registrar = registrar.asBuilder().setClientCertificate(null, fakeClock.nowUtc()).build(); fakeClock.advanceOneMilli(); registrar = registrar.asBuilder().setClientCertificate(SAMPLE_CERT, fakeClock.nowUtc()).build(); @@ -199,7 +199,7 @@ public class RegistrarTest extends EntityTestCase { } @Test - public void testDeleteCertificateHash_alsoDeletesHash() { + void testDeleteCertificateHash_alsoDeletesHash() { assertThat(registrar.getClientCertificateHash()).isNotNull(); fakeClock.advanceOneMilli(); registrar = registrar.asBuilder().setClientCertificate(null, fakeClock.nowUtc()).build(); @@ -209,7 +209,7 @@ public class RegistrarTest extends EntityTestCase { } @Test - public void testSetFailoverCertificateHash_alsoSetsHash() { + void testSetFailoverCertificateHash_alsoSetsHash() { fakeClock.advanceOneMilli(); registrar = registrar @@ -222,7 +222,7 @@ public class RegistrarTest extends EntityTestCase { } @Test - public void testDeleteFailoverCertificateHash_alsoDeletesHash() { + void testDeleteFailoverCertificateHash_alsoDeletesHash() { registrar = registrar.asBuilder().setFailoverClientCertificate(SAMPLE_CERT, fakeClock.nowUtc()).build(); assertThat(registrar.getFailoverClientCertificateHash()).isNotNull(); @@ -235,7 +235,7 @@ public class RegistrarTest extends EntityTestCase { } @Test - public void testSuccess_clearingIanaAndBillingIds() { + void testSuccess_clearingIanaAndBillingIds() { registrar .asBuilder() .setType(Type.TEST) @@ -245,30 +245,30 @@ public class RegistrarTest extends EntityTestCase { } @Test - public void testSuccess_clearingBillingAccountMap() { + void testSuccess_clearingBillingAccountMap() { registrar = registrar.asBuilder().setBillingAccountMap(null).build(); assertThat(registrar.getBillingAccountMap()).isEmpty(); } @Test - public void testSuccess_ianaIdForInternal() { + void testSuccess_ianaIdForInternal() { registrar.asBuilder().setType(Type.INTERNAL).setIanaIdentifier(9998L).build(); registrar.asBuilder().setType(Type.INTERNAL).setIanaIdentifier(9999L).build(); } @Test - public void testSuccess_ianaIdForPdt() { + void testSuccess_ianaIdForPdt() { registrar.asBuilder().setType(Type.PDT).setIanaIdentifier(9995L).build(); registrar.asBuilder().setType(Type.PDT).setIanaIdentifier(9996L).build(); } @Test - public void testSuccess_ianaIdForExternalMonitoring() { + void testSuccess_ianaIdForExternalMonitoring() { registrar.asBuilder().setType(Type.EXTERNAL_MONITORING).setIanaIdentifier(9997L).build(); } @Test - public void testSuccess_emptyContactTypesAllowed() { + void testSuccess_emptyContactTypesAllowed() { persistSimpleResource( new RegistrarContact.Builder() .setParent(registrar) @@ -284,7 +284,7 @@ public class RegistrarTest extends EntityTestCase { } @Test - public void testSuccess_getContactsByType() { + void testSuccess_getContactsByType() { RegistrarContact newTechContact = persistSimpleResource( new RegistrarContact.Builder() @@ -318,7 +318,7 @@ public class RegistrarTest extends EntityTestCase { } @Test - public void testFailure_missingRegistrarType() { + void testFailure_missingRegistrarType() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -327,7 +327,7 @@ public class RegistrarTest extends EntityTestCase { } @Test - public void testFailure_missingRegistrarName() { + void testFailure_missingRegistrarName() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -337,7 +337,7 @@ public class RegistrarTest extends EntityTestCase { } @Test - public void testFailure_missingAddress() { + void testFailure_missingAddress() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -353,21 +353,21 @@ public class RegistrarTest extends EntityTestCase { } @Test - public void testFailure_badIanaIdForInternal() { + void testFailure_badIanaIdForInternal() { assertThrows( IllegalArgumentException.class, () -> new Registrar.Builder().setType(Type.INTERNAL).setIanaIdentifier(8L).build()); } @Test - public void testFailure_badIanaIdForPdt() { + void testFailure_badIanaIdForPdt() { assertThrows( IllegalArgumentException.class, () -> new Registrar.Builder().setType(Type.PDT).setIanaIdentifier(8L).build()); } @Test - public void testFailure_badIanaIdForExternalMonitoring() { + void testFailure_badIanaIdForExternalMonitoring() { assertThrows( IllegalArgumentException.class, () -> @@ -375,51 +375,51 @@ public class RegistrarTest extends EntityTestCase { } @Test - public void testFailure_missingIanaIdForReal() { + void testFailure_missingIanaIdForReal() { assertThrows( IllegalArgumentException.class, () -> new Registrar.Builder().setType(Type.REAL).build()); } @Test - public void testFailure_missingIanaIdForInternal() { + void testFailure_missingIanaIdForInternal() { assertThrows( IllegalArgumentException.class, () -> new Registrar.Builder().setType(Type.INTERNAL).build()); } @Test - public void testFailure_missingIanaIdForPdt() { + void testFailure_missingIanaIdForPdt() { assertThrows( IllegalArgumentException.class, () -> new Registrar.Builder().setType(Type.PDT).build()); } @Test - public void testFailure_missingIanaIdForExternalMonitoring() { + void testFailure_missingIanaIdForExternalMonitoring() { assertThrows( IllegalArgumentException.class, () -> new Registrar.Builder().setType(Type.EXTERNAL_MONITORING).build()); } @Test - public void testFailure_phonePasscodeTooShort() { + void testFailure_phonePasscodeTooShort() { assertThrows( IllegalArgumentException.class, () -> new Registrar.Builder().setPhonePasscode("0123")); } @Test - public void testFailure_phonePasscodeTooLong() { + void testFailure_phonePasscodeTooLong() { assertThrows( IllegalArgumentException.class, () -> new Registrar.Builder().setPhonePasscode("012345")); } @Test - public void testFailure_phonePasscodeInvalidCharacters() { + void testFailure_phonePasscodeInvalidCharacters() { assertThrows( IllegalArgumentException.class, () -> new Registrar.Builder().setPhonePasscode("code1")); } @Test - public void testSuccess_setAllowedTlds() { + void testSuccess_setAllowedTlds() { assertThat( registrar .asBuilder() @@ -430,7 +430,7 @@ public class RegistrarTest extends EntityTestCase { } @Test - public void testSuccess_setAllowedTldsUncached() { + void testSuccess_setAllowedTldsUncached() { assertThat( registrar .asBuilder() @@ -441,21 +441,21 @@ public class RegistrarTest extends EntityTestCase { } @Test - public void testFailure_setAllowedTlds_nonexistentTld() { + void testFailure_setAllowedTlds_nonexistentTld() { assertThrows( IllegalArgumentException.class, () -> registrar.asBuilder().setAllowedTlds(ImmutableSet.of("bad"))); } @Test - public void testFailure_setAllowedTldsUncached_nonexistentTld() { + void testFailure_setAllowedTldsUncached_nonexistentTld() { assertThrows( IllegalArgumentException.class, () -> registrar.asBuilder().setAllowedTldsUncached(ImmutableSet.of("bad"))); } @Test - public void testFailure_driveFolderId_asFullUrl() { + void testFailure_driveFolderId_asFullUrl() { String driveFolderId = "https://drive.google.com/drive/folders/1j3v7RZkU25DjbTx2-Q93H04zKOBau89M"; IllegalArgumentException thrown = @@ -466,14 +466,14 @@ public class RegistrarTest extends EntityTestCase { } @Test - public void testFailure_nullEmail() { + void testFailure_nullEmail() { NullPointerException thrown = assertThrows(NullPointerException.class, () -> registrar.asBuilder().setEmailAddress(null)); assertThat(thrown).hasMessageThat().isEqualTo("Provided email was null"); } @Test - public void testFailure_invalidEmail() { + void testFailure_invalidEmail() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, () -> registrar.asBuilder().setEmailAddress("lolcat")); @@ -483,7 +483,7 @@ public class RegistrarTest extends EntityTestCase { } @Test - public void testFailure_emptyEmail() { + void testFailure_emptyEmail() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, () -> registrar.asBuilder().setEmailAddress("")); @@ -491,7 +491,7 @@ public class RegistrarTest extends EntityTestCase { } @Test - public void testFailure_nullIcannReferralEmail() { + void testFailure_nullIcannReferralEmail() { NullPointerException thrown = assertThrows( NullPointerException.class, () -> registrar.asBuilder().setIcannReferralEmail(null)); @@ -499,7 +499,7 @@ public class RegistrarTest extends EntityTestCase { } @Test - public void testFailure_invalidIcannReferralEmail() { + void testFailure_invalidIcannReferralEmail() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -510,7 +510,7 @@ public class RegistrarTest extends EntityTestCase { } @Test - public void testFailure_emptyIcannReferralEmail() { + void testFailure_emptyIcannReferralEmail() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, () -> registrar.asBuilder().setEmailAddress("")); @@ -518,7 +518,7 @@ public class RegistrarTest extends EntityTestCase { } @Test - public void testSuccess_setAllowedTldsUncached_newTldNotInCache() { + void testSuccess_setAllowedTldsUncached_newTldNotInCache() { int origSingletonCacheRefreshSeconds = RegistryConfig.CONFIG_SETTINGS.get().caching.singletonCacheRefreshSeconds; // Sanity check for Gradle-based open-source build. @@ -567,7 +567,7 @@ public class RegistrarTest extends EntityTestCase { } @Test - public void testLoadByClientIdCached_isTransactionless() { + void testLoadByClientIdCached_isTransactionless() { tm().transact( () -> { assertThat(Registrar.loadByClientIdCached("registrar")).isPresent(); @@ -584,28 +584,28 @@ public class RegistrarTest extends EntityTestCase { } @Test - public void testFailure_loadByClientId_clientIdIsNull() { + void testFailure_loadByClientId_clientIdIsNull() { IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () -> Registrar.loadByClientId(null)); assertThat(thrown).hasMessageThat().contains("clientId must be specified"); } @Test - public void testFailure_loadByClientId_clientIdIsEmpty() { + void testFailure_loadByClientId_clientIdIsEmpty() { IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () -> Registrar.loadByClientId("")); assertThat(thrown).hasMessageThat().contains("clientId must be specified"); } @Test - public void testFailure_loadByClientIdCached_clientIdIsNull() { + void testFailure_loadByClientIdCached_clientIdIsNull() { IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () -> Registrar.loadByClientIdCached(null)); assertThat(thrown).hasMessageThat().contains("clientId must be specified"); } @Test - public void testFailure_loadByClientIdCached_clientIdIsEmpty() { + void testFailure_loadByClientIdCached_clientIdIsEmpty() { IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () -> Registrar.loadByClientIdCached("")); assertThat(thrown).hasMessageThat().contains("clientId must be specified"); diff --git a/core/src/test/java/google/registry/model/registry/RegistryLockDaoTest.java b/core/src/test/java/google/registry/model/registry/RegistryLockDaoTest.java index 2802b68a4..1564f1227 100644 --- a/core/src/test/java/google/registry/model/registry/RegistryLockDaoTest.java +++ b/core/src/test/java/google/registry/model/registry/RegistryLockDaoTest.java @@ -35,12 +35,12 @@ import org.junit.jupiter.api.Test; /** Unit tests for {@link RegistryLockDao}. */ public final class RegistryLockDaoTest extends EntityTestCase { - public RegistryLockDaoTest() { + RegistryLockDaoTest() { super(JpaEntityCoverageCheck.ENABLED); } @Test - public void testSaveAndLoad_success() { + void testSaveAndLoad_success() { RegistryLock lock = createLock(); saveRegistryLock(lock); RegistryLock fromDatabase = getRegistryLockByVerificationCode(lock.getVerificationCode()).get(); @@ -50,7 +50,7 @@ public final class RegistryLockDaoTest extends EntityTestCase { } @Test - public void testSaveTwiceAndLoad_returnsLatest() { + void testSaveTwiceAndLoad_returnsLatest() { RegistryLock lock = createLock(); saveRegistryLock(lock); fakeClock.advanceOneMilli(); @@ -74,7 +74,7 @@ public final class RegistryLockDaoTest extends EntityTestCase { } @Test - public void testSave_load_withUnlock() { + void testSave_load_withUnlock() { RegistryLock lock = saveRegistryLock( createLock() @@ -93,7 +93,7 @@ public final class RegistryLockDaoTest extends EntityTestCase { } @Test - public void testUpdateLock_usingSamePrimaryKey() { + void testUpdateLock_usingSamePrimaryKey() { RegistryLock lock = saveRegistryLock(createLock()); fakeClock.advanceOneMilli(); RegistryLock updatedLock = @@ -110,17 +110,17 @@ public final class RegistryLockDaoTest extends EntityTestCase { } @Test - public void testFailure_saveNull() { + void testFailure_saveNull() { assertThrows(NullPointerException.class, () -> saveRegistryLock(null)); } @Test - public void getLock_unknownCode() { + void getLock_unknownCode() { assertThat(getRegistryLockByVerificationCode("hi").isPresent()).isFalse(); } @Test - public void testByRevisionId_valid() { + void testByRevisionId_valid() { RegistryLock lock = saveRegistryLock(createLock()); RegistryLock otherLock = getRegistryLockByRevisionId(lock.getRevisionId()).get(); // can't do direct comparison due to update time @@ -129,12 +129,12 @@ public final class RegistryLockDaoTest extends EntityTestCase { } @Test - public void testByRevisionId_invalid() { + void testByRevisionId_invalid() { assertThat(getRegistryLockByRevisionId(8675309L).isPresent()).isFalse(); } @Test - public void testLoad_lockedDomains_byRegistrarId() { + void testLoad_lockedDomains_byRegistrarId() { RegistryLock lock = createLock(); RegistryLock secondLock = createLock() @@ -163,7 +163,7 @@ public final class RegistryLockDaoTest extends EntityTestCase { } @Test - public void testLoad_byRepoId() { + void testLoad_byRepoId() { RegistryLock completedLock = createLock().asBuilder().setLockCompletionTimestamp(fakeClock.nowUtc()).build(); saveRegistryLock(completedLock); @@ -178,12 +178,12 @@ public final class RegistryLockDaoTest extends EntityTestCase { } @Test - public void testLoad_byRepoId_empty() { + void testLoad_byRepoId_empty() { assertThat(getMostRecentRegistryLockByRepoId("nonexistent").isPresent()).isFalse(); } @Test - public void testLoad_verified_byRepoId() { + void testLoad_verified_byRepoId() { RegistryLock completedLock = createLock().asBuilder().setLockCompletionTimestamp(fakeClock.nowUtc()).build(); saveRegistryLock(completedLock); @@ -198,14 +198,14 @@ public final class RegistryLockDaoTest extends EntityTestCase { } @Test - public void testLoad_verified_byRepoId_empty() { + void testLoad_verified_byRepoId_empty() { saveRegistryLock(createLock()); Optional mostRecent = getMostRecentVerifiedRegistryLockByRepoId("repoId"); assertThat(mostRecent.isPresent()).isFalse(); } @Test - public void testLoad_verifiedUnlock_byRepoId() { + void testLoad_verifiedUnlock_byRepoId() { RegistryLock lock = saveRegistryLock( createLock() @@ -220,7 +220,7 @@ public final class RegistryLockDaoTest extends EntityTestCase { } @Test - public void testLoad_verifiedUnlock_empty() { + void testLoad_verifiedUnlock_empty() { RegistryLock completedLock = createLock().asBuilder().setLockCompletionTimestamp(fakeClock.nowUtc()).build(); saveRegistryLock(completedLock); diff --git a/core/src/test/java/google/registry/model/registry/RegistryTest.java b/core/src/test/java/google/registry/model/registry/RegistryTest.java index 58d2332f6..ced7963ce 100644 --- a/core/src/test/java/google/registry/model/registry/RegistryTest.java +++ b/core/src/test/java/google/registry/model/registry/RegistryTest.java @@ -46,40 +46,37 @@ import google.registry.model.registry.label.ReservedList; import java.math.BigDecimal; import org.joda.money.Money; import org.joda.time.DateTime; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** Unit tests for {@link Registry}. */ -public class RegistryTest extends EntityTestCase { +class RegistryTest extends EntityTestCase { - Registry registry; - - @Before - public void setup() { + @BeforeEach + void beforeEach() { createTld("tld"); - registry = Registry.get("tld"); } @Test - public void testPersistence() { + void testPersistence() { assertWithMessage("Registry not found").that(Registry.get("tld")).isNotNull(); assertThat(ofy().load().type(Registry.class).parent(getCrossTldKey()).id("tld").now()) .isEqualTo(Registry.get("tld")); } @Test - public void testFailure_registryNotFound() { + void testFailure_registryNotFound() { createTld("foo"); assertThrows(RegistryNotFoundException.class, () -> Registry.get("baz")); } @Test - public void testIndexing() throws Exception { + void testIndexing() throws Exception { verifyIndexing(Registry.get("tld")); } @Test - public void testSettingEscrowEnabled_null() { + void testSettingEscrowEnabled_null() { assertThat(Registry.get("tld").asBuilder().setEscrowEnabled(true).build().getEscrowEnabled()) .isTrue(); assertThat(Registry.get("tld").asBuilder().setEscrowEnabled(false).build().getEscrowEnabled()) @@ -87,7 +84,7 @@ public class RegistryTest extends EntityTestCase { } @Test - public void testSettingCreateBillingCost() { + void testSettingCreateBillingCost() { Registry registry = Registry.get("tld").asBuilder().setCreateBillingCost(Money.of(USD, 42)).build(); assertThat(registry.getStandardCreateCost()).isEqualTo(Money.of(USD, 42)); @@ -96,7 +93,7 @@ public class RegistryTest extends EntityTestCase { } @Test - public void testSettingRestoreBillingCost() { + void testSettingRestoreBillingCost() { Registry registry = Registry.get("tld").asBuilder().setRestoreBillingCost(Money.of(USD, 42)).build(); // The default value of 13 is set in createTld(). @@ -105,19 +102,19 @@ public class RegistryTest extends EntityTestCase { } @Test - public void testDefaultNumDnsPublishShards_equalToOne() { + void testDefaultNumDnsPublishShards_equalToOne() { Registry registry = Registry.get("tld").asBuilder().build(); assertThat(registry.getNumDnsPublishLocks()).isEqualTo(1); } @Test - public void testSettingNumDnsPublishShards() { + void testSettingNumDnsPublishShards() { Registry registry = Registry.get("tld").asBuilder().setNumDnsPublishLocks(2).build(); assertThat(registry.getNumDnsPublishLocks()).isEqualTo(2); } @Test - public void testSetReservedList_doesntMutateExistingRegistry() { + void testSetReservedList_doesntMutateExistingRegistry() { ReservedList rl15 = persistReservedList("tld-reserved15", "potato,FULLY_BLOCKED", "phone,FULLY_BLOCKED"); ReservedList rl16 = @@ -135,14 +132,14 @@ public class RegistryTest extends EntityTestCase { } @Test - public void testGetReservedLists_doesntReturnNullWhenUninitialized() { + void testGetReservedLists_doesntReturnNullWhenUninitialized() { Registry registry = newRegistry("foo", "FOO"); assertThat(registry.getReservedLists()).isNotNull(); assertThat(registry.getReservedLists()).isEmpty(); } @Test - public void testGetAll() { + void testGetAll() { createTld("foo"); assertThat(Registry.getAll(ImmutableSet.of("foo", "tld"))) .containsExactlyElementsIn( @@ -155,7 +152,7 @@ public class RegistryTest extends EntityTestCase { } @Test - public void testSetReservedLists() { + void testSetReservedLists() { ReservedList rl5 = persistReservedList("tld-reserved5", "lol,FULLY_BLOCKED", "cat,FULLY_BLOCKED"); ReservedList rl6 = @@ -169,7 +166,7 @@ public class RegistryTest extends EntityTestCase { } @Test - public void testSetReservedListsByName() { + void testSetReservedListsByName() { persistReservedList("tld-reserved24", "lol,FULLY_BLOCKED", "cat,FULLY_BLOCKED"); persistReservedList("tld-reserved25", "mit,FULLY_BLOCKED", "tim,FULLY_BLOCKED"); Registry r = @@ -184,7 +181,7 @@ public class RegistryTest extends EntityTestCase { } @Test - public void testSetPremiumList() { + void testSetPremiumList() { PremiumList pl2 = persistPremiumList("tld2", "lol,USD 50", "cat,USD 700"); Registry registry = Registry.get("tld").asBuilder().setPremiumList(pl2).build(); Key plKey = registry.getPremiumList(); @@ -194,20 +191,20 @@ public class RegistryTest extends EntityTestCase { } @Test - public void testSettingServerStatusChangeBillingCost() { + void testSettingServerStatusChangeBillingCost() { Registry registry = Registry.get("tld").asBuilder().setServerStatusChangeBillingCost(Money.of(USD, 42)).build(); assertThat(registry.getServerStatusChangeCost()).isEqualTo(Money.of(USD, 42)); } @Test - public void testSettingLordnUsername() { + void testSettingLordnUsername() { Registry registry = Registry.get("tld").asBuilder().setLordnUsername("username").build(); assertThat(registry.getLordnUsername()).isEqualTo("username"); } @Test - public void testSettingDnsWriters() { + void testSettingDnsWriters() { Registry registry = Registry.get("tld"); assertThat(registry.getDnsWriters()).containsExactly(VoidDnsWriter.NAME); registry = registry.asBuilder().setDnsWriters(ImmutableSet.of("baz", "bang")).build(); @@ -215,7 +212,7 @@ public class RegistryTest extends EntityTestCase { } @Test - public void testPdtLooksLikeGa() { + void testPdtLooksLikeGa() { Registry registry = Registry.get("tld") .asBuilder() @@ -225,7 +222,7 @@ public class RegistryTest extends EntityTestCase { } @Test - public void testTldStateTransitionTimes() { + void testTldStateTransitionTimes() { Registry registry = Registry.get("tld") .asBuilder() @@ -260,7 +257,7 @@ public class RegistryTest extends EntityTestCase { } @Test - public void testQuietPeriodCanAppearMultipleTimesAnywhere() { + void testQuietPeriodCanAppearMultipleTimesAnywhere() { Registry.get("tld") .asBuilder() .setTldStateTransitions( @@ -275,7 +272,7 @@ public class RegistryTest extends EntityTestCase { } @Test - public void testRenewBillingCostTransitionTimes() { + void testRenewBillingCostTransitionTimes() { Registry registry = Registry.get("tld") .asBuilder() @@ -314,7 +311,7 @@ public class RegistryTest extends EntityTestCase { } @Test - public void testRenewBillingCostNoTransitions() { + void testRenewBillingCostNoTransitions() { Registry registry = Registry.get("tld"); // The default value of 11 is set in createTld(). assertThat(registry.getStandardRenewCost(START_OF_TIME)).isEqualTo(Money.of(USD, 11)); @@ -327,21 +324,21 @@ public class RegistryTest extends EntityTestCase { } @Test - public void testFailure_tldNeverSet() { + void testFailure_tldNeverSet() { IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () -> new Registry.Builder().build()); assertThat(thrown).hasMessageThat().contains("No registry TLD specified"); } @Test - public void testFailure_setTldStr_null() { + void testFailure_setTldStr_null() { IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () -> new Registry.Builder().setTldStr(null)); assertThat(thrown).hasMessageThat().contains("TLD must not be null"); } @Test - public void testFailure_setTldStr_invalidTld() { + void testFailure_setTldStr_invalidTld() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, () -> new Registry.Builder().setTldStr(".tld").build()); @@ -351,7 +348,7 @@ public class RegistryTest extends EntityTestCase { } @Test - public void testFailure_setTldStr_nonCanonicalTld() { + void testFailure_setTldStr_nonCanonicalTld() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, () -> new Registry.Builder().setTldStr("TLD").build()); @@ -361,7 +358,7 @@ public class RegistryTest extends EntityTestCase { } @Test - public void testFailure_tldStatesOutOfOrder() { + void testFailure_tldStatesOutOfOrder() { assertThrows( IllegalArgumentException.class, () -> @@ -375,7 +372,7 @@ public class RegistryTest extends EntityTestCase { } @Test - public void testFailure_duplicateTldState() { + void testFailure_duplicateTldState() { assertThrows( IllegalArgumentException.class, () -> @@ -389,7 +386,7 @@ public class RegistryTest extends EntityTestCase { } @Test - public void testFailure_pricingEngineIsRequired() { + void testFailure_pricingEngineIsRequired() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -400,7 +397,7 @@ public class RegistryTest extends EntityTestCase { } @Test - public void testFailure_negativeRenewBillingCostTransitionValue() { + void testFailure_negativeRenewBillingCostTransitionValue() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -413,7 +410,7 @@ public class RegistryTest extends EntityTestCase { } @Test - public void testFailure_negativeCreateBillingCost() { + void testFailure_negativeCreateBillingCost() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -422,7 +419,7 @@ public class RegistryTest extends EntityTestCase { } @Test - public void testFailure_negativeRestoreBillingCost() { + void testFailure_negativeRestoreBillingCost() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -431,7 +428,7 @@ public class RegistryTest extends EntityTestCase { } @Test - public void testFailure_nonPositiveNumDnsPublishLocks() { + void testFailure_nonPositiveNumDnsPublishLocks() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -451,7 +448,7 @@ public class RegistryTest extends EntityTestCase { } @Test - public void testFailure_negativeServerStatusChangeBillingCost() { + void testFailure_negativeServerStatusChangeBillingCost() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -463,7 +460,7 @@ public class RegistryTest extends EntityTestCase { } @Test - public void testFailure_renewBillingCostTransitionValue_wrongCurrency() { + void testFailure_renewBillingCostTransitionValue_wrongCurrency() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -477,7 +474,7 @@ public class RegistryTest extends EntityTestCase { } @Test - public void testFailure_createBillingCost_wrongCurrency() { + void testFailure_createBillingCost_wrongCurrency() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -486,7 +483,7 @@ public class RegistryTest extends EntityTestCase { } @Test - public void testFailure_restoreBillingCost_wrongCurrency() { + void testFailure_restoreBillingCost_wrongCurrency() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -495,7 +492,7 @@ public class RegistryTest extends EntityTestCase { } @Test - public void testFailure_serverStatusChangeBillingCost_wrongCurrency() { + void testFailure_serverStatusChangeBillingCost_wrongCurrency() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -508,13 +505,13 @@ public class RegistryTest extends EntityTestCase { } @Test - public void testEapFee_undefined() { + void testEapFee_undefined() { assertThat(Registry.get("tld").getEapFeeFor(fakeClock.nowUtc()).getCost()) .isEqualTo(BigDecimal.ZERO.setScale(2, ROUND_UNNECESSARY)); } @Test - public void testEapFee_specified() { + void testEapFee_specified() { DateTime a = fakeClock.nowUtc().minusDays(1); DateTime b = fakeClock.nowUtc().plusDays(1); Registry registry = @@ -536,7 +533,7 @@ public class RegistryTest extends EntityTestCase { } @Test - public void testFailure_eapFee_wrongCurrency() { + void testFailure_eapFee_wrongCurrency() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -549,7 +546,7 @@ public class RegistryTest extends EntityTestCase { } @Test - public void testFailure_roidSuffixTooLong() { + void testFailure_roidSuffixTooLong() { IllegalArgumentException e = assertThrows( IllegalArgumentException.class, @@ -558,14 +555,14 @@ public class RegistryTest extends EntityTestCase { } @Test - public void testFailure_roidSuffixNotUppercased() { + void testFailure_roidSuffixNotUppercased() { assertThrows( IllegalArgumentException.class, () -> Registry.get("tld").asBuilder().setRoidSuffix("abcd")); } @Test - public void testFailure_roidSuffixContainsInvalidCharacters() { + void testFailure_roidSuffixContainsInvalidCharacters() { assertThrows( IllegalArgumentException.class, () -> Registry.get("tld").asBuilder().setRoidSuffix("ABC-DEF")); diff --git a/core/src/test/java/google/registry/model/registry/label/PremiumListUtilsTest.java b/core/src/test/java/google/registry/model/registry/label/PremiumListUtilsTest.java index b82ba313b..5336ce324 100644 --- a/core/src/test/java/google/registry/model/registry/label/PremiumListUtilsTest.java +++ b/core/src/test/java/google/registry/model/registry/label/PremiumListUtilsTest.java @@ -51,29 +51,26 @@ import google.registry.testing.AppEngineRule; import google.registry.testing.TestCacheRule; import java.util.Map; import org.joda.money.Money; -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; /** Unit tests for {@link PremiumListUtils}. */ -@RunWith(JUnit4.class) public class PremiumListUtilsTest { - @Rule + @RegisterExtension public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build(); // Set long persist times on caches so they can be tested (cache times default to 0 in tests). - @Rule + @RegisterExtension public final TestCacheRule testCacheRule = new TestCacheRule.Builder() .withPremiumListsCache(standardDays(1)) .withPremiumListEntriesCache(standardDays(1)) .build(); - @Before - public void before() { + @BeforeEach + void before() { // createTld() overwrites the premium list, so call it before persisting pl. createTld("tld"); PremiumList pl = @@ -101,7 +98,7 @@ public class PremiumListUtilsTest { } @Test - public void testGetPremiumPrice_returnsNoPriceWhenNoPremiumListConfigured() { + void testGetPremiumPrice_returnsNoPriceWhenNoPremiumListConfigured() { createTld("ghost"); persistResource( new Registry.Builder() @@ -116,7 +113,7 @@ public class PremiumListUtilsTest { } @Test - public void testGetPremiumPrice_throwsExceptionWhenNonExistentPremiumListConfigured() { + void testGetPremiumPrice_throwsExceptionWhenNonExistentPremiumListConfigured() { deletePremiumList(PremiumList.getUncached("tld").get()); IllegalStateException thrown = assertThrows( @@ -125,7 +122,7 @@ public class PremiumListUtilsTest { } @Test - public void testSave_largeNumberOfEntries_succeeds() { + void testSave_largeNumberOfEntries_succeeds() { PremiumList premiumList = persistHumongousPremiumList("tld", 2500); assertThat(loadPremiumListEntries(premiumList)).hasSize(2500); assertThat(getPremiumPrice("7", Registry.get("tld"))).hasValue(Money.parse("USD 100")); @@ -133,7 +130,7 @@ public class PremiumListUtilsTest { } @Test - public void testSave_updateTime_isUpdatedOnEverySave() { + void testSave_updateTime_isUpdatedOnEverySave() { PremiumList pl = savePremiumListAndEntries( new PremiumList.Builder().setName("tld3").build(), ImmutableList.of("slime,USD 10")); @@ -145,20 +142,20 @@ public class PremiumListUtilsTest { } @Test - public void testSave_creationTime_onlyUpdatedOnFirstCreation() { + void testSave_creationTime_onlyUpdatedOnFirstCreation() { PremiumList pl = persistPremiumList("tld3", "sludge,JPY 1000"); PremiumList newPl = savePremiumListAndEntries(pl, ImmutableList.of("sleighbells,CHF 2000")); assertThat(newPl.creationTime).isEqualTo(pl.creationTime); } @Test - public void testExists() { + void testExists() { assertThat(doesPremiumListExist("tld")).isTrue(); assertThat(doesPremiumListExist("nonExistentPremiumList")).isFalse(); } @Test - public void testGetPremiumPrice_comesFromBloomFilter() throws Exception { + void testGetPremiumPrice_comesFromBloomFilter() throws Exception { PremiumList pl = PremiumList.getCached("tld").get(); PremiumListEntry entry = persistResource( @@ -179,7 +176,7 @@ public class PremiumListUtilsTest { } @Test - public void testGetPremiumPrice_cachedSecondTime() { + void testGetPremiumPrice_cachedSecondTime() { assertThat(getPremiumPrice("rich", Registry.get("tld"))).hasValue(Money.parse("USD 1999")); assertThat(getPremiumPrice("rich", Registry.get("tld"))).hasValue(Money.parse("USD 1999")); assertThat(premiumListChecks) @@ -197,7 +194,7 @@ public class PremiumListUtilsTest { } @Test - public void testGetPremiumPrice_bloomFilterFalsePositive() { + void testGetPremiumPrice_bloomFilterFalsePositive() { // Remove one of the premium list entries from behind the Bloom filter's back. tm() .transactNew( @@ -229,7 +226,7 @@ public class PremiumListUtilsTest { } @Test - public void testSave_removedPremiumListEntries_areNoLongerInDatastore() { + void testSave_removedPremiumListEntries_areNoLongerInDatastore() { Registry registry = Registry.get("tld"); PremiumList pl = persistPremiumList("tld", "genius,USD 10", "dolt,JPY 1000"); assertThat(getPremiumPrice("genius", registry)).hasValue(Money.parse("USD 10")); @@ -262,14 +259,14 @@ public class PremiumListUtilsTest { } @Test - public void testGetPremiumPrice_allLabelsAreNonPremium_whenNotInList() { + void testGetPremiumPrice_allLabelsAreNonPremium_whenNotInList() { assertThat(getPremiumPrice("blah", Registry.get("tld"))).isEmpty(); assertThat(getPremiumPrice("slinge", Registry.get("tld"))).isEmpty(); assertMetricOutcomeCount(2, BLOOM_FILTER_NEGATIVE); } @Test - public void testSave_simple() { + void testSave_simple() { PremiumList pl = savePremiumListAndEntries( new PremiumList.Builder().setName("tld2").build(), @@ -301,7 +298,7 @@ public class PremiumListUtilsTest { } @Test - public void test_saveAndUpdateEntriesTwice() { + void test_saveAndUpdateEntriesTwice() { PremiumList pl = savePremiumListAndEntries( new PremiumList.Builder().setName("pl").build(), ImmutableList.of("test,USD 1")); @@ -319,7 +316,7 @@ public class PremiumListUtilsTest { } @Test - public void test_savePremiumListAndEntries_clearsCache() { + void test_savePremiumListAndEntries_clearsCache() { assertThat(PremiumList.cachePremiumLists.getIfPresent("tld")).isNull(); PremiumList pl = PremiumList.getCached("tld").get(); assertThat(PremiumList.cachePremiumLists.getIfPresent("tld")).isEqualTo(pl); @@ -329,7 +326,7 @@ public class PremiumListUtilsTest { } @Test - public void testDelete() { + void testDelete() { persistPremiumList("gtld1", "trombone,USD 10"); assertThat(PremiumList.getUncached("gtld1")).isPresent(); Key parent = PremiumList.getUncached("gtld1").get().getRevisionKey(); @@ -339,7 +336,7 @@ public class PremiumListUtilsTest { } @Test - public void testDelete_largeNumberOfEntries_succeeds() { + void testDelete_largeNumberOfEntries_succeeds() { persistHumongousPremiumList("ginormous", 2500); deletePremiumList(PremiumList.getUncached("ginormous").get()); assertThat(PremiumList.getUncached("ginormous")).isEmpty(); diff --git a/core/src/test/java/google/registry/model/reporting/HistoryEntryTest.java b/core/src/test/java/google/registry/model/reporting/HistoryEntryTest.java index fac55eff2..7d47bc49a 100644 --- a/core/src/test/java/google/registry/model/reporting/HistoryEntryTest.java +++ b/core/src/test/java/google/registry/model/reporting/HistoryEntryTest.java @@ -26,16 +26,16 @@ import google.registry.model.EntityTestCase; import google.registry.model.domain.Period; import google.registry.model.eppcommon.Trid; import google.registry.model.reporting.DomainTransactionRecord.TransactionReportField; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** Unit tests for {@link HistoryEntry}. */ -public class HistoryEntryTest extends EntityTestCase { +class HistoryEntryTest extends EntityTestCase { - HistoryEntry historyEntry; + private HistoryEntry historyEntry; - @Before - public void setUp() { + @BeforeEach + void setUp() { createTld("foobar"); DomainTransactionRecord transactionRecord = new DomainTransactionRecord.Builder() @@ -64,12 +64,12 @@ public class HistoryEntryTest extends EntityTestCase { } @Test - public void testPersistence() { + void testPersistence() { assertThat(ofy().load().entity(historyEntry).now()).isEqualTo(historyEntry); } @Test - public void testIndexing() throws Exception { + void testIndexing() throws Exception { verifyIndexing(historyEntry, "modificationTime", "clientId"); } } diff --git a/core/src/test/java/google/registry/model/reporting/Spec11ThreatMatchTest.java b/core/src/test/java/google/registry/model/reporting/Spec11ThreatMatchTest.java index 741c9b9d5..e9615b21d 100644 --- a/core/src/test/java/google/registry/model/reporting/Spec11ThreatMatchTest.java +++ b/core/src/test/java/google/registry/model/reporting/Spec11ThreatMatchTest.java @@ -46,12 +46,12 @@ public class Spec11ThreatMatchTest extends EntityTestCase { private HostResource host; private ContactResource registrantContact; - public Spec11ThreatMatchTest() { + Spec11ThreatMatchTest() { super(JpaEntityCoverageCheck.ENABLED); } @BeforeEach - public void setUp() { + void setUp() { VKey hostVKey = VKey.createSql(HostResource.class, "host"); VKey registrantContactVKey = VKey.createSql(ContactResource.class, "contact_id"); @@ -100,7 +100,7 @@ public class Spec11ThreatMatchTest extends EntityTestCase { } @Test - public void testPersistence() { + void testPersistence() { saveRegistrar(REGISTRAR_ID); jpaTm() @@ -119,7 +119,7 @@ public class Spec11ThreatMatchTest extends EntityTestCase { } @Test - public void testThreatForeignKeyConstraints() { + void testThreatForeignKeyConstraints() { assertThrowForeignKeyViolation( () -> { jpaTm() @@ -149,7 +149,7 @@ public class Spec11ThreatMatchTest extends EntityTestCase { } @Test - public void testFailure_threatsWithInvalidFields() { + void testFailure_threatsWithInvalidFields() { assertThrows( IllegalArgumentException.class, () -> threat.asBuilder().setRegistrarId(null).build()); diff --git a/core/src/test/java/google/registry/model/server/KmsSecretRevisionTest.java b/core/src/test/java/google/registry/model/server/KmsSecretRevisionTest.java index 7ca513980..b578c140f 100644 --- a/core/src/test/java/google/registry/model/server/KmsSecretRevisionTest.java +++ b/core/src/test/java/google/registry/model/server/KmsSecretRevisionTest.java @@ -21,22 +21,20 @@ import static org.junit.Assert.assertThrows; import com.google.common.base.Strings; import google.registry.testing.AppEngineRule; -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; -@RunWith(JUnit4.class) +/** Unit tests for {@link google.registry.model.server.KmsSecretRevision}. */ public class KmsSecretRevisionTest { - @Rule + @RegisterExtension public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build(); private KmsSecretRevision secretRevision; - @Before - public void setUp() { + @BeforeEach + void beforeEach() { secretRevision = persistResource( new KmsSecretRevision.Builder() @@ -47,7 +45,7 @@ public class KmsSecretRevisionTest { } @Test - public void test_setEncryptedValue_tooLong_throwsException() { + void test_setEncryptedValue_tooLong_throwsException() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, @@ -63,7 +61,7 @@ public class KmsSecretRevisionTest { } @Test - public void testPersistence() { + void testPersistence() { assertThat(ofy().load().entity(secretRevision).now()).isEqualTo(secretRevision); } } diff --git a/core/src/test/java/google/registry/model/server/KmsSecretTest.java b/core/src/test/java/google/registry/model/server/KmsSecretTest.java index 6004e2312..37208410b 100644 --- a/core/src/test/java/google/registry/model/server/KmsSecretTest.java +++ b/core/src/test/java/google/registry/model/server/KmsSecretTest.java @@ -19,23 +19,20 @@ import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.testing.DatastoreHelper.persistResource; import google.registry.testing.AppEngineRule; -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; -@RunWith(JUnit4.class) public class KmsSecretTest { - @Rule + @RegisterExtension public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build(); private KmsSecret secret; private KmsSecretRevision secretRevision; - @Before - public void setUp() { + @BeforeEach + void setUp() { secretRevision = persistResource( new KmsSecretRevision.Builder() @@ -48,7 +45,7 @@ public class KmsSecretTest { } @Test - public void testPersistence() { + void testPersistence() { assertThat(ofy().load().entity(secret).now()).isEqualTo(secret); } } diff --git a/core/src/test/java/google/registry/model/server/LockTest.java b/core/src/test/java/google/registry/model/server/LockTest.java index 922a30677..8ba75042f 100644 --- a/core/src/test/java/google/registry/model/server/LockTest.java +++ b/core/src/test/java/google/registry/model/server/LockTest.java @@ -34,15 +34,12 @@ import google.registry.testing.InjectRule; import google.registry.util.RequestStatusChecker; import java.util.Optional; import org.joda.time.Duration; -import org.junit.After; -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.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; /** Unit tests for {@link Lock}. */ -@RunWith(JUnit4.class) public class LockTest { private static final String RESOURCE_NAME = "foo"; @@ -53,11 +50,11 @@ public class LockTest { private LockMetrics origLockMetrics; - @Rule + @RegisterExtension public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().withClock(clock).build(); - @Rule public final InjectRule inject = new InjectRule(); + @RegisterExtension public final InjectRule inject = new InjectRule(); private Optional acquire(String tld, Duration leaseLength, LockState expectedLockState) { Lock.lockMetrics = mock(LockMetrics.class); @@ -77,7 +74,8 @@ public class LockTest { Lock.lockMetrics = null; } - @Before public void setUp() { + @BeforeEach + void beforeEach() { inject.setStaticField(Ofy.class, "clock", clock); origLockMetrics = Lock.lockMetrics; Lock.lockMetrics = null; @@ -85,13 +83,13 @@ public class LockTest { when(requestStatusChecker.isRunning("current-request-id")).thenReturn(true); } - @After - public void restoreLockMetric() { + @AfterEach + void restoreLockMetric() { Lock.lockMetrics = origLockMetrics; } @Test - public void testReleasedExplicitly() { + void testReleasedExplicitly() { Optional lock = acquire("", ONE_DAY, FREE); assertThat(lock).isPresent(); // We can't get it again at the same time. @@ -103,7 +101,7 @@ public class LockTest { } @Test - public void testReleasedAfterTimeout() { + void testReleasedAfterTimeout() { assertThat(acquire("", TWO_MILLIS, FREE)).isPresent(); // We can't get it again at the same time. assertThat(acquire("", TWO_MILLIS, IN_USE)).isEmpty(); @@ -116,7 +114,7 @@ public class LockTest { } @Test - public void testReleasedAfterRequestFinish() { + void testReleasedAfterRequestFinish() { assertThat(acquire("", ONE_DAY, FREE)).isPresent(); // We can't get it again while request is active assertThat(acquire("", ONE_DAY, IN_USE)).isEmpty(); @@ -126,7 +124,7 @@ public class LockTest { } @Test - public void testTldsAreIndependent() { + void testTldsAreIndependent() { Optional lockA = acquire("a", ONE_DAY, FREE); assertThat(lockA).isPresent(); // For a different tld we can still get a lock with the same name. @@ -141,7 +139,7 @@ public class LockTest { } @Test - public void testFailure_emptyResourceName() { + void testFailure_emptyResourceName() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, diff --git a/core/src/test/java/google/registry/model/server/ServerSecretTest.java b/core/src/test/java/google/registry/model/server/ServerSecretTest.java index 073ad6c34..a052729a9 100644 --- a/core/src/test/java/google/registry/model/server/ServerSecretTest.java +++ b/core/src/test/java/google/registry/model/server/ServerSecretTest.java @@ -20,32 +20,30 @@ import static google.registry.model.ofy.ObjectifyService.ofy; import google.registry.model.ofy.RequestCapturingAsyncDatastoreService; import google.registry.testing.AppEngineRule; import java.util.UUID; -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; /** Unit tests for {@link ServerSecret}. */ -@RunWith(JUnit4.class) public class ServerSecretTest { - @Rule + + @RegisterExtension public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build(); - @Before - public void before() { + @BeforeEach + void beforeEach() { ServerSecret.resetCache(); } @Test - public void testGet_bootstrapping_savesSecretToDatastore() { + void testGet_bootstrapping_savesSecretToDatastore() { ServerSecret secret = ServerSecret.get(); assertThat(secret).isNotNull(); assertThat(ofy().load().entity(new ServerSecret()).now()).isEqualTo(secret); } @Test - public void testGet_existingSecret_returned() { + void testGet_existingSecret_returned() { ServerSecret secret = ServerSecret.create(123, 456); ofy().saveWithoutBackup().entity(secret).now(); assertThat(ServerSecret.get()).isEqualTo(secret); @@ -53,7 +51,7 @@ public class ServerSecretTest { } @Test - public void testGet_cachedSecret_returnedWithoutDatastoreRead() { + void testGet_cachedSecret_returnedWithoutDatastoreRead() { int numInitialReads = RequestCapturingAsyncDatastoreService.getReads().size(); ServerSecret secret = ServerSecret.get(); int numReads = RequestCapturingAsyncDatastoreService.getReads().size(); @@ -63,14 +61,14 @@ public class ServerSecretTest { } @Test - public void testAsUuid() { + void testAsUuid() { UUID uuid = ServerSecret.create(123, 456).asUuid(); assertThat(uuid.getMostSignificantBits()).isEqualTo(123); assertThat(uuid.getLeastSignificantBits()).isEqualTo(456); } @Test - public void testAsBytes() { + void testAsBytes() { byte[] bytes = ServerSecret.create(123, 0x456).asBytes(); assertThat(bytes) .isEqualTo(new byte[] {0, 0, 0, 0, 0, 0, 0, 123, 0, 0, 0, 0, 0, 0, 0x4, 0x56}); diff --git a/core/src/test/java/google/registry/model/smd/IssuerInfoTest.java b/core/src/test/java/google/registry/model/smd/IssuerInfoTest.java index 7760f0588..245891f37 100644 --- a/core/src/test/java/google/registry/model/smd/IssuerInfoTest.java +++ b/core/src/test/java/google/registry/model/smd/IssuerInfoTest.java @@ -16,16 +16,13 @@ package google.registry.model.smd; import static com.google.common.truth.Truth.assertThat; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.Test; /** Unit tests for {@link IssuerInfo}. */ -@RunWith(JUnit4.class) -public final class IssuerInfoTest { +final class IssuerInfoTest { @Test - public void testDeadCodeWeDontWantToDelete() { + void testDeadCodeWeDontWantToDelete() { IssuerInfo mp = new IssuerInfo(); mp.issuerId = "sloth"; assertThat(mp.getIssuerId()).isEqualTo("sloth"); diff --git a/core/src/test/java/google/registry/model/smd/SignedMarkRevocationListTest.java b/core/src/test/java/google/registry/model/smd/SignedMarkRevocationListTest.java index d168b8fef..a9a0134c6 100644 --- a/core/src/test/java/google/registry/model/smd/SignedMarkRevocationListTest.java +++ b/core/src/test/java/google/registry/model/smd/SignedMarkRevocationListTest.java @@ -26,22 +26,19 @@ import com.google.common.collect.ImmutableMap; import google.registry.testing.AppEngineRule; import google.registry.testing.FakeClock; 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 SignedMarkRevocationList}. */ -@RunWith(JUnit4.class) public class SignedMarkRevocationListTest { - @Rule + @RegisterExtension public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build(); private final FakeClock clock = new FakeClock(DateTime.parse("2013-01-01T00:00:00Z")); @Test - public void testUnshardedSaveFails() { + void testUnshardedSaveFails() { // Our @Entity's @OnSave method will notice that this shouldn't be saved. assertThrows( SignedMarkRevocationList.UnshardedSaveException.class, @@ -59,14 +56,14 @@ public class SignedMarkRevocationListTest { } @Test - public void testEmpty() { + void testEmpty() { // When Datastore is empty, it should give us an empty thing. assertThat(SignedMarkRevocationList.get()) .isEqualTo(SignedMarkRevocationList.create(START_OF_TIME, ImmutableMap.of())); } @Test - public void testSharding2() { + void testSharding2() { final int rows = SHARD_SIZE + 1; // Create a SignedMarkRevocationList that will need 2 shards to save. ImmutableMap.Builder revokes = new ImmutableMap.Builder<>(); @@ -82,7 +79,7 @@ public class SignedMarkRevocationListTest { } @Test - public void testSharding4() { + void testSharding4() { final int rows = SHARD_SIZE * 3 + 1; // Create a SignedMarkRevocationList that will need 4 shards to save. ImmutableMap.Builder revokes = new ImmutableMap.Builder<>(); @@ -109,7 +106,7 @@ public class SignedMarkRevocationListTest { } @Test - public void test_isSmdRevoked_null() { + void test_isSmdRevoked_null() { assertThrows( NullPointerException.class, () -> @@ -118,7 +115,7 @@ public class SignedMarkRevocationListTest { } @Test - public void test_isSmdRevoked_garbage() { + void test_isSmdRevoked_garbage() { SignedMarkRevocationList smdrl = createSaveGetHelper(SHARD_SIZE + 1); assertThat(smdrl.getCreationTime()).isEqualTo(clock.nowUtc()); assertThat(smdrl.isSmdRevoked("rofl", clock.nowUtc())).isFalse(); @@ -126,7 +123,7 @@ public class SignedMarkRevocationListTest { } @Test - public void test_getCreationTime() { + void test_getCreationTime() { clock.setTo(DateTime.parse("2000-01-01T00:00:00Z")); createSaveGetHelper(5); assertThat(SignedMarkRevocationList.get().getCreationTime()) @@ -137,7 +134,7 @@ public class SignedMarkRevocationListTest { } @Test - public void test_isSmdRevoked_present() { + void test_isSmdRevoked_present() { final int rows = SHARD_SIZE + 1; SignedMarkRevocationList smdrl = createSaveGetHelper(rows); assertThat(smdrl.isSmdRevoked("0", clock.nowUtc())).isTrue(); @@ -146,7 +143,7 @@ public class SignedMarkRevocationListTest { } @Test - public void test_isSmdRevoked_future() { + void test_isSmdRevoked_future() { final int rows = SHARD_SIZE; SignedMarkRevocationList smdrl = createSaveGetHelper(rows); clock.advanceOneMilli(); @@ -156,7 +153,7 @@ public class SignedMarkRevocationListTest { } @Test - public void test_isSmdRevoked_past() { + void test_isSmdRevoked_past() { final int rows = SHARD_SIZE; SignedMarkRevocationList smdrl = createSaveGetHelper(rows); clock.setTo(clock.nowUtc().minusMillis(1)); diff --git a/core/src/test/java/google/registry/model/tmch/ClaimsListShardTest.java b/core/src/test/java/google/registry/model/tmch/ClaimsListShardTest.java index c54e736b5..3079b8879 100644 --- a/core/src/test/java/google/registry/model/tmch/ClaimsListShardTest.java +++ b/core/src/test/java/google/registry/model/tmch/ClaimsListShardTest.java @@ -31,22 +31,19 @@ import java.util.HashMap; import java.util.List; import java.util.Map; 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 ClaimsListShard}. */ -@RunWith(JUnit4.class) public class ClaimsListShardTest { - @Rule + @RegisterExtension public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build(); private final int shardSize = 10; @Test - public void test_unshardedSaveFails() { + void test_unshardedSaveFails() { assertThrows( UnshardedSaveException.class, () -> @@ -63,13 +60,13 @@ public class ClaimsListShardTest { } @Test - public void testGet_safelyLoadsEmptyClaimsList_whenNoShardsExist() { + void testGet_safelyLoadsEmptyClaimsList_whenNoShardsExist() { assertThat(ClaimsListShard.get().labelsToKeys).isEmpty(); assertThat(ClaimsListShard.get().creationTime).isEqualTo(START_OF_TIME); } @Test - public void test_savesAndGets_withSharding() { + void test_savesAndGets_withSharding() { // Create a ClaimsList that will need 4 shards to save. Map labelsToKeys = new HashMap<>(); for (int i = 0; i <= shardSize * 3; i++) { diff --git a/core/src/test/java/google/registry/model/tmch/TmchCrlTest.java b/core/src/test/java/google/registry/model/tmch/TmchCrlTest.java index badb94ded..6ea28c71e 100644 --- a/core/src/test/java/google/registry/model/tmch/TmchCrlTest.java +++ b/core/src/test/java/google/registry/model/tmch/TmchCrlTest.java @@ -17,20 +17,17 @@ package google.registry.model.tmch; import static com.google.common.truth.Truth.assertThat; import google.registry.testing.AppEngineRule; -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 TmchCrl}. */ -@RunWith(JUnit4.class) public class TmchCrlTest { - @Rule + @RegisterExtension public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build(); @Test - public void testSuccess() { + void testSuccess() { assertThat(TmchCrl.get()).isNull(); TmchCrl.set("lolcat", "http://lol.cat"); assertThat(TmchCrl.get().getCrl()).isEqualTo("lolcat"); diff --git a/core/src/test/java/google/registry/model/transfer/TransferDataTest.java b/core/src/test/java/google/registry/model/transfer/TransferDataTest.java index e3d7a83f0..6c58cb3e4 100644 --- a/core/src/test/java/google/registry/model/transfer/TransferDataTest.java +++ b/core/src/test/java/google/registry/model/transfer/TransferDataTest.java @@ -25,17 +25,14 @@ import google.registry.model.poll.PollMessage; import google.registry.persistence.VKey; import google.registry.testing.AppEngineRule; 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; /** Unit tests for {@link TransferData}. */ -@RunWith(JUnit4.class) public class TransferDataTest { - @Rule + @RegisterExtension public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build(); private final DateTime now = DateTime.now(UTC); @@ -46,8 +43,8 @@ public class TransferDataTest { private VKey autorenewPollMessageKey; private VKey otherServerApprovePollMessageKey; - @Before - public void setUp() { + @BeforeEach + void beforeEach() { transferBillingEventKey = VKey.create(BillingEvent.OneTime.class, 12345); otherServerApproveBillingEventKey = VKey.create(BillingEvent.Cancellation.class, 2468); recurringBillingEventKey = VKey.create(BillingEvent.Recurring.class, 13579); @@ -56,7 +53,7 @@ public class TransferDataTest { } @Test - public void test_copyConstantFieldsToBuilder() { + void test_copyConstantFieldsToBuilder() { DomainTransferData constantTransferData = new DomainTransferData.Builder() .setTransferRequestTrid(Trid.create("server-trid", "client-trid")) diff --git a/core/src/test/java/google/registry/model/translators/CommitLogRevisionsTranslatorFactoryTest.java b/core/src/test/java/google/registry/model/translators/CommitLogRevisionsTranslatorFactoryTest.java index de0e5ba57..bd926eacb 100644 --- a/core/src/test/java/google/registry/model/translators/CommitLogRevisionsTranslatorFactoryTest.java +++ b/core/src/test/java/google/registry/model/translators/CommitLogRevisionsTranslatorFactoryTest.java @@ -32,14 +32,11 @@ import google.registry.testing.FakeClock; import google.registry.testing.InjectRule; import java.util.List; 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; /** Unit tests for {@link CommitLogRevisionsTranslatorFactory}. */ -@RunWith(JUnit4.class) public class CommitLogRevisionsTranslatorFactoryTest { private static final DateTime START_TIME = DateTime.parse("2000-01-01TZ"); @@ -49,20 +46,19 @@ public class CommitLogRevisionsTranslatorFactoryTest { ImmutableSortedMap> revisions = ImmutableSortedMap.of(); } - @Rule + @RegisterExtension public final AppEngineRule appEngine = AppEngineRule.builder() .withDatastoreAndCloudSql() .withOfyTestEntities(TestObject.class) .build(); - @Rule - public final InjectRule inject = new InjectRule(); + @RegisterExtension public final InjectRule inject = new InjectRule(); private final FakeClock clock = new FakeClock(START_TIME); - @Before - public void before() { + @BeforeEach + void beforeEach() { inject.setStaticField(Ofy.class, "clock", clock); } @@ -76,7 +72,7 @@ public class CommitLogRevisionsTranslatorFactoryTest { } @Test - public void testSave_doesNotMutateOriginalResource() { + void testSave_doesNotMutateOriginalResource() { TestObject object = new TestObject(); save(object); assertThat(object.revisions).isEmpty(); @@ -84,7 +80,7 @@ public class CommitLogRevisionsTranslatorFactoryTest { } @Test - public void testSave_translatorAddsKeyToCommitLogToField() { + void testSave_translatorAddsKeyToCommitLogToField() { save(new TestObject()); TestObject object = reload(); assertThat(object.revisions).hasSize(1); @@ -94,7 +90,7 @@ public class CommitLogRevisionsTranslatorFactoryTest { } @Test - public void testSave_twoVersionsOnOneDay_keyToLastCommitLogsGetsStored() { + void testSave_twoVersionsOnOneDay_keyToLastCommitLogsGetsStored() { save(new TestObject()); clock.advanceBy(standardHours(1)); save(reload()); @@ -104,7 +100,7 @@ public class CommitLogRevisionsTranslatorFactoryTest { } @Test - public void testSave_twoVersionsOnTwoDays_keyToBothCommitLogsGetsStored() { + void testSave_twoVersionsOnTwoDays_keyToBothCommitLogsGetsStored() { save(new TestObject()); clock.advanceBy(standardDays(1)); save(reload()); @@ -115,7 +111,7 @@ public class CommitLogRevisionsTranslatorFactoryTest { } @Test - public void testSave_moreThanThirtyDays_truncatedAtThirtyPlusOne() { + void testSave_moreThanThirtyDays_truncatedAtThirtyPlusOne() { save(new TestObject()); for (int i = 0; i < 35; i++) { clock.advanceBy(standardDays(1)); @@ -127,7 +123,7 @@ public class CommitLogRevisionsTranslatorFactoryTest { } @Test - public void testSave_moreThanThirtySparse_keepsOneEntryPrecedingThirtyDays() { + void testSave_moreThanThirtySparse_keepsOneEntryPrecedingThirtyDays() { save(new TestObject()); assertThat(reload().revisions).hasSize(1); assertThat(reload().revisions.firstKey()).isEqualTo(clock.nowUtc().minusDays(0)); @@ -147,7 +143,7 @@ public class CommitLogRevisionsTranslatorFactoryTest { @Test @SuppressWarnings("unchecked") - public void testRawEntityLayout() { + void testRawEntityLayout() { save(new TestObject()); clock.advanceBy(standardDays(1)); com.google.appengine.api.datastore.Entity entity = @@ -161,12 +157,12 @@ public class CommitLogRevisionsTranslatorFactoryTest { } @Test - public void testLoad_neverSaved_returnsNull() { + void testLoad_neverSaved_returnsNull() { assertThat(ofy().load().entity(new TestObject()).now()).isNull(); } @Test - public void testLoad_missingRevisionRawProperties_createsEmptyObject() { + void testLoad_missingRevisionRawProperties_createsEmptyObject() { com.google.appengine.api.datastore.Entity entity = tm().transactNewReadOnly(() -> ofy().save().toEntity(new TestObject())); entity.removeProperty("revisions.key"); diff --git a/core/src/test/java/google/registry/model/translators/StatusValueAdapterTest.java b/core/src/test/java/google/registry/model/translators/StatusValueAdapterTest.java index 8257387fe..33526aed5 100644 --- a/core/src/test/java/google/registry/model/translators/StatusValueAdapterTest.java +++ b/core/src/test/java/google/registry/model/translators/StatusValueAdapterTest.java @@ -31,20 +31,17 @@ import google.registry.model.host.HostInfoData; import google.registry.testing.AppEngineRule; import google.registry.testing.EppLoader; import google.registry.xml.ValidationMode; -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; -@RunWith(JUnit4.class) public class StatusValueAdapterTest { // Needed to create HostResources. - @Rule + @RegisterExtension public AppEngineRule appEngine = new AppEngineRule.Builder().withDatastoreAndCloudSql().build(); @Test - public void testMarshalling() throws Exception { + void testMarshalling() throws Exception { // Mangle the status value through marshalling by stuffing it in a host info response and then // ripping it out of the marshalled xml. Use lenient marshalling so we can omit other fields. String marshalled = new String( @@ -77,19 +74,19 @@ public class StatusValueAdapterTest { } @Test - public void testNoOptionalFields_unmarshallsWithoutException() throws Exception { + void testNoOptionalFields_unmarshallsWithoutException() throws Exception { assertThat(unmarshal("")) .isEqualTo(StatusValue.CLIENT_UPDATE_PROHIBITED); } @Test - public void testHasLang_unmarshallsWithoutException() throws Exception { + void testHasLang_unmarshallsWithoutException() throws Exception { assertThat(unmarshal("")) .isEqualTo(StatusValue.CLIENT_UPDATE_PROHIBITED); } @Test - public void testHasMessage_unmarshallsWithoutException() throws Exception { + void testHasMessage_unmarshallsWithoutException() throws Exception { assertThat(unmarshal("my message")) .isEqualTo(StatusValue.CLIENT_UPDATE_PROHIBITED); } diff --git a/core/src/test/java/google/registry/model/translators/VKeyTranslatorFactoryTest.java b/core/src/test/java/google/registry/model/translators/VKeyTranslatorFactoryTest.java index 7ab68c9b7..79e08084e 100644 --- a/core/src/test/java/google/registry/model/translators/VKeyTranslatorFactoryTest.java +++ b/core/src/test/java/google/registry/model/translators/VKeyTranslatorFactoryTest.java @@ -34,7 +34,7 @@ public class VKeyTranslatorFactoryTest { @RegisterExtension public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build(); - public VKeyTranslatorFactoryTest() {} + VKeyTranslatorFactoryTest() {} @Test void testEntityWithFlatKey() { diff --git a/core/src/test/java/google/registry/testing/TestCacheRule.java b/core/src/test/java/google/registry/testing/TestCacheRule.java index a809b8d99..8af277c62 100644 --- a/core/src/test/java/google/registry/testing/TestCacheRule.java +++ b/core/src/test/java/google/registry/testing/TestCacheRule.java @@ -22,7 +22,9 @@ import google.registry.model.registry.label.PremiumList; import java.util.Map; import java.util.Optional; import org.joda.time.Duration; -import org.junit.rules.ExternalResource; +import org.junit.jupiter.api.extension.AfterEachCallback; +import org.junit.jupiter.api.extension.BeforeEachCallback; +import org.junit.jupiter.api.extension.ExtensionContext; /** * Sets up caches with desired data expiry for testing and restores their default configurations @@ -31,7 +33,7 @@ import org.junit.rules.ExternalResource; *

This rule is necessary because many caches in the system are singleton and referenced through * static fields. */ -public class TestCacheRule extends ExternalResource { +public class TestCacheRule implements BeforeEachCallback, AfterEachCallback { private final ImmutableList cacheHandlers; @@ -40,12 +42,12 @@ public class TestCacheRule extends ExternalResource { } @Override - protected void before() { + public void beforeEach(ExtensionContext context) { cacheHandlers.forEach(TestCacheHandler::before); } @Override - protected void after() { + public void afterEach(ExtensionContext context) { cacheHandlers.forEach(TestCacheHandler::after); } diff --git a/core/src/test/java/google/registry/whois/WhoisActionTest.java b/core/src/test/java/google/registry/whois/WhoisActionTest.java index 690011523..9caa739ab 100644 --- a/core/src/test/java/google/registry/whois/WhoisActionTest.java +++ b/core/src/test/java/google/registry/whois/WhoisActionTest.java @@ -66,23 +66,20 @@ import java.io.Reader; import java.io.StringReader; import org.joda.time.DateTime; import org.joda.time.Duration; -import org.junit.Before; -import org.junit.Ignore; -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.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; /** Unit tests for {@link WhoisAction}. */ -@RunWith(JUnit4.class) public class WhoisActionTest { - @Rule + @RegisterExtension public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build(); - @Rule public final InjectRule inject = new InjectRule(); + @RegisterExtension public final InjectRule inject = new InjectRule(); - @Rule + @RegisterExtension public final TestCacheRule testCacheRule = new TestCacheRule.Builder() .withEppResourceCache(Duration.standardDays(1)) @@ -107,15 +104,15 @@ public class WhoisActionTest { return whoisAction; } - @Before - public void setUp() { + @BeforeEach + void setUp() { clock = new FakeClock(DateTime.parse("2009-06-29T20:13:00Z")); createTlds("lol", "xn--q9jyb4c", "1.test"); inject.setStaticField(Ofy.class, "clock", clock); } @Test - public void testRun_badRequest_stillSends200() { + void testRun_badRequest_stillSends200() { newWhoisAction("\r\n").run(); assertThat(response.getStatus()).isEqualTo(200); assertThat(response.getPayload()).isEqualTo(loadFile("whois_action_no_command.txt")); @@ -133,7 +130,7 @@ public class WhoisActionTest { } @Test - public void testRun_domainQuery_works() { + void testRun_domainQuery_works() { Registrar registrar = persistResource(makeRegistrar("evilregistrar", "Yes Virginia", ACTIVE)); persistResource(makeDomainBaseWithRegistrar(registrar)); @@ -144,7 +141,7 @@ public class WhoisActionTest { } @Test - public void testRun_domainQuery_usesCache() { + void testRun_domainQuery_usesCache() { Registrar registrar = persistResource(makeRegistrar("evilregistrar", "Yes Virginia", ACTIVE)); persistResource(makeDomainBaseWithRegistrar(registrar)); @@ -172,7 +169,7 @@ public class WhoisActionTest { } @Test - public void testRun_domainAfterTransfer_hasUpdatedEppTimeAndClientId() { + void testRun_domainAfterTransfer_hasUpdatedEppTimeAndClientId() { Registrar registrar = persistResource(makeRegistrar("TheRegistrar", "Yes Virginia", ACTIVE)); persistResource( makeDomainBaseWithRegistrar(registrar) @@ -197,7 +194,7 @@ public class WhoisActionTest { } @Test - public void testRun_idnDomain_works() { + void testRun_idnDomain_works() { Registrar registrar = persistResource(makeRegistrar( "evilregistrar", "Yes Virginia", ACTIVE)); persistResource(makeDomainBase( @@ -215,7 +212,7 @@ public class WhoisActionTest { } @Test - public void testRun_punycodeDomain_works() { + void testRun_punycodeDomain_works() { Registrar registrar = persistResource(makeRegistrar( "evilregistrar", "Yes Virginia", ACTIVE)); persistResource(makeDomainBase( @@ -233,14 +230,14 @@ public class WhoisActionTest { } @Test - public void testRun_domainNotFound_returns200OkAndPlainTextResponse() { + void testRun_domainNotFound_returns200OkAndPlainTextResponse() { newWhoisAction("domain cat.lol\r\n").run(); assertThat(response.getStatus()).isEqualTo(200); assertThat(response.getPayload()).isEqualTo(loadFile("whois_action_domain_not_found.txt")); } @Test - public void testRun_domainNotFound_usesCache() { + void testRun_domainNotFound_usesCache() { // Populate the cache with the nonexistence of this domain. assertThat(loadByForeignKeyCached(DomainBase.class, "cat.lol", clock.nowUtc())).isEmpty(); // Add a new valid cat.lol domain that won't be found because the cache will be hit instead. @@ -251,9 +248,9 @@ public class WhoisActionTest { } // todo (b/27378695): reenable or delete this test - @Ignore + @Disabled @Test - public void testRun_domainInTestTld_isConsideredNotFound() { + void testRun_domainInTestTld_isConsideredNotFound() { persistResource(Registry.get("lol").asBuilder().setTldType(Registry.TldType.TEST).build()); Registrar registrar = persistResource(makeRegistrar( "evilregistrar", "Yes Virginia", ACTIVE)); @@ -272,7 +269,7 @@ public class WhoisActionTest { } @Test - public void testRun_domainFlaggedAsDeletedInDatastore_isConsideredNotFound() { + void testRun_domainFlaggedAsDeletedInDatastore_isConsideredNotFound() { Registrar registrar; persistResource(makeDomainBase("cat.lol", persistResource( @@ -293,11 +290,11 @@ public class WhoisActionTest { } /** - * Create a deleted domain and an active domain with the same label, and make sure only the - * active one is returned. + * Create a deleted domain and an active domain with the same label, and make sure only the active + * one is returned. */ @Test - public void testRun_domainDeletedThenRecreated_isFound() { + void testRun_domainDeletedThenRecreated_isFound() { Registrar registrar; DomainBase domain1 = persistResource(makeDomainBase("cat.lol", persistResource( @@ -333,7 +330,7 @@ public class WhoisActionTest { } @Test - public void testRun_nameserverQuery_works() { + void testRun_nameserverQuery_works() { persistResource(loadRegistrar("TheRegistrar").asBuilder().setUrl("http://my.fake.url").build()); persistResource(makeHostResource("ns1.cat.lol", "1.2.3.4")); newWhoisAction("nameserver ns1.cat.lol\r\n").run(); @@ -342,7 +339,7 @@ public class WhoisActionTest { } @Test - public void testRun_ipv6_displaysInCollapsedReadableFormat() { + void testRun_ipv6_displaysInCollapsedReadableFormat() { persistResource(makeHostResource("ns1.cat.lol", "bad:f00d:cafe::15:beef")); newWhoisAction("nameserver ns1.cat.lol\r\n").run(); assertThat(response.getStatus()).isEqualTo(200); @@ -353,7 +350,7 @@ public class WhoisActionTest { } @Test - public void testRun_idnNameserver_works() { + void testRun_idnNameserver_works() { persistResource(makeHostResource("ns1.cat.みんな", "1.2.3.4")); newWhoisAction("nameserver ns1.cat.みんな\r\n").run(); assertThat(response.getStatus()).isEqualTo(200); @@ -362,7 +359,7 @@ public class WhoisActionTest { } @Test - public void testRun_nameserver_usesCache() { + void testRun_nameserver_usesCache() { persistResource(makeHostResource("ns1.cat.xn--q9jyb4c", "1.2.3.4")); // Populate the cache. HostResource host = @@ -379,7 +376,7 @@ public class WhoisActionTest { } @Test - public void testRun_punycodeNameserver_works() { + void testRun_punycodeNameserver_works() { persistResource(makeHostResource("ns1.cat.みんな", "1.2.3.4")); newWhoisAction("nameserver ns1.cat.xn--q9jyb4c\r\n").run(); assertThat(response.getStatus()).isEqualTo(200); @@ -388,7 +385,7 @@ public class WhoisActionTest { } @Test - public void testRun_nameserverNotFound_returns200AndText() { + void testRun_nameserverNotFound_returns200AndText() { persistResource(makeHostResource("ns1.cat.lol", "1.2.3.4")); newWhoisAction("nameserver ns1.cat.lulz\r\n").run(); assertThat(response.getStatus()).isEqualTo(200); @@ -396,7 +393,7 @@ public class WhoisActionTest { } @Test - public void testRun_nameserverFlaggedAsDeletedInDatastore_doesntGetLeaked() { + void testRun_nameserverFlaggedAsDeletedInDatastore_doesntGetLeaked() { persistResource( makeHostResource("ns1.cat.lol", "1.2.3.4").asBuilder() .setDeletionTime(clock.nowUtc().minusDays(1)).build()); @@ -406,7 +403,7 @@ public class WhoisActionTest { } @Test - public void testRun_ipNameserverLookup_works() { + void testRun_ipNameserverLookup_works() { persistResource(makeHostResource("ns1.cat.lol", "1.2.3.4")); newWhoisAction("nameserver 1.2.3.4").run(); assertThat(response.getStatus()).isEqualTo(200); @@ -414,7 +411,7 @@ public class WhoisActionTest { } @Test - public void testRun_ipMapsToMultipleNameservers_theyAllGetReturned() { + void testRun_ipMapsToMultipleNameservers_theyAllGetReturned() { persistResource(makeHostResource("ns1.cat.lol", "1.2.3.4")); persistResource(makeHostResource("ns2.cat.lol", "1.2.3.4")); newWhoisAction("nameserver 1.2.3.4").run(); @@ -424,7 +421,7 @@ public class WhoisActionTest { } @Test - public void testRun_ipMapsToMultipleNameserverInDifferentTlds_showsThemAll() { + void testRun_ipMapsToMultipleNameserverInDifferentTlds_showsThemAll() { persistResource(makeHostResource("ns1.cat.lol", "1.2.3.4")); persistResource( makeHostResource("ns1.cat.xn--q9jyb4c", "1.2.3.4")); @@ -435,14 +432,14 @@ public class WhoisActionTest { } @Test - public void testRun_ipNameserverEntityDoesNotExist_returns200NotFound() { + void testRun_ipNameserverEntityDoesNotExist_returns200NotFound() { newWhoisAction("nameserver feed:a:bee::acab\r\n").run(); assertThat(response.getStatus()).isEqualTo(200); assertThat(response.getPayload()).isEqualTo(loadFile("whois_action_ip_not_found.txt")); } @Test - public void testRun_ipMapsToNameserverUnderNonAuthoritativeTld_notFound() { + void testRun_ipMapsToNameserverUnderNonAuthoritativeTld_notFound() { assertThat(getTlds()).doesNotContain("com"); persistResource(makeHostResource("ns1.google.com", "1.2.3.4")); newWhoisAction("nameserver 1.2.3.4").run(); @@ -451,7 +448,7 @@ public class WhoisActionTest { } @Test - public void testRun_nameserverUnderNonAuthoritativeTld_notFound() { + void testRun_nameserverUnderNonAuthoritativeTld_notFound() { assertThat(getTlds()).doesNotContain("com"); persistResource(makeHostResource("ns1.google.com", "1.2.3.4")); newWhoisAction("nameserver ns1.google.com").run(); @@ -460,9 +457,9 @@ public class WhoisActionTest { } // todo (b/27378695): reenable or delete this test - @Ignore + @Disabled @Test - public void testRun_nameserverInTestTld_notFound() { + void testRun_nameserverInTestTld_notFound() { persistResource(Registry.get("lol").asBuilder().setTldType(Registry.TldType.TEST).build()); persistResource(makeHostResource("ns1.cat.lol", "1.2.3.4")); newWhoisAction("nameserver ns1.cat.lol").run(); @@ -471,7 +468,7 @@ public class WhoisActionTest { } @Test - public void testRun_registrarLookup_works() { + void testRun_registrarLookup_works() { Registrar registrar = persistResource( makeRegistrar("example", "Example Registrar, Inc.", ACTIVE)); persistSimpleResources(makeRegistrarContacts(registrar)); @@ -482,7 +479,7 @@ public class WhoisActionTest { } @Test - public void testRun_pdtRegistrarLookup_works() { + void testRun_pdtRegistrarLookup_works() { Registrar registrar = persistResource( makeRegistrar("example", "Example Registrar, Inc.", ACTIVE) @@ -498,7 +495,7 @@ public class WhoisActionTest { } @Test - public void testRun_registrarLookupInPendingState_returnsNotFound() { + void testRun_registrarLookupInPendingState_returnsNotFound() { Registrar registrar = persistResource( makeRegistrar("example", "Example Registrar, Inc.", Registrar.State.PENDING)); persistSimpleResources(makeRegistrarContacts(registrar)); @@ -508,7 +505,7 @@ public class WhoisActionTest { } @Test - public void testRun_registrarLookupWithTestType_returnsNotFound() { + void testRun_registrarLookupWithTestType_returnsNotFound() { Registrar registrar = persistResource( makeRegistrar("example", "Example Registrar, Inc.", ACTIVE) .asBuilder() @@ -522,7 +519,7 @@ public class WhoisActionTest { } @Test - public void testRun_multilevelDomain_isNotConsideredAHostname() { + void testRun_multilevelDomain_isNotConsideredAHostname() { Registrar registrar = persistResource(makeRegistrar("example", "Example Registrar", ACTIVE)); persistResource(makeDomainBase("cat.1.test", @@ -540,7 +537,7 @@ public class WhoisActionTest { } @Test - public void testRun_hostnameWithMultilevelTld_isStillConsideredHostname() { + void testRun_hostnameWithMultilevelTld_isStillConsideredHostname() { persistResource(makeHostResource("ns1.cat.1.test", "1.2.3.4")); newWhoisAction("nameserver ns1.cat.1.test\r\n").run(); assertThat(response.getStatus()).isEqualTo(200); @@ -549,7 +546,7 @@ public class WhoisActionTest { } @Test - public void testRun_metricsLoggedForSuccessfulCommand() { + void testRun_metricsLoggedForSuccessfulCommand() { persistResource(makeHostResource("ns1.cat.lol", "1.2.3.4")); persistResource(makeHostResource("ns2.cat.lol", "1.2.3.4")); WhoisAction action = newWhoisAction("nameserver 1.2.3.4"); @@ -565,7 +562,7 @@ public class WhoisActionTest { } @Test - public void testRun_metricsLoggedForUnsuccessfulCommand() { + void testRun_metricsLoggedForUnsuccessfulCommand() { WhoisAction action = newWhoisAction("domain cat.lol\r\n"); action.whoisMetrics = mock(WhoisMetrics.class); action.run(); @@ -579,7 +576,7 @@ public class WhoisActionTest { } @Test - public void testRun_metricsLoggedForInternalServerError() throws Exception { + void testRun_metricsLoggedForInternalServerError() throws Exception { persistResource(makeHostResource("ns1.cat.lol", "1.2.3.4")); WhoisAction action = newWhoisAction("ns1.cat.lol"); action.whoisReader = mock(WhoisReader.class); @@ -598,7 +595,7 @@ public class WhoisActionTest { } @Test - public void testRun_retryOnTransientFailure() throws Exception { + void testRun_retryOnTransientFailure() throws Exception { persistResource(loadRegistrar("TheRegistrar").asBuilder().setUrl("http://my.fake.url").build()); persistResource(makeHostResource("ns1.cat.lol", "1.2.3.4")); WhoisAction action = newWhoisAction("ns1.cat.lol");