mirror of
https://github.com/google/nomulus.git
synced 2025-05-31 01:34:05 +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
|
@ -15,7 +15,7 @@
|
|||
package google.registry.request.lock;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
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;
|
||||
|
@ -100,12 +100,11 @@ public final class LockHandlerImplTest {
|
|||
public void testLockSucceeds_uncheckedException() throws Exception {
|
||||
Lock lock = mock(Lock.class);
|
||||
Exception expectedException = new RuntimeException("test");
|
||||
try {
|
||||
executeWithLocks(new ThrowingCallable(expectedException), lock);
|
||||
fail("Expected RuntimeException");
|
||||
} catch (RuntimeException exception) {
|
||||
assertThat(exception).isSameAs(expectedException);
|
||||
}
|
||||
RuntimeException exception =
|
||||
expectThrows(
|
||||
RuntimeException.class,
|
||||
() -> executeWithLocks(new ThrowingCallable(expectedException), lock));
|
||||
assertThat(exception).isSameAs(expectedException);
|
||||
verify(lock, times(1)).release();
|
||||
}
|
||||
|
||||
|
@ -113,12 +112,11 @@ public final class LockHandlerImplTest {
|
|||
public void testLockSucceeds_checkedException() throws Exception {
|
||||
Lock lock = mock(Lock.class);
|
||||
Exception expectedException = new Exception("test");
|
||||
try {
|
||||
executeWithLocks(new ThrowingCallable(expectedException), lock);
|
||||
fail("Expected RuntimeException");
|
||||
} catch (RuntimeException exception) {
|
||||
assertThat(exception).hasCauseThat().isSameAs(expectedException);
|
||||
}
|
||||
RuntimeException exception =
|
||||
expectThrows(
|
||||
RuntimeException.class,
|
||||
() -> executeWithLocks(new ThrowingCallable(expectedException), lock));
|
||||
assertThat(exception).hasCauseThat().isSameAs(expectedException);
|
||||
verify(lock, times(1)).release();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue