From 5f1b82343cb99caae29ce07f316b3b6b556c8b33 Mon Sep 17 00:00:00 2001 From: Pierre Date: Mon, 7 Dec 2020 17:47:23 +0100 Subject: fix multiple checked exceptions assertions on overall code --- .../org/sonar/db/profiling/InvocationUtilsTest.java | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/server/sonar-db-core/src/test/java/org/sonar/db/profiling/InvocationUtilsTest.java b/server/sonar-db-core/src/test/java/org/sonar/db/profiling/InvocationUtilsTest.java index 45bf5a1f0e1..a7d139023e7 100644 --- a/server/sonar-db-core/src/test/java/org/sonar/db/profiling/InvocationUtilsTest.java +++ b/server/sonar-db-core/src/test/java/org/sonar/db/profiling/InvocationUtilsTest.java @@ -19,8 +19,10 @@ */ package org.sonar.db.profiling; +import java.lang.reflect.Method; import java.sql.Connection; import java.sql.SQLException; +import org.junit.Assert; import org.junit.Test; import org.sonar.test.TestUtils; @@ -45,13 +47,9 @@ public class InvocationUtilsTest { Connection target = mock(Connection.class); String failSql = "any sql"; when(target.prepareStatement(failSql)).thenThrow(new SQLException("Expected")); + Method prepareStatement = Connection.class.getMethod("prepareStatement", String.class); - try { - InvocationUtils.invokeQuietly(target, Connection.class.getMethod("prepareStatement", String.class), new Object[] {failSql}); - fail(); - } catch (Throwable t) { - assertThat(t).isInstanceOf(SQLException.class); - } + Assert.assertThrows(SQLException.class, () -> InvocationUtils.invokeQuietly(target, prepareStatement, new Object[] {failSql})); } @Test @@ -59,13 +57,9 @@ public class InvocationUtilsTest { Connection target = mock(Connection.class); String failSql = "any sql"; when(target.prepareStatement(failSql)).thenThrow(new SQLException("Expected")); + Method wait = Object.class.getMethod("wait"); - try { - InvocationUtils.invokeQuietly(target, Object.class.getMethod("wait"), new Object[0]); - fail(); - } catch (Throwable t) { - assertThat(t).isInstanceOf(IllegalStateException.class); - } + Assert.assertThrows(IllegalStateException.class, () -> InvocationUtils.invokeQuietly(target, wait, new Object[0])); } @Test -- cgit v1.2.3