mirror of
https://github.com/google/nomulus.git
synced 2025-07-25 20:18:34 +02:00
Merge JUnitBackport's expectThrows into assertThrows
More information: https://github.com/junit-team/junit5/issues/531 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=187034408
This commit is contained in:
parent
f96a0b7da9
commit
606b470cd0
180 changed files with 1325 additions and 1381 deletions
|
@ -17,7 +17,6 @@ package google.registry.request;
|
|||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.request.RequestModule.provideJsonPayload;
|
||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
|
||||
import com.google.common.net.MediaType;
|
||||
import google.registry.request.HttpException.BadRequestException;
|
||||
|
@ -44,7 +43,7 @@ public final class RequestModuleTest {
|
|||
@Test
|
||||
public void testProvideJsonPayload_malformedInput_throws500() throws Exception {
|
||||
BadRequestException thrown =
|
||||
expectThrows(
|
||||
assertThrows(
|
||||
BadRequestException.class, () -> provideJsonPayload(MediaType.JSON_UTF_8, "{\"k\":"));
|
||||
assertThat(thrown).hasMessageThat().contains("Malformed JSON");
|
||||
}
|
||||
|
@ -52,7 +51,7 @@ public final class RequestModuleTest {
|
|||
@Test
|
||||
public void testProvideJsonPayload_emptyInput_throws500() throws Exception {
|
||||
BadRequestException thrown =
|
||||
expectThrows(BadRequestException.class, () -> provideJsonPayload(MediaType.JSON_UTF_8, ""));
|
||||
assertThrows(BadRequestException.class, () -> provideJsonPayload(MediaType.JSON_UTF_8, ""));
|
||||
assertThat(thrown).hasMessageThat().contains("Malformed JSON");
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ import static google.registry.request.RequestParameters.extractOptionalEnumParam
|
|||
import static google.registry.request.RequestParameters.extractOptionalParameter;
|
||||
import static google.registry.request.RequestParameters.extractRequiredDatetimeParameter;
|
||||
import static google.registry.request.RequestParameters.extractRequiredParameter;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
|
@ -49,7 +49,7 @@ public class RequestParametersTest {
|
|||
@Test
|
||||
public void testExtractRequiredParameter_notPresent_throwsBadRequest() throws Exception {
|
||||
BadRequestException thrown =
|
||||
expectThrows(BadRequestException.class, () -> extractRequiredParameter(req, "spin"));
|
||||
assertThrows(BadRequestException.class, () -> extractRequiredParameter(req, "spin"));
|
||||
assertThat(thrown).hasMessageThat().contains("spin");
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ public class RequestParametersTest {
|
|||
public void testExtractRequiredParameter_empty_throwsBadRequest() throws Exception {
|
||||
when(req.getParameter("spin")).thenReturn("");
|
||||
BadRequestException thrown =
|
||||
expectThrows(BadRequestException.class, () -> extractRequiredParameter(req, "spin"));
|
||||
assertThrows(BadRequestException.class, () -> extractRequiredParameter(req, "spin"));
|
||||
assertThat(thrown).hasMessageThat().contains("spin");
|
||||
}
|
||||
|
||||
|
@ -142,7 +142,7 @@ public class RequestParametersTest {
|
|||
public void testExtractEnumValue_nonExistentValue_throwsBadRequest() throws Exception {
|
||||
when(req.getParameter("spin")).thenReturn("sing");
|
||||
BadRequestException thrown =
|
||||
expectThrows(
|
||||
assertThrows(
|
||||
BadRequestException.class, () -> extractEnumParameter(req, Club.class, "spin"));
|
||||
assertThat(thrown).hasMessageThat().contains("spin");
|
||||
}
|
||||
|
@ -163,7 +163,7 @@ public class RequestParametersTest {
|
|||
public void testOptionalExtractEnumValue_nonExistentValue_throwsBadRequest() throws Exception {
|
||||
when(req.getParameter("spin")).thenReturn("sing");
|
||||
BadRequestException thrown =
|
||||
expectThrows(
|
||||
assertThrows(
|
||||
BadRequestException.class, () -> extractOptionalEnumParameter(req, Club.class, "spin"));
|
||||
assertThat(thrown).hasMessageThat().contains("spin");
|
||||
}
|
||||
|
@ -179,7 +179,7 @@ public class RequestParametersTest {
|
|||
public void testExtractRequiredDatetimeParameter_badValue_throwsBadRequest() throws Exception {
|
||||
when(req.getParameter("timeParam")).thenReturn("Tuesday at three o'clock");
|
||||
BadRequestException thrown =
|
||||
expectThrows(
|
||||
assertThrows(
|
||||
BadRequestException.class, () -> extractRequiredDatetimeParameter(req, "timeParam"));
|
||||
assertThat(thrown).hasMessageThat().contains("timeParam");
|
||||
}
|
||||
|
@ -195,7 +195,7 @@ public class RequestParametersTest {
|
|||
public void testExtractOptionalDatetimeParameter_badValue_throwsBadRequest() throws Exception {
|
||||
when(req.getParameter("timeParam")).thenReturn("Tuesday at three o'clock");
|
||||
BadRequestException thrown =
|
||||
expectThrows(
|
||||
assertThrows(
|
||||
BadRequestException.class, () -> extractOptionalDatetimeParameter(req, "timeParam"));
|
||||
assertThat(thrown).hasMessageThat().contains("timeParam");
|
||||
}
|
||||
|
@ -209,7 +209,7 @@ public class RequestParametersTest {
|
|||
@Test
|
||||
public void testExtractRequiredDatetimeParameter_noValue_throwsBadRequest() throws Exception {
|
||||
BadRequestException thrown =
|
||||
expectThrows(
|
||||
assertThrows(
|
||||
BadRequestException.class, () -> extractRequiredDatetimeParameter(req, "timeParam"));
|
||||
assertThat(thrown).hasMessageThat().contains("timeParam");
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ package google.registry.request;
|
|||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth8.assertThat;
|
||||
import static google.registry.request.auth.Auth.AUTH_INTERNAL_ONLY;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.Callable;
|
||||
|
@ -37,7 +37,7 @@ public final class RouterTest {
|
|||
@Test
|
||||
public void testRoute_noRoutes_throws() throws Exception {
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(IllegalArgumentException.class, () -> Router.create(Empty.class));
|
||||
assertThrows(IllegalArgumentException.class, () -> Router.create(Empty.class));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains("No routes found for class: google.registry.request.RouterTest.Empty");
|
||||
|
@ -143,7 +143,7 @@ public final class RouterTest {
|
|||
@Test
|
||||
public void testRoute_methodsInComponentAreIgnored_throws() throws Exception {
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
assertThrows(
|
||||
IllegalArgumentException.class, () -> Router.create(WeirdMethodsComponent.class));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
|
@ -173,7 +173,7 @@ public final class RouterTest {
|
|||
@Test
|
||||
public void testCreate_twoTasksWithSameMethodAndPath_resultsInError() throws Exception {
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(IllegalArgumentException.class, () -> Router.create(DuplicateComponent.class));
|
||||
assertThrows(IllegalArgumentException.class, () -> Router.create(DuplicateComponent.class));
|
||||
assertThat(thrown).hasMessageThat().contains("Multiple entries with same key");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ package google.registry.request.auth;
|
|||
import static com.google.common.net.HttpHeaders.AUTHORIZATION;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth8.assertThat;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
@ -388,7 +388,7 @@ public class RequestAuthenticatorTest {
|
|||
@Test
|
||||
public void testCheckAuthConfig_NoMethods_failure() throws Exception {
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> RequestAuthenticator.checkAuthConfig(AUTH_NO_METHODS));
|
||||
assertThat(thrown).hasMessageThat().contains("Must specify at least one auth method");
|
||||
|
@ -397,7 +397,7 @@ public class RequestAuthenticatorTest {
|
|||
@Test
|
||||
public void testCheckAuthConfig_WrongMethodOrdering_failure() throws Exception {
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> RequestAuthenticator.checkAuthConfig(AUTH_WRONG_METHOD_ORDERING));
|
||||
assertThat(thrown)
|
||||
|
@ -408,7 +408,7 @@ public class RequestAuthenticatorTest {
|
|||
@Test
|
||||
public void testCheckAuthConfig_DuplicateMethods_failure() throws Exception {
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> RequestAuthenticator.checkAuthConfig(AUTH_DUPLICATE_METHODS));
|
||||
assertThat(thrown)
|
||||
|
@ -419,7 +419,7 @@ public class RequestAuthenticatorTest {
|
|||
@Test
|
||||
public void testCheckAuthConfig_InternalWithUser_failure() throws Exception {
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> RequestAuthenticator.checkAuthConfig(AUTH_INTERNAL_WITH_USER));
|
||||
assertThat(thrown)
|
||||
|
@ -430,7 +430,7 @@ public class RequestAuthenticatorTest {
|
|||
@Test
|
||||
public void testCheckAuthConfig_WronglyIgnoringUser_failure() throws Exception {
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> RequestAuthenticator.checkAuthConfig(AUTH_WRONGLY_IGNORING_USER));
|
||||
assertThat(thrown)
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
package google.registry.request.lock;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
@ -97,7 +97,7 @@ public final class LockHandlerImplTest {
|
|||
Lock lock = mock(Lock.class);
|
||||
Exception expectedException = new RuntimeException("test");
|
||||
RuntimeException exception =
|
||||
expectThrows(
|
||||
assertThrows(
|
||||
RuntimeException.class,
|
||||
() -> executeWithLocks(new ThrowingCallable(expectedException), lock));
|
||||
assertThat(exception).isSameAs(expectedException);
|
||||
|
@ -109,7 +109,7 @@ public final class LockHandlerImplTest {
|
|||
Lock lock = mock(Lock.class);
|
||||
Exception expectedException = new Exception("test");
|
||||
RuntimeException exception =
|
||||
expectThrows(
|
||||
assertThrows(
|
||||
RuntimeException.class,
|
||||
() -> executeWithLocks(new ThrowingCallable(expectedException), lock));
|
||||
assertThat(exception).hasCauseThat().isSameAs(expectedException);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue