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.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