mirror of
https://github.com/google/nomulus.git
synced 2025-08-03 00:12:11 +02:00
Automatically refactor some exception testing to use new JUnit rules
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=176550995
This commit is contained in:
parent
f041b1bac0
commit
c7484b25e0
13 changed files with 199 additions and 194 deletions
|
@ -14,6 +14,8 @@
|
|||
|
||||
package google.registry.util;
|
||||
|
||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.net.InetAddresses;
|
||||
import com.google.common.testing.NullPointerTester;
|
||||
|
@ -289,12 +291,7 @@ public class CidrAddressBlockTest extends TestCase {
|
|||
Iterator<InetAddress> i = b2.iterator();
|
||||
i.next();
|
||||
i.next();
|
||||
try {
|
||||
// Let's run off the end and expect an IllegalArgumentException.
|
||||
i.next();
|
||||
fail();
|
||||
} catch (NoSuchElementException expected) {
|
||||
}
|
||||
assertThrows(NoSuchElementException.class, () -> i.next());
|
||||
}
|
||||
|
||||
public void testSerializability() {
|
||||
|
@ -310,18 +307,10 @@ public class CidrAddressBlockTest extends TestCase {
|
|||
}
|
||||
|
||||
private static void assertConstructionFails(String ip) {
|
||||
try {
|
||||
new CidrAddressBlock(ip);
|
||||
fail();
|
||||
} catch (IllegalArgumentException expected) {
|
||||
}
|
||||
assertThrows(IllegalArgumentException.class, () -> new CidrAddressBlock(ip));
|
||||
}
|
||||
|
||||
private static void assertConstructionFails(String ip, int netmask) {
|
||||
try {
|
||||
new CidrAddressBlock(ip, netmask);
|
||||
fail();
|
||||
} catch (IllegalArgumentException expected) {
|
||||
}
|
||||
assertThrows(IllegalArgumentException.class, () -> new CidrAddressBlock(ip, netmask));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
package google.registry.util;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Functions;
|
||||
|
@ -51,18 +51,17 @@ public class ConcurrentTest {
|
|||
|
||||
@Test
|
||||
public void testTransform_throwsException_isSinglyWrappedByUee() throws Exception {
|
||||
try {
|
||||
Concurrent.transform(
|
||||
ImmutableList.of(1, 2, 3),
|
||||
input -> {
|
||||
throw new RuntimeException("hello");
|
||||
});
|
||||
fail("Didn't throw!");
|
||||
} catch (UncheckedExecutionException e) {
|
||||
// We can't use ExpectedException because root cause must be one level of indirection away.
|
||||
assertThat(e).hasCauseThat().isInstanceOf(RuntimeException.class);
|
||||
assertThat(e).hasCauseThat().hasMessageThat().isEqualTo("hello");
|
||||
}
|
||||
UncheckedExecutionException e =
|
||||
expectThrows(
|
||||
UncheckedExecutionException.class,
|
||||
() ->
|
||||
Concurrent.transform(
|
||||
ImmutableList.of(1, 2, 3),
|
||||
input -> {
|
||||
throw new RuntimeException("hello");
|
||||
}));
|
||||
assertThat(e).hasCauseThat().isInstanceOf(RuntimeException.class);
|
||||
assertThat(e).hasCauseThat().hasMessageThat().isEqualTo("hello");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue