Replace ExceptionRule with ExpectedException

This is in preparation for running the automatic refactoring script that
will replace all ExpectedExceptions with use of JUnit 4.13's assertThrows/
expectThrows.

Note that I have recorded the callsites of assertions about EppExceptions
being marshallable and will edit those specific assertions back in after
running the automatic refactoring script (which do not understand these).

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=178812403
This commit is contained in:
mcilwain 2017-12-12 14:10:10 -08:00 committed by jianglai
parent c5515ab4e6
commit 03c782f38e
142 changed files with 285 additions and 359 deletions

View file

@ -30,7 +30,6 @@ import google.registry.rde.EscrowTaskRunner.EscrowTask;
import google.registry.request.HttpException.NoContentException;
import google.registry.request.HttpException.ServiceUnavailableException;
import google.registry.testing.AppEngineRule;
import google.registry.testing.ExceptionRule;
import google.registry.testing.FakeClock;
import google.registry.testing.FakeLockHandler;
import org.joda.time.DateTime;
@ -38,6 +37,7 @@ import org.joda.time.DateTimeZone;
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;
@ -46,7 +46,7 @@ import org.junit.runners.JUnit4;
public class EscrowTaskRunnerTest {
@Rule
public final ExceptionRule thrown = new ExceptionRule();
public final ExpectedException thrown = ExpectedException.none();
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()

View file

@ -27,7 +27,6 @@ import com.google.common.io.ByteStreams;
import google.registry.keyring.api.Keyring;
import google.registry.rde.Ghostryde.DecodeResult;
import google.registry.testing.BouncyCastleProviderRule;
import google.registry.testing.ExceptionRule;
import google.registry.testing.FakeKeyringModule;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@ -43,6 +42,7 @@ import org.junit.Test;
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;
/** Unit tests for {@link Ghostryde}. */
@ -51,7 +51,7 @@ import org.junit.runner.RunWith;
public class GhostrydeTest {
@Rule
public final ExceptionRule thrown = new ExceptionRule();
public final ExpectedException thrown = ExpectedException.none();
@Rule
public final BouncyCastleProviderRule bouncy = new BouncyCastleProviderRule();

View file

@ -27,7 +27,6 @@ import google.registry.model.domain.DomainResource;
import google.registry.model.eppcommon.StatusValue;
import google.registry.model.host.HostResource;
import google.registry.testing.AppEngineRule;
import google.registry.testing.ExceptionRule;
import google.registry.xjc.host.XjcHostStatusType;
import google.registry.xjc.host.XjcHostStatusValueType;
import google.registry.xjc.rdehost.XjcRdeHost;
@ -37,6 +36,7 @@ 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;
@ -55,7 +55,7 @@ public class HostResourceToXjcConverterTest {
.build();
@Rule
public final ExceptionRule thrown = new ExceptionRule();
public final ExpectedException thrown = ExpectedException.none();
@Before
public void init() {

View file

@ -49,7 +49,6 @@ import google.registry.model.registry.Registry;
import google.registry.request.HttpException.InternalServerErrorException;
import google.registry.testing.AppEngineRule;
import google.registry.testing.BouncyCastleProviderRule;
import google.registry.testing.ExceptionRule;
import google.registry.testing.FakeClock;
import google.registry.testing.FakeKeyringModule;
import google.registry.testing.FakeResponse;
@ -66,6 +65,7 @@ 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;
import org.mockito.ArgumentCaptor;
@ -79,7 +79,7 @@ public class RdeReportActionTest {
private static final ByteSource IIRDEA_GOOD_XML = RdeTestData.loadBytes("iirdea_good.xml");
@Rule
public final ExceptionRule thrown = new ExceptionRule();
public final ExpectedException thrown = ExpectedException.none();
@Rule
public final BouncyCastleProviderRule bouncy = new BouncyCastleProviderRule();
@ -182,9 +182,9 @@ public class RdeReportActionTest {
@Test
public void testRunWithLock_fetchFailed_throwsRuntimeException() throws Exception {
class ExpectedException extends RuntimeException {}
when(urlFetchService.fetch(any(HTTPRequest.class))).thenThrow(new ExpectedException());
thrown.expect(ExpectedException.class);
class ExpectedThrownException extends RuntimeException {}
when(urlFetchService.fetch(any(HTTPRequest.class))).thenThrow(new ExpectedThrownException());
thrown.expect(ExpectedThrownException.class);
createAction().runWithLock(loadRdeReportCursor());
}

View file

@ -53,7 +53,6 @@ import google.registry.model.ofy.Ofy;
import google.registry.model.registry.Registry;
import google.registry.request.HttpException.BadRequestException;
import google.registry.request.RequestParameters;
import google.registry.testing.ExceptionRule;
import google.registry.testing.FakeClock;
import google.registry.testing.FakeKeyringModule;
import google.registry.testing.FakeLockHandler;
@ -93,6 +92,7 @@ import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@ -109,7 +109,7 @@ public class RdeStagingActionTest extends MapreduceTestCase<RdeStagingAction> {
public final InjectRule inject = new InjectRule();
@Rule
public final ExceptionRule thrown = new ExceptionRule();
public final ExpectedException thrown = ExpectedException.none();
private final FakeClock clock = new FakeClock();
private final FakeResponse response = new FakeResponse();

View file

@ -61,7 +61,6 @@ import google.registry.request.HttpException.ServiceUnavailableException;
import google.registry.request.RequestParameters;
import google.registry.testing.AppEngineRule;
import google.registry.testing.BouncyCastleProviderRule;
import google.registry.testing.ExceptionRule;
import google.registry.testing.FakeClock;
import google.registry.testing.FakeKeyringModule;
import google.registry.testing.FakeResponse;
@ -87,6 +86,7 @@ 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.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@ -115,7 +115,7 @@ public class RdeUploadActionTest {
new GcsFilename("bucket", "tld_2010-10-17_full_S1_R1-report.xml.ghostryde");
@Rule
public final ExceptionRule thrown = new ExceptionRule();
public final ExpectedException thrown = ExpectedException.none();
@Rule
public final SftpServerRule sftpd = new SftpServerRule();

View file

@ -25,7 +25,6 @@ import com.google.common.io.ByteStreams;
import google.registry.config.RegistryConfig.ConfigModule;
import google.registry.gcs.GcsUtils;
import google.registry.testing.AppEngineRule;
import google.registry.testing.ExceptionRule;
import google.registry.xjc.JaxbFragment;
import google.registry.xjc.rdecontact.XjcRdeContact;
import google.registry.xjc.rdecontact.XjcRdeContactElement;
@ -39,6 +38,7 @@ import java.io.OutputStream;
import java.util.NoSuchElementException;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@ -62,7 +62,7 @@ public class RdeContactReaderTest {
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
@Rule public final ExceptionRule thrown = new ExceptionRule();
@Rule public final ExpectedException thrown = ExpectedException.none();
/** Reads at least one result at 0 offset 1 maxResults */
@Test

View file

@ -28,7 +28,6 @@ import com.google.common.io.ByteStreams;
import google.registry.config.RegistryConfig.ConfigModule;
import google.registry.gcs.GcsUtils;
import google.registry.testing.AppEngineRule;
import google.registry.testing.ExceptionRule;
import google.registry.xjc.JaxbFragment;
import google.registry.xjc.rdedomain.XjcRdeDomain;
import google.registry.xjc.rdedomain.XjcRdeDomainElement;
@ -43,6 +42,7 @@ import java.util.NoSuchElementException;
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;
@ -66,7 +66,7 @@ public class RdeDomainReaderTest {
.build();
@Rule
public final ExceptionRule thrown = new ExceptionRule();
public final ExpectedException thrown = ExpectedException.none();
@Before
public void before() {

View file

@ -26,7 +26,6 @@ import com.google.common.io.ByteStreams;
import google.registry.config.RegistryConfig.ConfigModule;
import google.registry.gcs.GcsUtils;
import google.registry.testing.AppEngineRule;
import google.registry.testing.ExceptionRule;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@ -34,6 +33,7 @@ import java.util.List;
import java.util.Optional;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@ -59,7 +59,7 @@ public class RdeHostInputTest {
.build();
@Rule
public final ExceptionRule thrown = new ExceptionRule();
public final ExpectedException thrown = ExpectedException.none();
/** Number of shards cannot be negative */
@Test

View file

@ -26,7 +26,6 @@ import com.google.common.io.ByteStreams;
import google.registry.config.RegistryConfig.ConfigModule;
import google.registry.gcs.GcsUtils;
import google.registry.testing.AppEngineRule;
import google.registry.testing.ExceptionRule;
import google.registry.xjc.JaxbFragment;
import google.registry.xjc.rdehost.XjcRdeHost;
import google.registry.xjc.rdehost.XjcRdeHostElement;
@ -40,6 +39,7 @@ import java.io.OutputStream;
import java.util.NoSuchElementException;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@ -59,7 +59,7 @@ public class RdeHostReaderTest {
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
@Rule public final ExceptionRule thrown = new ExceptionRule();
@Rule public final ExpectedException thrown = ExpectedException.none();
/** Reads at least one result at 0 offset 1 maxResults */
@Test

View file

@ -48,7 +48,6 @@ import google.registry.model.index.ForeignKeyIndex;
import google.registry.model.registrar.Registrar;
import google.registry.model.registry.Registry.TldState;
import google.registry.testing.AppEngineRule;
import google.registry.testing.ExceptionRule;
import google.registry.testing.FakeClock;
import google.registry.testing.ShardableTestCase;
import java.io.IOException;
@ -60,6 +59,7 @@ import org.junit.After;
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;
@ -81,7 +81,7 @@ public class RdeImportUtilsTest extends ShardableTestCase {
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
@Rule
public final ExceptionRule thrown = new ExceptionRule();
public final ExpectedException thrown = ExpectedException.none();
private final GcsUtils gcsUtils = mock(GcsUtils.class);

View file

@ -19,7 +19,6 @@ import static google.registry.rde.imports.RdeImportsTestData.loadBytes;
import com.google.common.io.ByteSource;
import google.registry.rde.imports.RdeParser.RdeHeader;
import google.registry.testing.ExceptionRule;
import google.registry.xjc.rdecontact.XjcRdeContact;
import google.registry.xjc.rdedomain.XjcRdeDomain;
import google.registry.xjc.rdeeppparams.XjcRdeEppParams;
@ -34,6 +33,7 @@ import org.junit.After;
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;
@ -45,7 +45,7 @@ public class RdeParserTest {
private InputStream xml;
@Rule public final ExceptionRule thrown = new ExceptionRule();
@Rule public final ExpectedException thrown = ExpectedException.none();
private void checkHeader(RdeHeader header) {
assertThat(header.getTld()).isEqualTo("test");

View file

@ -50,7 +50,6 @@ import google.registry.model.transfer.TransferData;
import google.registry.model.transfer.TransferStatus;
import google.registry.testing.AppEngineRule;
import google.registry.testing.DeterministicStringGenerator;
import google.registry.testing.ExceptionRule;
import google.registry.testing.InjectRule;
import google.registry.util.StringGenerator;
import google.registry.xjc.rdedomain.XjcRdeDomain;
@ -66,6 +65,7 @@ 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;
@ -91,7 +91,7 @@ public class XjcToDomainResourceConverterTest {
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
@Rule public final ExceptionRule thrown = new ExceptionRule();
@Rule public final ExpectedException thrown = ExpectedException.none();
@Rule public final InjectRule inject = new InjectRule();