Allow backwards compatibility with JUnit 4 @Rules in JUnit 5 (#526)

* Allow backwards compatibility with JUnit 4 @Rules in JUnit 5

This allows us to defer having to re-implement all of our JUnit 4 Rules as JUnit
5 extensions for now, while continuing to in-place upgrade all existing JUnit 4
test classes to JUnit 5.

As proof of concept, this upgrades PremiumListUtils (which uses AppEngineRule,
our largest and most complicated @Rule) to use the JUnit 5 test runner.

* Apply formatter to entire file
This commit is contained in:
Ben McIlwain 2020-03-23 14:45:54 -04:00 committed by GitHub
parent ad06f265a5
commit fe760d7066
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
54 changed files with 889 additions and 786 deletions

View file

@ -29,21 +29,20 @@ import google.registry.model.registry.label.PremiumList.PremiumListEntry;
import google.registry.model.registry.label.PremiumList.PremiumListRevision;
import google.registry.testing.AppEngineRule;
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.migrationsupport.rules.EnableRuleMigrationSupport;
/** Unit tests for {@link PremiumList}. */
@RunWith(JUnit4.class)
@EnableRuleMigrationSupport
public class PremiumListTest {
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@Before
public void before() {
@BeforeEach
void before() {
// createTld() overwrites the premium list, so call it first.
createTld("tld");
PremiumList pl =
@ -57,20 +56,20 @@ public class PremiumListTest {
}
@Test
public void testSave_badSyntax() {
void testSave_badSyntax() {
assertThrows(
IllegalArgumentException.class,
() -> persistPremiumList("gtld1", "lol,nonsense USD,e,e # yup"));
}
@Test
public void testSave_invalidCurrencySymbol() {
void testSave_invalidCurrencySymbol() {
assertThrows(
IllegalArgumentException.class, () -> persistReservedList("gtld1", "lol,XBTC 200"));
}
@Test
public void testProbablePremiumLabels() {
void testProbablePremiumLabels() {
PremiumList pl = PremiumList.getUncached("tld").get();
PremiumListRevision revision = ofy().load().key(pl.getRevisionKey()).now();
assertThat(revision.getProbablePremiumLabels().mightContain("notpremium")).isFalse();
@ -82,7 +81,7 @@ public class PremiumListTest {
}
@Test
public void testParse_cannotIncludeDuplicateLabels() {
void testParse_cannotIncludeDuplicateLabels() {
IllegalStateException thrown =
assertThrows(
IllegalStateException.class,
@ -103,7 +102,7 @@ public class PremiumListTest {
}
@Test
public void testValidation_labelMustBeLowercase() {
void testValidation_labelMustBeLowercase() {
Exception e =
assertThrows(
IllegalArgumentException.class,
@ -116,7 +115,7 @@ public class PremiumListTest {
}
@Test
public void testValidation_labelMustBePunyCoded() {
void testValidation_labelMustBePunyCoded() {
Exception e =
assertThrows(
IllegalArgumentException.class,