mirror of
https://github.com/google/nomulus.git
synced 2025-07-24 19:48:32 +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
|
@ -15,7 +15,7 @@
|
|||
package google.registry.util;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.testing.NullPointerTester;
|
||||
|
@ -51,7 +51,7 @@ public class ConcurrentTest {
|
|||
@Test
|
||||
public void testTransform_throwsException_isSinglyWrappedByUee() throws Exception {
|
||||
UncheckedExecutionException e =
|
||||
expectThrows(
|
||||
assertThrows(
|
||||
UncheckedExecutionException.class,
|
||||
() ->
|
||||
Concurrent.transform(
|
||||
|
|
|
@ -17,7 +17,7 @@ package google.registry.util;
|
|||
import static com.google.common.io.BaseEncoding.base64;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import com.google.common.testing.EqualsTester;
|
||||
|
@ -202,7 +202,7 @@ public class PosixTarHeaderTest {
|
|||
bytes[150] = '0';
|
||||
bytes[151] = '0';
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(IllegalArgumentException.class, () -> PosixTarHeader.from(bytes));
|
||||
assertThrows(IllegalArgumentException.class, () -> PosixTarHeader.from(bytes));
|
||||
assertThat(thrown).hasMessageThat().contains("chksum invalid");
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
package google.registry.util;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
|
||||
import google.registry.testing.FakeClock;
|
||||
import google.registry.testing.FakeSleeper;
|
||||
|
@ -83,7 +83,7 @@ public class RetrierTest {
|
|||
@Test
|
||||
public void testRetryableException() throws Exception {
|
||||
CountingException thrown =
|
||||
expectThrows(
|
||||
assertThrows(
|
||||
CountingException.class,
|
||||
() -> retrier.callWithRetry(new CountingThrower(3), CountingException.class));
|
||||
assertThat(thrown).hasMessageThat().contains("3");
|
||||
|
@ -92,7 +92,7 @@ public class RetrierTest {
|
|||
@Test
|
||||
public void testUnretryableException() throws Exception {
|
||||
CountingException thrown =
|
||||
expectThrows(
|
||||
assertThrows(
|
||||
CountingException.class,
|
||||
() -> retrier.callWithRetry(new CountingThrower(5), IllegalArgumentException.class));
|
||||
assertThat(thrown).hasMessageThat().contains("1");
|
||||
|
@ -107,7 +107,7 @@ public class RetrierTest {
|
|||
@Test
|
||||
public void testRetryFailed_withReporter() throws Exception {
|
||||
CountingException thrown =
|
||||
expectThrows(
|
||||
assertThrows(
|
||||
CountingException.class,
|
||||
() -> {
|
||||
TestReporter reporter = new TestReporter();
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
package google.registry.util;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
import static google.registry.util.SerializeUtils.deserialize;
|
||||
import static google.registry.util.SerializeUtils.serialize;
|
||||
|
||||
|
@ -51,14 +51,14 @@ public class SerializeUtilsTest {
|
|||
@Test
|
||||
public void testSerialize_objectDoesntImplementSerialize_hasInformativeError() throws Exception {
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(IllegalArgumentException.class, () -> serialize(new Lol()));
|
||||
assertThrows(IllegalArgumentException.class, () -> serialize(new Lol()));
|
||||
assertThat(thrown).hasMessageThat().contains("Unable to serialize: LOL_VALUE");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeserialize_badValue_hasInformativeError() throws Exception {
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> deserialize(String.class, new byte[] {(byte) 0xff}));
|
||||
assertThat(thrown).hasMessageThat().contains("Unable to deserialize: objectBytes=FF");
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
package google.registry.util;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
@ -49,7 +49,7 @@ public class SqlTemplateTest {
|
|||
@Test
|
||||
public void testFillSqlTemplate_substitutionButNoVariables() throws Exception {
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
assertThrows(
|
||||
IllegalArgumentException.class, () -> SqlTemplate.create("").put("ONE", "1").build());
|
||||
assertThat(thrown).hasMessageThat().contains("Not found in template: ONE");
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ public class SqlTemplateTest {
|
|||
@Test
|
||||
public void testFillSqlTemplate_substitutionButMissingVariables() throws Exception {
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> SqlTemplate.create("%ONE%").put("ONE", "1").put("TWO", "2").build());
|
||||
assertThat(thrown).hasMessageThat().contains("Not found in template: TWO");
|
||||
|
@ -66,7 +66,7 @@ public class SqlTemplateTest {
|
|||
@Test
|
||||
public void testFillSqlTemplate_sameKeyTwice_failsEarly() throws Exception {
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> SqlTemplate.create("%ONE%").put("ONE", "1").put("ONE", "2"));
|
||||
assertThat(thrown).hasMessageThat().contains("");
|
||||
|
@ -75,7 +75,7 @@ public class SqlTemplateTest {
|
|||
@Test
|
||||
public void testFillSqlTemplate_variablesButNotEnoughSubstitutions() throws Exception {
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> SqlTemplate.create("%ONE% %TWO%").put("ONE", "1").build());
|
||||
assertThat(thrown).hasMessageThat().contains("%TWO% found in template but no substitution");
|
||||
|
@ -84,7 +84,7 @@ public class SqlTemplateTest {
|
|||
@Test
|
||||
public void testFillSqlTemplate_mismatchedVariableAndSubstitution() throws Exception {
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> SqlTemplate.create("%TWO%").put("TOO", "2").build());
|
||||
assertThat(thrown).hasMessageThat().contains("%TWO% found in template but no substitution");
|
||||
|
@ -93,14 +93,14 @@ public class SqlTemplateTest {
|
|||
@Test
|
||||
public void testFillSqlTemplate_missingKeyVals_whatsThePoint() throws Exception {
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(IllegalArgumentException.class, () -> SqlTemplate.create("%TWO%").build());
|
||||
assertThrows(IllegalArgumentException.class, () -> SqlTemplate.create("%TWO%").build());
|
||||
assertThat(thrown).hasMessageThat().contains("%TWO% found in template but no substitution");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFillSqlTemplate_lowercaseKey_notAllowed() throws Exception {
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> SqlTemplate.create("%test%").put("test", "hello world").build());
|
||||
assertThat(thrown).hasMessageThat().contains("Bad substitution key: test");
|
||||
|
@ -109,7 +109,7 @@ public class SqlTemplateTest {
|
|||
@Test
|
||||
public void testFillSqlTemplate_substitution_disallowsSingleQuotes() throws Exception {
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> SqlTemplate.create("The words are '%LOS%' and baz").put("LOS", "foo'bar"));
|
||||
assertThat(thrown).hasMessageThat().contains("Illegal characters in foo'bar");
|
||||
|
@ -118,7 +118,7 @@ public class SqlTemplateTest {
|
|||
@Test
|
||||
public void testFillSqlTemplate_substitution_disallowsDoubleQuotes() throws Exception {
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> SqlTemplate.create("The words are '%LOS%' and baz").put("LOS", "foo\"bar"));
|
||||
assertThat(thrown).hasMessageThat().contains("Illegal characters in foo\"bar");
|
||||
|
@ -127,7 +127,7 @@ public class SqlTemplateTest {
|
|||
@Test
|
||||
public void testFillSqlTemplate_quoteMismatch_throwsError() throws Exception {
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
SqlTemplate.create("The words are \"%LOS%' and baz").put("LOS", "foobar").build());
|
||||
|
@ -137,7 +137,7 @@ public class SqlTemplateTest {
|
|||
@Test
|
||||
public void testFillSqlTemplate_extendedQuote_throwsError() throws Exception {
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
SqlTemplate.create("The words are '%LOS%-lol' and baz").put("LOS", "roid").build());
|
||||
|
|
|
@ -17,7 +17,6 @@ package google.registry.util;
|
|||
import static com.google.appengine.api.taskqueue.TaskOptions.Builder.withUrl;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
@ -93,7 +92,7 @@ public final class TaskEnqueuerTest {
|
|||
.thenThrow(new TransientFailureException("three"))
|
||||
.thenThrow(new TransientFailureException("four"));
|
||||
TransientFailureException thrown =
|
||||
expectThrows(TransientFailureException.class, () -> taskEnqueuer.enqueue(queue, task));
|
||||
assertThrows(TransientFailureException.class, () -> taskEnqueuer.enqueue(queue, task));
|
||||
assertThat(thrown).hasMessageThat().contains("three");
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@ package google.registry.util;
|
|||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
|
@ -63,7 +62,7 @@ public class TeeOutputStreamTest {
|
|||
public void testWriteInteger_failsAfterClose() throws Exception {
|
||||
OutputStream tee = new TeeOutputStream(asList(outputA));
|
||||
tee.close();
|
||||
IllegalStateException thrown = expectThrows(IllegalStateException.class, () -> tee.write(1));
|
||||
IllegalStateException thrown = assertThrows(IllegalStateException.class, () -> tee.write(1));
|
||||
assertThat(thrown).hasMessageThat().contains("outputstream closed");
|
||||
}
|
||||
|
||||
|
@ -72,7 +71,7 @@ public class TeeOutputStreamTest {
|
|||
OutputStream tee = new TeeOutputStream(asList(outputA));
|
||||
tee.close();
|
||||
IllegalStateException thrown =
|
||||
expectThrows(IllegalStateException.class, () -> tee.write("hello".getBytes(UTF_8)));
|
||||
assertThrows(IllegalStateException.class, () -> tee.write("hello".getBytes(UTF_8)));
|
||||
assertThat(thrown).hasMessageThat().contains("outputstream closed");
|
||||
}
|
||||
|
||||
|
@ -81,7 +80,7 @@ public class TeeOutputStreamTest {
|
|||
OutputStream tee = new TeeOutputStream(asList(outputA));
|
||||
tee.close();
|
||||
IllegalStateException thrown =
|
||||
expectThrows(IllegalStateException.class, () -> tee.write("hello".getBytes(UTF_8), 1, 3));
|
||||
assertThrows(IllegalStateException.class, () -> tee.write("hello".getBytes(UTF_8), 1, 3));
|
||||
assertThat(thrown).hasMessageThat().contains("outputstream closed");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
package google.registry.util;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
@ -36,7 +36,7 @@ public class TypeUtilsTest {
|
|||
@Test
|
||||
public void test_getClassFromString_notAssignableFrom() {
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> TypeUtils.getClassFromString("java.util.ArrayList", Integer.class));
|
||||
assertThat(thrown).hasMessageThat().contains("ArrayList does not implement/extend Integer");
|
||||
|
@ -45,7 +45,7 @@ public class TypeUtilsTest {
|
|||
@Test
|
||||
public void test_getClassFromString_unknownClass() {
|
||||
IllegalArgumentException thrown =
|
||||
expectThrows(
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> TypeUtils.getClassFromString("com.fake.company.nonexistent.Class", Object.class));
|
||||
assertThat(thrown)
|
||||
|
|
|
@ -18,7 +18,7 @@ import static com.google.common.net.HttpHeaders.CONTENT_LENGTH;
|
|||
import static com.google.common.net.HttpHeaders.CONTENT_TYPE;
|
||||
import static com.google.common.net.MediaType.CSV_UTF_8;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
import static google.registry.util.UrlFetchUtils.setPayloadMultipart;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.mockito.Matchers.any;
|
||||
|
@ -95,7 +95,7 @@ public class UrlFetchUtilsTest {
|
|||
HTTPRequest request = mock(HTTPRequest.class);
|
||||
String payload = "I screamed------------------------------AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHHH";
|
||||
IllegalStateException thrown =
|
||||
expectThrows(
|
||||
assertThrows(
|
||||
IllegalStateException.class,
|
||||
() -> setPayloadMultipart(request, "lol", "cat", CSV_UTF_8, payload));
|
||||
assertThat(thrown)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue