mirror of
https://github.com/google/nomulus.git
synced 2025-05-15 00:47:11 +02:00
Automatically refactor more exception testing to use new JUnit rules
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=178911894
This commit is contained in:
parent
36ad38e5df
commit
7dc224627f
125 changed files with 1970 additions and 1982 deletions
|
@ -15,14 +15,13 @@
|
|||
package google.registry.util;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.testing.JUnitBackports.expectThrows;
|
||||
|
||||
import google.registry.testing.FakeClock;
|
||||
import google.registry.testing.FakeSleeper;
|
||||
import google.registry.util.Retrier.FailureReporter;
|
||||
import java.util.concurrent.Callable;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
|
@ -30,9 +29,6 @@ import org.junit.runners.JUnit4;
|
|||
@RunWith(JUnit4.class)
|
||||
public class RetrierTest {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
Retrier retrier = new Retrier(new FakeSleeper(new FakeClock()), 3);
|
||||
|
||||
/** An exception to throw from {@link CountingThrower}. */
|
||||
|
@ -86,16 +82,20 @@ public class RetrierTest {
|
|||
|
||||
@Test
|
||||
public void testRetryableException() throws Exception {
|
||||
thrown.expect(CountingException.class);
|
||||
thrown.expectMessage("3");
|
||||
retrier.callWithRetry(new CountingThrower(3), CountingException.class);
|
||||
CountingException thrown =
|
||||
expectThrows(
|
||||
CountingException.class,
|
||||
() -> retrier.callWithRetry(new CountingThrower(3), CountingException.class));
|
||||
assertThat(thrown).hasMessageThat().contains("3");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnretryableException() throws Exception {
|
||||
thrown.expect(CountingException.class);
|
||||
thrown.expectMessage("1");
|
||||
retrier.callWithRetry(new CountingThrower(5), IllegalArgumentException.class);
|
||||
CountingException thrown =
|
||||
expectThrows(
|
||||
CountingException.class,
|
||||
() -> retrier.callWithRetry(new CountingThrower(5), IllegalArgumentException.class));
|
||||
assertThat(thrown).hasMessageThat().contains("1");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -106,15 +106,19 @@ public class RetrierTest {
|
|||
|
||||
@Test
|
||||
public void testRetryFailed_withReporter() throws Exception {
|
||||
thrown.expect(CountingException.class);
|
||||
thrown.expectMessage("3");
|
||||
TestReporter reporter = new TestReporter();
|
||||
try {
|
||||
retrier.callWithRetry(new CountingThrower(3), reporter, CountingException.class);
|
||||
} catch (CountingException expected) {
|
||||
reporter.assertNumbers(2, 1);
|
||||
throw expected;
|
||||
}
|
||||
CountingException thrown =
|
||||
expectThrows(
|
||||
CountingException.class,
|
||||
() -> {
|
||||
TestReporter reporter = new TestReporter();
|
||||
try {
|
||||
retrier.callWithRetry(new CountingThrower(3), reporter, CountingException.class);
|
||||
} catch (CountingException expected) {
|
||||
reporter.assertNumbers(2, 1);
|
||||
throw expected;
|
||||
}
|
||||
});
|
||||
assertThat(thrown).hasMessageThat().contains("3");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue