From e02ee5b64761d7058d0f13bf0f0d2d0c98ce2d86 Mon Sep 17 00:00:00 2001 From: mcilwain Date: Wed, 25 Oct 2017 13:19:07 -0700 Subject: [PATCH] Use assertThrows() to avoid having empty catch blocks ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=173439894 --- .../util/ComparingInvocationHandlerTest.java | 23 ++++--------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/javatests/google/registry/util/ComparingInvocationHandlerTest.java b/javatests/google/registry/util/ComparingInvocationHandlerTest.java index 423c86037..88f1f6374 100644 --- a/javatests/google/registry/util/ComparingInvocationHandlerTest.java +++ b/javatests/google/registry/util/ComparingInvocationHandlerTest.java @@ -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.assertThrows; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -125,12 +125,7 @@ public class ComparingInvocationHandlerTest { when(myActualMock.func(3, "str")).thenThrow(myException); when(mySecondMock.func(3, "str")).thenReturn(SECOND_RESULT); - try { - comparator.func(3, "str"); - fail("Should have thrown MyException"); - } catch (MyException expected) { - } - + assertThrows(MyException.class, () -> comparator.func(3, "str")); assertThat(log) .containsExactly( String.format( @@ -162,12 +157,7 @@ public class ComparingInvocationHandlerTest { when(myActualMock.func(3, "str")).thenThrow(myException); when(mySecondMock.func(3, "str")).thenThrow(myOtherException); - try { - comparator.func(3, "str"); - fail("Should have thrown MyException"); - } catch (MyException expected) { - } - + assertThrows(MyException.class, () -> comparator.func(3, "str")); assertThat(log).isEmpty(); } @@ -179,12 +169,7 @@ public class ComparingInvocationHandlerTest { when(myActualMock.func(3, "str")).thenThrow(myException); when(mySecondMock.func(3, "str")).thenThrow(myOtherException); - try { - comparator.func(3, "str"); - fail("Should have thrown MyException"); - } catch (MyException expected) { - } - + assertThrows(MyException.class, () -> comparator.func(3, "str")); assertThat(log) .containsExactly( String.format(