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:
mcilwain 2017-11-21 13:15:12 -08:00 committed by jianglai
parent f041b1bac0
commit c7484b25e0
13 changed files with 199 additions and 194 deletions

View file

@ -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();
}