Normalize expected exception handling in tests

This removes exception rules that aren't used and switches over
existing uses of ExceptedException to ExceptionRule when possible.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=129013329
This commit is contained in:
Ben McIlwain 2016-08-01 12:25:54 -07:00 committed by Justine Tunney
parent 60fc27646a
commit 9e65acc937
11 changed files with 14 additions and 29 deletions

View file

@ -34,7 +34,6 @@ import org.joda.time.Duration;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;
@ -51,9 +50,6 @@ public class PublishDnsUpdatesActionTest {
@Rule
public final InjectRule inject = new InjectRule();
@Rule
public final ExpectedException thrown = ExpectedException.none();
private final FakeClock clock = new FakeClock(DateTime.parse("1971-01-01TZ"));
private final DnsWriter dnsWriter = mock(DnsWriter.class);
private PublishDnsUpdatesAction action;

View file

@ -19,9 +19,9 @@ import static google.registry.testing.DatastoreHelper.createTlds;
import com.google.common.net.InternetDomainName;
import google.registry.testing.AppEngineRule;
import google.registry.testing.ExceptionRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@ -33,7 +33,7 @@ public class RegistriesTest {
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
@Rule
public ExpectedException thrown = ExpectedException.none();
public ExceptionRule thrown = new ExceptionRule();
private void initTestTlds() {
createTlds("foo", "a.b.c"); // Test a multipart tld.

View file

@ -35,7 +35,6 @@ import google.registry.testing.AppEngineRule;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Matchers;
import org.mockito.Mock;
@ -45,9 +44,6 @@ import org.mockito.runners.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class MetricsExportActionTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()

View file

@ -33,7 +33,6 @@ import java.util.Set;
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;
@ -41,9 +40,6 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class GtechToolTest {
@Rule
public final ExpectedException thrown = ExpectedException.none();
@Rule
public final Expect expect = Expect.create();

View file

@ -16,9 +16,9 @@ package google.registry.tools;
import static com.google.common.truth.Truth.assertThat;
import google.registry.testing.ExceptionRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@ -27,7 +27,7 @@ import org.junit.runners.JUnit4;
public class RegistryToolEnvironmentTest {
@Rule
public final ExpectedException thrown = ExpectedException.none();
public ExceptionRule thrown = new ExceptionRule();
@Test
public void testGet_withoutSetup_throws() throws Exception {

View file

@ -32,7 +32,6 @@ import java.util.Set;
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;
@ -40,9 +39,6 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class RegistryToolTest {
@Rule
public final ExpectedException thrown = ExpectedException.none();
@Rule
public final Expect expect = Expect.create();

View file

@ -21,6 +21,7 @@ java_library(
"//third_party/java/re2j",
"//third_party/java/truth",
"//java/google/registry/ui/forms",
"//javatests/google/registry/testing",
],
)

View file

@ -17,9 +17,9 @@ package google.registry.ui.forms;
import static com.google.common.truth.Truth.assertThat;
import com.google.common.testing.NullPointerTester;
import google.registry.testing.ExceptionRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@ -28,7 +28,7 @@ import org.junit.runners.JUnit4;
public class FormFieldExceptionTest {
@Rule
public final ExpectedException thrown = ExpectedException.none();
public ExceptionRule thrown = new ExceptionRule();
@Test
public void testGetFieldName_multiplePropagations_joinsUsingJsonNotation() throws Exception {

View file

@ -19,6 +19,7 @@ import static google.registry.util.ResourceUtils.readResourceUtf8;
import static google.registry.xjc.XjcXmlTransformer.unmarshal;
import static java.nio.charset.StandardCharsets.UTF_8;
import google.registry.testing.ExceptionRule;
import google.registry.xjc.epp.XjcEpp;
import google.registry.xjc.rde.XjcRdeDeposit;
import java.io.ByteArrayInputStream;
@ -26,7 +27,6 @@ import org.junit.Rule;
import org.junit.experimental.theories.DataPoints;
import org.junit.experimental.theories.Theories;
import org.junit.experimental.theories.Theory;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
/**
@ -37,7 +37,7 @@ import org.junit.runner.RunWith;
public class XmlTestdataTest {
@Rule
public final ExpectedException thrown = ExpectedException.none();
public final ExceptionRule thrown = new ExceptionRule();
private static class Example {
final ByteArrayInputStream xmlStream;
@ -151,7 +151,7 @@ public class XmlTestdataTest {
@Theory
public void testInvalid(Evil v) throws Exception {
thrown.expectMessage(v.error);
thrown.expect(Throwable.class, v.error);
unmarshal(XjcObject.class, v.xmlStream);
}
}

View file

@ -16,10 +16,10 @@ package google.registry.xml;
import static com.google.common.truth.Truth.assertThat;
import google.registry.testing.ExceptionRule;
import org.joda.time.LocalDate;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@ -28,7 +28,7 @@ import org.junit.runners.JUnit4;
public class DateAdapterTest {
@Rule
public final ExpectedException thrown = ExpectedException.none();
public final ExceptionRule thrown = new ExceptionRule();
@Test
public void testMarshal() {

View file

@ -17,11 +17,11 @@ package google.registry.xml;
import static com.google.common.truth.Truth.assertThat;
import static org.joda.time.DateTimeZone.UTC;
import google.registry.testing.ExceptionRule;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@ -30,7 +30,7 @@ import org.junit.runners.JUnit4;
public class UtcDateTimeAdapterTest {
@Rule
public final ExpectedException thrown = ExpectedException.none();
public final ExceptionRule thrown = new ExceptionRule();
@Test
public void testMarshal() {