mirror of
https://github.com/google/nomulus.git
synced 2025-08-05 17:28:25 +02:00
Automatically refactor more exception testing to use new JUnit rules
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=178911894
This commit is contained in:
parent
36ad38e5df
commit
7dc224627f
125 changed files with 1970 additions and 1982 deletions
|
@ -41,16 +41,11 @@ import google.registry.model.host.HostResource;
|
|||
import google.registry.model.smd.EncodedSignedMark;
|
||||
import org.joda.money.Money;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
/** Unit tests for {@link DomainApplication}. */
|
||||
public class DomainApplicationTest extends EntityTestCase {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
DomainApplication domainApplication;
|
||||
|
||||
@Before
|
||||
|
|
|
@ -24,6 +24,7 @@ import static google.registry.testing.DatastoreHelper.newDomainResource;
|
|||
import static google.registry.testing.DatastoreHelper.newHostResource;
|
||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||
import static google.registry.testing.DomainResourceSubject.assertAboutDomains;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||
import static org.joda.money.CurrencyUnit.USD;
|
||||
|
||||
|
@ -55,16 +56,10 @@ import java.util.stream.Stream;
|
|||
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.rules.ExpectedException;
|
||||
|
||||
/** Unit tests for {@link DomainResource}. */
|
||||
public class DomainResourceTest extends EntityTestCase {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
DomainResource domain;
|
||||
|
||||
@Before
|
||||
|
@ -445,15 +440,23 @@ public class DomainResourceTest extends EntityTestCase {
|
|||
|
||||
@Test
|
||||
public void testFailure_uppercaseDomainName() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Domain name must be in puny-coded, lower-case form");
|
||||
domain.asBuilder().setFullyQualifiedDomainName("AAA.BBB");
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> domain.asBuilder().setFullyQualifiedDomainName("AAA.BBB"));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains("Domain name must be in puny-coded, lower-case form");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_utf8DomainName() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Domain name must be in puny-coded, lower-case form");
|
||||
domain.asBuilder().setFullyQualifiedDomainName("みんな.みんな");
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> domain.asBuilder().setFullyQualifiedDomainName("みんな.みんな"));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains("Domain name must be in puny-coded, lower-case form");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
package google.registry.model.domain;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
|
||||
import com.googlecode.objectify.Key;
|
||||
|
@ -30,7 +31,6 @@ import org.joda.time.DateTime;
|
|||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
|
@ -42,10 +42,6 @@ public class GracePeriodTest {
|
|||
public final AppEngineRule appEngine = AppEngineRule.builder()
|
||||
.withDatastore() // Needed to be able to construct Keys.
|
||||
.build();
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private final DateTime now = DateTime.now(UTC);
|
||||
private BillingEvent.OneTime onetime;
|
||||
|
||||
|
@ -96,19 +92,24 @@ public class GracePeriodTest {
|
|||
|
||||
@Test
|
||||
public void testFailure_forBillingEvent_autoRenew() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("autorenew");
|
||||
GracePeriod.forBillingEvent(GracePeriodStatus.AUTO_RENEW, onetime);
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> GracePeriod.forBillingEvent(GracePeriodStatus.AUTO_RENEW, onetime));
|
||||
assertThat(thrown).hasMessageThat().contains("autorenew");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_createForRecurring_notAutoRenew() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("autorenew");
|
||||
GracePeriod.createForRecurring(
|
||||
GracePeriodStatus.RENEW,
|
||||
now.plusDays(1),
|
||||
"TheRegistrar",
|
||||
Key.create(Recurring.class, 12345));
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
GracePeriod.createForRecurring(
|
||||
GracePeriodStatus.RENEW,
|
||||
now.plusDays(1),
|
||||
"TheRegistrar",
|
||||
Key.create(Recurring.class, 12345)));
|
||||
assertThat(thrown).hasMessageThat().contains("autorenew");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,9 +26,7 @@ import com.googlecode.objectify.Key;
|
|||
import google.registry.model.EntityTestCase;
|
||||
import google.registry.model.reporting.HistoryEntry;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
/** Unit tests for {@link LrpTokenEntity}. */
|
||||
public class LrpTokenEntityTest extends EntityTestCase {
|
||||
|
@ -36,9 +34,6 @@ public class LrpTokenEntityTest extends EntityTestCase {
|
|||
LrpTokenEntity unredeemedToken;
|
||||
LrpTokenEntity redeemedToken;
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
createTld("tld");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue