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

View file

@ -19,9 +19,9 @@ import static google.registry.testing.DatastoreHelper.createTlds;
import com.google.common.net.InternetDomainName; import com.google.common.net.InternetDomainName;
import google.registry.testing.AppEngineRule; import google.registry.testing.AppEngineRule;
import google.registry.testing.ExceptionRule;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.JUnit4; import org.junit.runners.JUnit4;
@ -33,7 +33,7 @@ public class RegistriesTest {
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build(); public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
@Rule @Rule
public ExpectedException thrown = ExpectedException.none(); public ExceptionRule thrown = new ExceptionRule();
private void initTestTlds() { private void initTestTlds() {
createTlds("foo", "a.b.c"); // Test a multipart tld. 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.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Matchers; import org.mockito.Matchers;
import org.mockito.Mock; import org.mockito.Mock;
@ -45,9 +44,6 @@ import org.mockito.runners.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class) @RunWith(MockitoJUnitRunner.class)
public class MetricsExportActionTest { public class MetricsExportActionTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Rule @Rule
public final AppEngineRule appEngine = AppEngineRule.builder() public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore() .withDatastore()

View file

@ -33,7 +33,6 @@ import java.util.Set;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.JUnit4; import org.junit.runners.JUnit4;
@ -41,9 +40,6 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class) @RunWith(JUnit4.class)
public class GtechToolTest { public class GtechToolTest {
@Rule
public final ExpectedException thrown = ExpectedException.none();
@Rule @Rule
public final Expect expect = Expect.create(); 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 static com.google.common.truth.Truth.assertThat;
import google.registry.testing.ExceptionRule;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.JUnit4; import org.junit.runners.JUnit4;
@ -27,7 +27,7 @@ import org.junit.runners.JUnit4;
public class RegistryToolEnvironmentTest { public class RegistryToolEnvironmentTest {
@Rule @Rule
public final ExpectedException thrown = ExpectedException.none(); public ExceptionRule thrown = new ExceptionRule();
@Test @Test
public void testGet_withoutSetup_throws() throws Exception { public void testGet_withoutSetup_throws() throws Exception {

View file

@ -32,7 +32,6 @@ import java.util.Set;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.JUnit4; import org.junit.runners.JUnit4;
@ -40,9 +39,6 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class) @RunWith(JUnit4.class)
public class RegistryToolTest { public class RegistryToolTest {
@Rule
public final ExpectedException thrown = ExpectedException.none();
@Rule @Rule
public final Expect expect = Expect.create(); public final Expect expect = Expect.create();

View file

@ -21,6 +21,7 @@ java_library(
"//third_party/java/re2j", "//third_party/java/re2j",
"//third_party/java/truth", "//third_party/java/truth",
"//java/google/registry/ui/forms", "//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 static com.google.common.truth.Truth.assertThat;
import com.google.common.testing.NullPointerTester; import com.google.common.testing.NullPointerTester;
import google.registry.testing.ExceptionRule;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.JUnit4; import org.junit.runners.JUnit4;
@ -28,7 +28,7 @@ import org.junit.runners.JUnit4;
public class FormFieldExceptionTest { public class FormFieldExceptionTest {
@Rule @Rule
public final ExpectedException thrown = ExpectedException.none(); public ExceptionRule thrown = new ExceptionRule();
@Test @Test
public void testGetFieldName_multiplePropagations_joinsUsingJsonNotation() throws Exception { 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 google.registry.xjc.XjcXmlTransformer.unmarshal;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
import google.registry.testing.ExceptionRule;
import google.registry.xjc.epp.XjcEpp; import google.registry.xjc.epp.XjcEpp;
import google.registry.xjc.rde.XjcRdeDeposit; import google.registry.xjc.rde.XjcRdeDeposit;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
@ -26,7 +27,6 @@ import org.junit.Rule;
import org.junit.experimental.theories.DataPoints; import org.junit.experimental.theories.DataPoints;
import org.junit.experimental.theories.Theories; import org.junit.experimental.theories.Theories;
import org.junit.experimental.theories.Theory; import org.junit.experimental.theories.Theory;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
/** /**
@ -37,7 +37,7 @@ import org.junit.runner.RunWith;
public class XmlTestdataTest { public class XmlTestdataTest {
@Rule @Rule
public final ExpectedException thrown = ExpectedException.none(); public final ExceptionRule thrown = new ExceptionRule();
private static class Example { private static class Example {
final ByteArrayInputStream xmlStream; final ByteArrayInputStream xmlStream;
@ -151,7 +151,7 @@ public class XmlTestdataTest {
@Theory @Theory
public void testInvalid(Evil v) throws Exception { public void testInvalid(Evil v) throws Exception {
thrown.expectMessage(v.error); thrown.expect(Throwable.class, v.error);
unmarshal(XjcObject.class, v.xmlStream); unmarshal(XjcObject.class, v.xmlStream);
} }
} }

View file

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

View file

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