This is an automated email from the ASF dual-hosted git repository.

sunnianjun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new aecd37ae897 Refactor @Test(expected) to assert assertThrows on kernel 
modules (#24466)
aecd37ae897 is described below

commit aecd37ae897d49e8b50d4e5cf905958ad5aed050
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Mar 5 15:03:38 2023 +0800

    Refactor @Test(expected) to assert assertThrows on kernel modules (#24466)
---
 .../datasource/PipelineDataSourceWrapperTest.java  | 17 +++--
 ...MatchDataConsistencyCalculateAlgorithmTest.java |  5 +-
 .../datasource/MySQLDataSourceCheckerTest.java     | 17 +++--
 .../mysql/ingest/client/MySQLClientTest.java       |  5 +-
 .../netty/MySQLBinlogEventPacketDecoderTest.java   |  5 +-
 .../client/netty/MySQLNegotiateHandlerTest.java    |  5 +-
 .../netty/MySQLNegotiatePackageDecoderTest.java    |  5 +-
 .../ingest/wal/decode/MppdbDecodingPluginTest.java |  9 ++-
 .../PostgreSQLDataSourceCheckerTest.java           |  5 +-
 .../ingest/PostgreSQLPositionInitializerTest.java  |  5 +-
 .../wal/PostgreSQLLogicalReplicationTest.java      |  5 +-
 .../ingest/wal/WALEventConverterTest.java          |  7 +-
 .../ingest/wal/decode/TestDecodingPluginTest.java  |  9 ++-
 .../engine/SingleStandardRouteEngineTest.java      |  5 +-
 .../ddl/SingleDropSchemaMetaDataValidatorTest.java | 11 ++-
 .../result/SQLFederationResultSetTest.java         | 85 +++++++++++-----------
 .../sqltranslator/rule/SQLTranslatorRuleTest.java  |  6 +-
 .../AlterTrafficRuleStatementUpdaterTest.java      | 11 ++-
 .../transaction/core/ResourceDataSourceTest.java   |  5 +-
 ...eataATShardingSphereTransactionManagerTest.java |  9 ++-
 .../manager/BitronixRecoveryResourceTest.java      |  7 +-
 21 files changed, 132 insertions(+), 106 deletions(-)

diff --git 
a/kernel/data-pipeline/api/src/test/java/org/apache/shardingsphere/data/pipeline/api/datasource/PipelineDataSourceWrapperTest.java
 
b/kernel/data-pipeline/api/src/test/java/org/apache/shardingsphere/data/pipeline/api/datasource/PipelineDataSourceWrapperTest.java
index 30081042456..09dff3b41aa 100644
--- 
a/kernel/data-pipeline/api/src/test/java/org/apache/shardingsphere/data/pipeline/api/datasource/PipelineDataSourceWrapperTest.java
+++ 
b/kernel/data-pipeline/api/src/test/java/org/apache/shardingsphere/data/pipeline/api/datasource/PipelineDataSourceWrapperTest.java
@@ -32,6 +32,7 @@ import java.util.logging.Logger;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertThrows;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.when;
@@ -94,27 +95,27 @@ public final class PipelineDataSourceWrapperTest {
         assertThat(actual, is(parentLogger));
     }
     
-    @Test(expected = SQLException.class)
+    @Test
     public void assertSetLoginTimeoutFailure() throws SQLException {
         doThrow(new 
SQLException("")).when(dataSource).setLoginTimeout(LOGIN_TIMEOUT);
-        new PipelineDataSourceWrapper(dataSource, new 
H2DatabaseType()).setLoginTimeout(LOGIN_TIMEOUT);
+        assertThrows(SQLException.class, () -> new 
PipelineDataSourceWrapper(dataSource, new 
H2DatabaseType()).setLoginTimeout(LOGIN_TIMEOUT));
     }
     
-    @Test(expected = SQLException.class)
+    @Test
     public void assertSetLogWriterFailure() throws SQLException {
         doThrow(new 
SQLException("")).when(dataSource).setLogWriter(printWriter);
-        new PipelineDataSourceWrapper(dataSource, new 
H2DatabaseType()).setLogWriter(printWriter);
+        assertThrows(SQLException.class, () -> new 
PipelineDataSourceWrapper(dataSource, new 
H2DatabaseType()).setLogWriter(printWriter));
     }
     
-    @Test(expected = SQLException.class)
+    @Test
     public void assertCloseExceptionFailure() throws Exception {
         doThrow(new Exception("")).when((AutoCloseable) dataSource).close();
-        new PipelineDataSourceWrapper(dataSource, new 
H2DatabaseType()).close();
+        assertThrows(SQLException.class, () -> new 
PipelineDataSourceWrapper(dataSource, new H2DatabaseType()).close());
     }
     
-    @Test(expected = SQLException.class)
+    @Test
     public void assertCloseSQLExceptionFailure() throws Exception {
         doThrow(new SQLException("")).when((AutoCloseable) dataSource).close();
-        new PipelineDataSourceWrapper(dataSource, new 
H2DatabaseType()).close();
+        assertThrows(SQLException.class, () -> new 
PipelineDataSourceWrapper(dataSource, new H2DatabaseType()).close());
     }
 }
diff --git 
a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/check/consistency/algorithm/CRC32MatchDataConsistencyCalculateAlgorithmTest.java
 
b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/check/consistency/algorithm/CRC32MatchDataConsistencyCalculateAlgorithmTest.java
index f0ab95487b4..e0e47943879 100644
--- 
a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/check/consistency/algorithm/CRC32MatchDataConsistencyCalculateAlgorithmTest.java
+++ 
b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/check/consistency/algorithm/CRC32MatchDataConsistencyCalculateAlgorithmTest.java
@@ -41,6 +41,7 @@ import java.util.Iterator;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThrows;
 import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
 import static org.mockito.Mockito.anyString;
 import static org.mockito.Mockito.mock;
@@ -85,9 +86,9 @@ public final class 
CRC32MatchDataConsistencyCalculateAlgorithmTest {
         return result;
     }
     
-    @Test(expected = 
PipelineTableDataConsistencyCheckLoadingFailedException.class)
+    @Test
     public void assertCalculateFailed() throws SQLException {
         when(connection.prepareStatement(anyString())).thenThrow(new 
SQLException());
-        new CRC32MatchDataConsistencyCalculateAlgorithm().calculate(parameter);
+        
assertThrows(PipelineTableDataConsistencyCheckLoadingFailedException.class, () 
-> new CRC32MatchDataConsistencyCalculateAlgorithm().calculate(parameter));
     }
 }
diff --git 
a/kernel/data-pipeline/dialect/mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/check/datasource/MySQLDataSourceCheckerTest.java
 
b/kernel/data-pipeline/dialect/mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/check/datasource/MySQLDataSourceCheckerTest.java
index e34dec61e30..55cbbaee8a2 100644
--- 
a/kernel/data-pipeline/dialect/mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/check/datasource/MySQLDataSourceCheckerTest.java
+++ 
b/kernel/data-pipeline/dialect/mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/check/datasource/MySQLDataSourceCheckerTest.java
@@ -33,6 +33,7 @@ import java.sql.SQLException;
 import java.util.Collection;
 import java.util.Collections;
 
+import static org.junit.Assert.assertThrows;
 import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
 import static org.mockito.Mockito.mock;
@@ -75,15 +76,15 @@ public final class MySQLDataSourceCheckerTest {
         verify(preparedStatement).executeQuery();
     }
     
-    @Test(expected = PrepareJobWithoutEnoughPrivilegeException.class)
+    @Test
     public void assertCheckPrivilegeLackPrivileges() {
-        new MySQLDataSourceChecker().checkPrivilege(dataSources);
+        assertThrows(PrepareJobWithoutEnoughPrivilegeException.class, () -> 
new MySQLDataSourceChecker().checkPrivilege(dataSources));
     }
     
-    @Test(expected = PrepareJobWithCheckPrivilegeFailedException.class)
+    @Test
     public void assertCheckPrivilegeFailure() throws SQLException {
         when(resultSet.next()).thenThrow(new SQLException(""));
-        new MySQLDataSourceChecker().checkPrivilege(dataSources);
+        assertThrows(PrepareJobWithCheckPrivilegeFailedException.class, () -> 
new MySQLDataSourceChecker().checkPrivilege(dataSources));
     }
     
     @Test
@@ -94,16 +95,16 @@ public final class MySQLDataSourceCheckerTest {
         verify(preparedStatement, times(3)).executeQuery();
     }
     
-    @Test(expected = PrepareJobWithInvalidSourceDataSourceException.class)
+    @Test
     public void assertCheckVariableWithWrongVariable() throws SQLException {
         when(resultSet.next()).thenReturn(true, true);
         when(resultSet.getString(2)).thenReturn("OFF", "ROW");
-        new MySQLDataSourceChecker().checkVariable(dataSources);
+        assertThrows(PrepareJobWithInvalidSourceDataSourceException.class, () 
-> new MySQLDataSourceChecker().checkVariable(dataSources));
     }
     
-    @Test(expected = PrepareJobWithCheckPrivilegeFailedException.class)
+    @Test
     public void assertCheckVariableFailure() throws SQLException {
         when(resultSet.next()).thenThrow(new SQLException(""));
-        new MySQLDataSourceChecker().checkVariable(dataSources);
+        assertThrows(PrepareJobWithCheckPrivilegeFailedException.class, () -> 
new MySQLDataSourceChecker().checkVariable(dataSources));
     }
 }
diff --git 
a/kernel/data-pipeline/dialect/mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/client/MySQLClientTest.java
 
b/kernel/data-pipeline/dialect/mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/client/MySQLClientTest.java
index 841f0c4413a..eea5e386dfa 100644
--- 
a/kernel/data-pipeline/dialect/mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/client/MySQLClientTest.java
+++ 
b/kernel/data-pipeline/dialect/mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/client/MySQLClientTest.java
@@ -43,6 +43,7 @@ import java.util.concurrent.atomic.AtomicInteger;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
@@ -155,10 +156,10 @@ public final class MySQLClientTest {
         assertFalse(channel.isOpen());
     }
     
-    @Test(expected = BinlogSyncChannelAlreadyClosedException.class)
+    @Test
     public void assertPollFailed() throws ReflectiveOperationException {
         
Plugins.getMemberAccessor().set(MySQLClient.class.getDeclaredField("channel"), 
mysqlClient, channel);
         
Plugins.getMemberAccessor().set(MySQLClient.class.getDeclaredField("running"), 
mysqlClient, false);
-        mysqlClient.poll();
+        assertThrows(BinlogSyncChannelAlreadyClosedException.class, () -> 
mysqlClient.poll());
     }
 }
diff --git 
a/kernel/data-pipeline/dialect/mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/client/netty/MySQLBinlogEventPacketDecoderTest.java
 
b/kernel/data-pipeline/dialect/mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/client/netty/MySQLBinlogEventPacketDecoderTest.java
index 54e1666e7c2..3193c6fe6c1 100644
--- 
a/kernel/data-pipeline/dialect/mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/client/netty/MySQLBinlogEventPacketDecoderTest.java
+++ 
b/kernel/data-pipeline/dialect/mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/client/netty/MySQLBinlogEventPacketDecoderTest.java
@@ -49,6 +49,7 @@ import java.util.concurrent.ConcurrentHashMap;
 import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.when;
 
@@ -76,13 +77,13 @@ public final class MySQLBinlogEventPacketDecoderTest {
                 new 
MySQLBinlogColumnDef(MySQLBinaryColumnType.MYSQL_TYPE_VARCHAR), new 
MySQLBinlogColumnDef(MySQLBinaryColumnType.MYSQL_TYPE_NEWDECIMAL));
     }
     
-    @Test(expected = RuntimeException.class)
+    @Test
     public void assertDecodeWithPacketError() {
         ByteBuf byteBuf = Unpooled.buffer();
         byteBuf.writeByte(1);
         byteBuf.writeByte(255);
         byteBuf.writeBytes(new byte[20]);
-        binlogEventPacketDecoder.decode(channelHandlerContext, byteBuf, null);
+        assertThrows(RuntimeException.class, () -> 
binlogEventPacketDecoder.decode(channelHandlerContext, byteBuf, null));
     }
     
     @Test
diff --git 
a/kernel/data-pipeline/dialect/mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/client/netty/MySQLNegotiateHandlerTest.java
 
b/kernel/data-pipeline/dialect/mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/client/netty/MySQLNegotiateHandlerTest.java
index 19c420f909a..b8d738944bb 100644
--- 
a/kernel/data-pipeline/dialect/mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/client/netty/MySQLNegotiateHandlerTest.java
+++ 
b/kernel/data-pipeline/dialect/mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/client/netty/MySQLNegotiateHandlerTest.java
@@ -40,6 +40,7 @@ import org.mockito.junit.MockitoJUnitRunner;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThrows;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
@@ -94,9 +95,9 @@ public final class MySQLNegotiateHandlerTest {
         verify(authResultCallback).setSuccess(serverInfo);
     }
     
-    @Test(expected = RuntimeException.class)
+    @Test
     public void assertChannelReadErrorPacket() {
         MySQLErrPacket errorPacket = new 
MySQLErrPacket(MySQLVendorError.ER_NO_DB_ERROR);
-        mysqlNegotiateHandler.channelRead(channelHandlerContext, errorPacket);
+        assertThrows(RuntimeException.class, () -> 
mysqlNegotiateHandler.channelRead(channelHandlerContext, errorPacket));
     }
 }
diff --git 
a/kernel/data-pipeline/dialect/mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/client/netty/MySQLNegotiatePackageDecoderTest.java
 
b/kernel/data-pipeline/dialect/mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/client/netty/MySQLNegotiatePackageDecoderTest.java
index f7f7c1d2c34..33166784e6c 100644
--- 
a/kernel/data-pipeline/dialect/mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/client/netty/MySQLNegotiatePackageDecoderTest.java
+++ 
b/kernel/data-pipeline/dialect/mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/client/netty/MySQLNegotiatePackageDecoderTest.java
@@ -40,6 +40,7 @@ import java.util.List;
 import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertThrows;
 import static org.mockito.Mockito.when;
 
 @RunWith(MockitoJUnitRunner.class)
@@ -56,10 +57,10 @@ public final class MySQLNegotiatePackageDecoderTest {
         
when(channelHandlerContext.channel().attr(CommonConstants.CHARSET_ATTRIBUTE_KEY).get()).thenReturn(StandardCharsets.UTF_8);
     }
     
-    @Test(expected = IllegalArgumentException.class)
+    @Test
     public void assertDecodeUnsupportedProtocolVersion() {
         MySQLNegotiatePackageDecoder commandPacketDecoder = new 
MySQLNegotiatePackageDecoder();
-        commandPacketDecoder.decode(channelHandlerContext, byteBuf, null);
+        assertThrows(IllegalArgumentException.class, () -> 
commandPacketDecoder.decode(channelHandlerContext, byteBuf, null));
     }
     
     @Test
diff --git 
a/kernel/data-pipeline/dialect/opengauss/src/test/java/org/apache/shardingsphere/data/pipeline/opengauss/ingest/wal/decode/MppdbDecodingPluginTest.java
 
b/kernel/data-pipeline/dialect/opengauss/src/test/java/org/apache/shardingsphere/data/pipeline/opengauss/ingest/wal/decode/MppdbDecodingPluginTest.java
index d26c789655f..2030a435838 100644
--- 
a/kernel/data-pipeline/dialect/opengauss/src/test/java/org/apache/shardingsphere/data/pipeline/opengauss/ingest/wal/decode/MppdbDecodingPluginTest.java
+++ 
b/kernel/data-pipeline/dialect/opengauss/src/test/java/org/apache/shardingsphere/data/pipeline/opengauss/ingest/wal/decode/MppdbDecodingPluginTest.java
@@ -46,6 +46,7 @@ import java.util.stream.IntStream;
 import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
@@ -209,7 +210,7 @@ public final class MppdbDecodingPluginTest {
         assertThat(new MppdbDecodingPlugin(null).decode(data, 
logSequenceNumber), instanceOf(PlaceholderEvent.class));
     }
     
-    @Test(expected = IngestException.class)
+    @Test
     public void assertDecodeUnknownRowEventType() {
         MppTableData tableData = new MppTableData();
         tableData.setTableName("public.test");
@@ -218,10 +219,10 @@ public final class MppdbDecodingPluginTest {
         tableData.setColumnsType(new String[]{"character varying"});
         tableData.setColumnsVal(new String[]{"1 2 3"});
         ByteBuffer data = ByteBuffer.wrap(toJSON(tableData).getBytes());
-        new MppdbDecodingPlugin(null).decode(data, logSequenceNumber);
+        assertThrows(IngestException.class, () -> new 
MppdbDecodingPlugin(null).decode(data, logSequenceNumber));
     }
     
-    @Test(expected = DecodingException.class)
+    @Test
     public void assertDecodeTime() throws SQLException {
         MppTableData tableData = new MppTableData();
         tableData.setTableName("public.test");
@@ -232,7 +233,7 @@ public final class MppdbDecodingPluginTest {
         TimestampUtils timestampUtils = mock(TimestampUtils.class);
         when(timestampUtils.toTime(null, "1 2 3")).thenThrow(new 
SQLException(""));
         ByteBuffer data = ByteBuffer.wrap(toJSON(tableData).getBytes());
-        new MppdbDecodingPlugin(new OpenGaussTimestampUtils(timestampUtils), 
true).decode(data, logSequenceNumber);
+        assertThrows(DecodingException.class, () -> new 
MppdbDecodingPlugin(new OpenGaussTimestampUtils(timestampUtils), 
true).decode(data, logSequenceNumber));
     }
     
     @Test
diff --git 
a/kernel/data-pipeline/dialect/postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/check/datasource/PostgreSQLDataSourceCheckerTest.java
 
b/kernel/data-pipeline/dialect/postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/check/datasource/PostgreSQLDataSourceCheckerTest.java
index e0d6b60c2b3..afe8d4d141c 100644
--- 
a/kernel/data-pipeline/dialect/postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/check/datasource/PostgreSQLDataSourceCheckerTest.java
+++ 
b/kernel/data-pipeline/dialect/postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/check/datasource/PostgreSQLDataSourceCheckerTest.java
@@ -32,6 +32,7 @@ import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.Collections;
 
+import static org.junit.Assert.assertThrows;
 import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.Mockito.atLeastOnce;
 import static org.mockito.Mockito.verify;
@@ -83,12 +84,12 @@ public final class PostgreSQLDataSourceCheckerTest {
         verify(resultSet, atLeastOnce()).getString("rolreplication");
     }
     
-    @Test(expected = PrepareJobWithoutEnoughPrivilegeException.class)
+    @Test
     public void asserCheckNoPrivilege() throws SQLException {
         PostgreSQLDataSourceChecker dataSourceChecker = new 
PostgreSQLDataSourceChecker();
         when(resultSet.getString("rolsuper")).thenReturn("f");
         when(resultSet.getString("rolreplication")).thenReturn("f");
-        
dataSourceChecker.checkPrivilege(Collections.singletonList(dataSource));
+        assertThrows(PrepareJobWithoutEnoughPrivilegeException.class, () -> 
dataSourceChecker.checkPrivilege(Collections.singletonList(dataSource)));
         verify(resultSet, atLeastOnce()).getString("rolreplication");
     }
 }
diff --git 
a/kernel/data-pipeline/dialect/postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/PostgreSQLPositionInitializerTest.java
 
b/kernel/data-pipeline/dialect/postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/PostgreSQLPositionInitializerTest.java
index d51b39f9310..c7ed8a55b30 100644
--- 
a/kernel/data-pipeline/dialect/postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/PostgreSQLPositionInitializerTest.java
+++ 
b/kernel/data-pipeline/dialect/postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/PostgreSQLPositionInitializerTest.java
@@ -35,6 +35,7 @@ import java.sql.SQLException;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertThrows;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
@@ -85,12 +86,12 @@ public final class PostgreSQLPositionInitializerTest {
         assertThat(actual.getLogSequenceNumber().get(), 
is(LogSequenceNumber.valueOf(POSTGRESQL_10_LSN)));
     }
     
-    @Test(expected = RuntimeException.class)
+    @Test
     public void assertGetCurrentPositionThrowException() throws SQLException {
         mockSlotExistsOrNot(false);
         when(databaseMetaData.getDatabaseMajorVersion()).thenReturn(9);
         when(databaseMetaData.getDatabaseMinorVersion()).thenReturn(4);
-        new PostgreSQLPositionInitializer().init(dataSource, "");
+        assertThrows(RuntimeException.class, () -> new 
PostgreSQLPositionInitializer().init(dataSource, ""));
     }
     
     @SneakyThrows(SQLException.class)
diff --git 
a/kernel/data-pipeline/dialect/postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/wal/PostgreSQLLogicalReplicationTest.java
 
b/kernel/data-pipeline/dialect/postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/wal/PostgreSQLLogicalReplicationTest.java
index ae2292a62cc..9c9cd966d6a 100644
--- 
a/kernel/data-pipeline/dialect/postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/wal/PostgreSQLLogicalReplicationTest.java
+++ 
b/kernel/data-pipeline/dialect/postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/wal/PostgreSQLLogicalReplicationTest.java
@@ -37,6 +37,7 @@ import java.sql.Connection;
 import java.sql.SQLException;
 
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThrows;
 import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.verify;
@@ -86,10 +87,10 @@ public final class PostgreSQLLogicalReplicationTest {
         verify(chainedLogicalStreamBuilder).start();
     }
     
-    @Test(expected = SQLException.class)
+    @Test
     @SneakyThrows(SQLException.class)
     public void assertCreateReplicationStreamFailure() {
         when(connection.unwrap(PGConnection.class)).thenThrow(new 
SQLException(""));
-        logicalReplication.createReplicationStream(connection, "", new 
PostgreSQLLogSequenceNumber(LogSequenceNumber.valueOf(100L)));
+        assertThrows(SQLException.class, () -> 
logicalReplication.createReplicationStream(connection, "", new 
PostgreSQLLogSequenceNumber(LogSequenceNumber.valueOf(100L))));
     }
 }
diff --git 
a/kernel/data-pipeline/dialect/postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/wal/WALEventConverterTest.java
 
b/kernel/data-pipeline/dialect/postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/wal/WALEventConverterTest.java
index a516a76b312..bc7d70317f8 100644
--- 
a/kernel/data-pipeline/dialect/postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/wal/WALEventConverterTest.java
+++ 
b/kernel/data-pipeline/dialect/postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/wal/WALEventConverterTest.java
@@ -54,6 +54,7 @@ import java.util.Collections;
 import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 
 public final class WALEventConverterTest {
@@ -147,10 +148,10 @@ public final class WALEventConverterTest {
         assertThat(record, instanceOf(PlaceholderRecord.class));
     }
     
-    @Test(expected = UnsupportedSQLOperationException.class)
+    @Test
     public void assertConvertFailure() {
-        walEventConverter.convert(new AbstractRowEvent() {
-        });
+        assertThrows(UnsupportedSQLOperationException.class, () -> 
walEventConverter.convert(new AbstractRowEvent() {
+        }));
     }
     
     private AbstractRowEvent mockWriteRowEvent() {
diff --git 
a/kernel/data-pipeline/dialect/postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/wal/decode/TestDecodingPluginTest.java
 
b/kernel/data-pipeline/dialect/postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/wal/decode/TestDecodingPluginTest.java
index 1c6a88ffe7a..6c6ab26e0fd 100644
--- 
a/kernel/data-pipeline/dialect/postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/wal/decode/TestDecodingPluginTest.java
+++ 
b/kernel/data-pipeline/dialect/postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/wal/decode/TestDecodingPluginTest.java
@@ -35,6 +35,7 @@ import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThrows;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -92,19 +93,19 @@ public final class TestDecodingPluginTest {
         assertThat(new TestDecodingPlugin(null).decode(data, 
logSequenceNumber), instanceOf(PlaceholderEvent.class));
     }
     
-    @Test(expected = IngestException.class)
+    @Test
     public void assertDecodeUnknownRowEventType() {
         ByteBuffer data = ByteBuffer.wrap("table public.test: UNKNOWN: 
data[character varying]:'1 2 3'''".getBytes());
-        new TestDecodingPlugin(null).decode(data, logSequenceNumber);
+        assertThrows(IngestException.class, () -> new 
TestDecodingPlugin(null).decode(data, logSequenceNumber));
     }
     
-    @Test(expected = DecodingException.class)
+    @Test
     @SneakyThrows(SQLException.class)
     public void assertDecodeTime() {
         TimestampUtils timestampUtils = mock(TimestampUtils.class);
         when(timestampUtils.toTime(null, "1 2 3'")).thenThrow(new 
SQLException(""));
         ByteBuffer data = ByteBuffer.wrap("table public.test: INSERT: 
data[time without time zone]:'1 2 3'''".getBytes());
-        new TestDecodingPlugin(new 
PostgreSQLTimestampUtils(timestampUtils)).decode(data, logSequenceNumber);
+        assertThrows(DecodingException.class, () -> new TestDecodingPlugin(new 
PostgreSQLTimestampUtils(timestampUtils)).decode(data, logSequenceNumber));
     }
     
     @Test
diff --git 
a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/route/engine/SingleStandardRouteEngineTest.java
 
b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/route/engine/SingleStandardRouteEngineTest.java
index 6ecaf20d85c..5e2a6030abb 100644
--- 
a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/route/engine/SingleStandardRouteEngineTest.java
+++ 
b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/route/engine/SingleStandardRouteEngineTest.java
@@ -49,6 +49,7 @@ import java.util.Optional;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertThrows;
 import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
@@ -126,10 +127,10 @@ public final class SingleStandardRouteEngineTest {
         return result;
     }
     
-    @Test(expected = TableExistsException.class)
+    @Test
     public void assertRouteDuplicateSingleTable() {
         SingleStandardRouteEngine engine = new 
SingleStandardRouteEngine(Collections.singletonList(new 
QualifiedTable(DefaultDatabase.LOGIC_NAME, "t_order")), mockStatement(false));
-        engine.route(new RouteContext(), mockSingleRule());
+        assertThrows(TableExistsException.class, () -> engine.route(new 
RouteContext(), mockSingleRule()));
     }
     
     @Test
diff --git 
a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/route/validator/ddl/SingleDropSchemaMetaDataValidatorTest.java
 
b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/route/validator/ddl/SingleDropSchemaMetaDataValidatorTest.java
index 1a757017ec1..5e5563787bc 100644
--- 
a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/route/validator/ddl/SingleDropSchemaMetaDataValidatorTest.java
+++ 
b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/route/validator/ddl/SingleDropSchemaMetaDataValidatorTest.java
@@ -32,22 +32,25 @@ import org.junit.Test;
 
 import java.util.Collections;
 
+import static org.junit.Assert.assertThrows;
 import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
 public final class SingleDropSchemaMetaDataValidatorTest {
     
-    @Test(expected = DropNotEmptySchemaException.class)
+    @Test
     public void assertValidateWithoutCascadeSchema() {
-        new 
SingleDropSchemaMetaDataValidator().validate(mock(SingleRule.class, 
RETURNS_DEEP_STUBS), createSQLStatementContext("foo_schema", false), 
mockDatabase());
+        assertThrows(DropNotEmptySchemaException.class,
+                () -> new 
SingleDropSchemaMetaDataValidator().validate(mock(SingleRule.class, 
RETURNS_DEEP_STUBS), createSQLStatementContext("foo_schema", false), 
mockDatabase()));
     }
     
-    @Test(expected = SchemaNotFoundException.class)
+    @Test
     public void assertValidateWithNotExistedSchema() {
         ShardingSphereDatabase database = mockDatabase();
         when(database.getSchema("not_existed_schema")).thenReturn(null);
-        new 
SingleDropSchemaMetaDataValidator().validate(mock(SingleRule.class, 
RETURNS_DEEP_STUBS), createSQLStatementContext("not_existed_schema", true), 
database);
+        assertThrows(SchemaNotFoundException.class,
+                () -> new 
SingleDropSchemaMetaDataValidator().validate(mock(SingleRule.class, 
RETURNS_DEEP_STUBS), createSQLStatementContext("not_existed_schema", true), 
database));
     }
     
     @Test
diff --git 
a/kernel/sql-federation/executor/advanced/src/test/java/org/apache/shardingsphere/sqlfederation/advanced/result/SQLFederationResultSetTest.java
 
b/kernel/sql-federation/executor/advanced/src/test/java/org/apache/shardingsphere/sqlfederation/advanced/result/SQLFederationResultSetTest.java
index 8da7c6dab2e..b1694c94784 100644
--- 
a/kernel/sql-federation/executor/advanced/src/test/java/org/apache/shardingsphere/sqlfederation/advanced/result/SQLFederationResultSetTest.java
+++ 
b/kernel/sql-federation/executor/advanced/src/test/java/org/apache/shardingsphere/sqlfederation/advanced/result/SQLFederationResultSetTest.java
@@ -53,6 +53,7 @@ import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
 import static org.mockito.Mockito.mock;
@@ -358,88 +359,88 @@ public final class SQLFederationResultSetTest {
         assertThat(federationResultSet.getTimestamp("order_id", 
Calendar.getInstance()), is(new Timestamp(0L)));
     }
     
-    @Test(expected = SQLFeatureNotSupportedException.class)
-    public void assertGetAsciiStreamWithColumnIndex() throws SQLException {
+    @Test
+    public void assertGetAsciiStreamWithColumnIndex() {
         when(enumerator.current()).thenReturn(new 
Object[]{mock(InputStream.class), 1, "OK", 1});
         federationResultSet.next();
-        assertThat(federationResultSet.getAsciiStream(1), 
instanceOf(InputStream.class));
+        assertThrows(SQLFeatureNotSupportedException.class, () -> 
federationResultSet.getAsciiStream(1));
     }
     
-    @Test(expected = SQLFeatureNotSupportedException.class)
-    public void assertGetAsciiStreamWithColumnLabel() throws SQLException {
+    @Test
+    public void assertGetAsciiStreamWithColumnLabel() {
         when(enumerator.current()).thenReturn(new 
Object[]{mock(InputStream.class), 1, "OK", 1});
         federationResultSet.next();
-        assertThat(federationResultSet.getAsciiStream("order_id"), 
instanceOf(InputStream.class));
+        assertThrows(SQLFeatureNotSupportedException.class, () -> 
federationResultSet.getAsciiStream("order_id"));
     }
     
-    @Test(expected = SQLFeatureNotSupportedException.class)
-    public void assertGetUnicodeStreamWithColumnIndex() throws SQLException {
+    @Test
+    public void assertGetUnicodeStreamWithColumnIndex() {
         when(enumerator.current()).thenReturn(new 
Object[]{mock(InputStream.class), 1, "OK", 1});
         federationResultSet.next();
-        assertThat(federationResultSet.getUnicodeStream(1), 
instanceOf(InputStream.class));
+        assertThrows(SQLFeatureNotSupportedException.class, () -> 
federationResultSet.getUnicodeStream(1));
     }
     
-    @Test(expected = SQLFeatureNotSupportedException.class)
-    public void assertGetUnicodeStreamWithColumnLabel() throws SQLException {
+    @Test
+    public void assertGetUnicodeStreamWithColumnLabel() {
         when(enumerator.current()).thenReturn(new 
Object[]{mock(InputStream.class), 1, "OK", 1});
         federationResultSet.next();
-        assertThat(federationResultSet.getUnicodeStream("order_id"), 
instanceOf(InputStream.class));
+        assertThrows(SQLFeatureNotSupportedException.class, () -> 
federationResultSet.getUnicodeStream("order_id"));
     }
     
-    @Test(expected = SQLFeatureNotSupportedException.class)
-    public void assertGetBinaryStreamWithColumnIndex() throws SQLException {
+    @Test
+    public void assertGetBinaryStreamWithColumnIndex() {
         when(enumerator.current()).thenReturn(new 
Object[]{mock(InputStream.class), 1, "OK", 1});
         federationResultSet.next();
-        assertThat(federationResultSet.getBinaryStream(1), 
instanceOf(InputStream.class));
+        assertThrows(SQLFeatureNotSupportedException.class, () -> 
federationResultSet.getBinaryStream(1));
     }
     
-    @Test(expected = SQLFeatureNotSupportedException.class)
-    public void assertGetBinaryStreamWithColumnLabel() throws SQLException {
+    @Test
+    public void assertGetBinaryStreamWithColumnLabel() {
         when(enumerator.current()).thenReturn(new 
Object[]{mock(InputStream.class), 1, "OK", 1});
         federationResultSet.next();
-        assertThat(federationResultSet.getBinaryStream("order_id"), 
instanceOf(InputStream.class));
+        assertThrows(SQLFeatureNotSupportedException.class, () -> 
federationResultSet.getBinaryStream("order_id"));
     }
     
-    @Test(expected = SQLFeatureNotSupportedException.class)
-    public void assertGetCharacterStreamWithColumnIndex() throws SQLException {
+    @Test
+    public void assertGetCharacterStreamWithColumnIndex() {
         when(enumerator.current()).thenReturn(new Object[]{mock(Reader.class), 
1, "OK", 1});
         federationResultSet.next();
-        federationResultSet.getCharacterStream(1);
+        assertThrows(SQLFeatureNotSupportedException.class, () -> 
federationResultSet.getCharacterStream(1));
     }
     
-    @Test(expected = SQLFeatureNotSupportedException.class)
-    public void assertGetCharacterStreamWithColumnLabel() throws SQLException {
+    @Test
+    public void assertGetCharacterStreamWithColumnLabel() {
         when(enumerator.current()).thenReturn(new Object[]{mock(Reader.class), 
1, "OK", 1});
         federationResultSet.next();
-        federationResultSet.getCharacterStream("order_id");
+        assertThrows(SQLFeatureNotSupportedException.class, () -> 
federationResultSet.getCharacterStream("order_id"));
     }
     
-    @Test(expected = SQLFeatureNotSupportedException.class)
-    public void assertGetBlobWithColumnIndex() throws SQLException {
+    @Test
+    public void assertGetBlobWithColumnIndex() {
         when(enumerator.current()).thenReturn(new Object[]{mock(Blob.class), 
1, "OK", 1});
         federationResultSet.next();
-        federationResultSet.getBlob(1);
+        assertThrows(SQLFeatureNotSupportedException.class, () -> 
federationResultSet.getBlob(1));
     }
     
-    @Test(expected = SQLFeatureNotSupportedException.class)
-    public void assertGetBlobWithColumnLabel() throws SQLException {
+    @Test
+    public void assertGetBlobWithColumnLabel() {
         when(enumerator.current()).thenReturn(new Object[]{mock(Blob.class), 
1, "OK", 1});
         federationResultSet.next();
-        federationResultSet.getBlob("order_id");
+        assertThrows(SQLFeatureNotSupportedException.class, () -> 
federationResultSet.getBlob("order_id"));
     }
     
-    @Test(expected = SQLFeatureNotSupportedException.class)
-    public void assertGetClobWithColumnIndex() throws SQLException {
+    @Test
+    public void assertGetClobWithColumnIndex() {
         when(enumerator.current()).thenReturn(new Object[]{mock(Clob.class), 
1, "OK", 1});
         federationResultSet.next();
-        federationResultSet.getClob(1);
+        assertThrows(SQLFeatureNotSupportedException.class, () -> 
federationResultSet.getClob(1));
     }
     
-    @Test(expected = SQLFeatureNotSupportedException.class)
-    public void assertGetClobWithColumnLabel() throws SQLException {
+    @Test
+    public void assertGetClobWithColumnLabel() {
         when(enumerator.current()).thenReturn(new Object[]{mock(Clob.class), 
1, "OK", 1});
         federationResultSet.next();
-        federationResultSet.getClob("order_id");
+        assertThrows(SQLFeatureNotSupportedException.class, () -> 
federationResultSet.getClob("order_id"));
     }
     
     @Test
@@ -470,18 +471,18 @@ public final class SQLFederationResultSetTest {
         assertThat(federationResultSet.getURL("order_id"), is(new 
URL("http://xxx.xxx";)));
     }
     
-    @Test(expected = SQLFeatureNotSupportedException.class)
-    public void assertGetSQLXMLWithColumnIndex() throws SQLException {
+    @Test
+    public void assertGetSQLXMLWithColumnIndex() {
         when(enumerator.current()).thenReturn(new Object[]{mock(SQLXML.class), 
1, "OK", 1});
         federationResultSet.next();
-        federationResultSet.getSQLXML(1);
+        assertThrows(SQLFeatureNotSupportedException.class, () -> 
federationResultSet.getSQLXML(1));
     }
     
-    @Test(expected = SQLFeatureNotSupportedException.class)
-    public void assertGetSQLXMLWithColumnLabel() throws SQLException {
+    @Test
+    public void assertGetSQLXMLWithColumnLabel() {
         when(enumerator.current()).thenReturn(new Object[]{mock(SQLXML.class), 
1, "OK", 1});
         federationResultSet.next();
-        federationResultSet.getSQLXML("order_id");
+        assertThrows(SQLFeatureNotSupportedException.class, () -> 
federationResultSet.getSQLXML("order_id"));
     }
     
     @After
diff --git 
a/kernel/sql-translator/core/src/test/java/org/apache/shardingsphere/sqltranslator/rule/SQLTranslatorRuleTest.java
 
b/kernel/sql-translator/core/src/test/java/org/apache/shardingsphere/sqltranslator/rule/SQLTranslatorRuleTest.java
index 9e701e8a4f5..6d730828149 100644
--- 
a/kernel/sql-translator/core/src/test/java/org/apache/shardingsphere/sqltranslator/rule/SQLTranslatorRuleTest.java
+++ 
b/kernel/sql-translator/core/src/test/java/org/apache/shardingsphere/sqltranslator/rule/SQLTranslatorRuleTest.java
@@ -27,6 +27,7 @@ import java.util.Locale;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertThrows;
 
 public final class SQLTranslatorRuleTest {
     
@@ -59,9 +60,10 @@ public final class SQLTranslatorRuleTest {
         assertThat(actual, is(expected));
     }
     
-    @Test(expected = UnsupportedTranslatedDatabaseException.class)
+    @Test
     public void assertNotUseOriginalSQLWhenTranslatingFailed() {
-        new SQLTranslatorRule(new 
SQLTranslatorRuleConfiguration("ALWAYS_FAILED", false)).translate("", null, new 
PostgreSQLDatabaseType(), new MySQLDatabaseType());
+        assertThrows(UnsupportedTranslatedDatabaseException.class,
+                () -> new SQLTranslatorRule(new 
SQLTranslatorRuleConfiguration("ALWAYS_FAILED", false)).translate("", null, new 
PostgreSQLDatabaseType(), new MySQLDatabaseType()));
     }
     
     @Test
diff --git 
a/kernel/traffic/distsql/handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/update/AlterTrafficRuleStatementUpdaterTest.java
 
b/kernel/traffic/distsql/handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/update/AlterTrafficRuleStatementUpdaterTest.java
index 8782d305412..6e6bc62b7e3 100644
--- 
a/kernel/traffic/distsql/handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/update/AlterTrafficRuleStatementUpdaterTest.java
+++ 
b/kernel/traffic/distsql/handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/update/AlterTrafficRuleStatementUpdaterTest.java
@@ -36,23 +36,26 @@ import java.util.Properties;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThrows;
 
 public final class AlterTrafficRuleStatementUpdaterTest {
     
-    @Test(expected = MissingRequiredRuleException.class)
+    @Test
     public void assertExecuteWithNotExistRuleName() {
         TrafficRuleSegment trafficRuleSegment = new TrafficRuleSegment(
                 "rule_name_3", Arrays.asList("olap", "order_by"), new 
AlgorithmSegment("DISTSQL.FIXTURE", new Properties()), new 
AlgorithmSegment("DISTSQL.FIXTURE", new Properties()));
         AlterTrafficRuleStatementUpdater updater = new 
AlterTrafficRuleStatementUpdater();
-        updater.checkSQLStatement(createTrafficRuleConfiguration(), new 
AlterTrafficRuleStatement(Collections.singleton(trafficRuleSegment)));
+        assertThrows(MissingRequiredRuleException.class,
+                () -> 
updater.checkSQLStatement(createTrafficRuleConfiguration(), new 
AlterTrafficRuleStatement(Collections.singleton(trafficRuleSegment))));
     }
     
-    @Test(expected = InvalidAlgorithmConfigurationException.class)
+    @Test
     public void assertExecuteWithInvalidAlgorithmType() {
         TrafficRuleSegment trafficRuleSegment = new TrafficRuleSegment(
                 "rule_name_1", Arrays.asList("olap", "order_by"), new 
AlgorithmSegment("invalid", new Properties()), new AlgorithmSegment("invalid", 
new Properties()));
         AlterTrafficRuleStatementUpdater updater = new 
AlterTrafficRuleStatementUpdater();
-        updater.checkSQLStatement(createTrafficRuleConfiguration(), new 
AlterTrafficRuleStatement(Collections.singleton(trafficRuleSegment)));
+        assertThrows(InvalidAlgorithmConfigurationException.class,
+                () -> 
updater.checkSQLStatement(createTrafficRuleConfiguration(), new 
AlterTrafficRuleStatement(Collections.singleton(trafficRuleSegment))));
     }
     
     @Test
diff --git 
a/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/core/ResourceDataSourceTest.java
 
b/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/core/ResourceDataSourceTest.java
index 2f3871e6b96..337e5c5f690 100644
--- 
a/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/core/ResourceDataSourceTest.java
+++ 
b/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/core/ResourceDataSourceTest.java
@@ -25,6 +25,7 @@ import java.util.regex.Pattern;
 import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 
 public final class ResourceDataSourceTest {
@@ -48,8 +49,8 @@ public final class ResourceDataSourceTest {
         return pattern.matcher(resourceId).matches();
     }
     
-    @Test(expected = IllegalStateException.class)
+    @Test
     public void assertDataSourceNameOnlyFailure() {
-        new ResourceDataSource(DATA_SOURCE_NAME, new MockedDataSource());
+        assertThrows(IllegalStateException.class, () -> new 
ResourceDataSource(DATA_SOURCE_NAME, new MockedDataSource()));
     }
 }
diff --git 
a/kernel/transaction/type/base/seata-at/src/test/java/org/apache/shardingsphere/transaction/base/seata/at/SeataATShardingSphereTransactionManagerTest.java
 
b/kernel/transaction/type/base/seata-at/src/test/java/org/apache/shardingsphere/transaction/base/seata/at/SeataATShardingSphereTransactionManagerTest.java
index 9359becfa98..babbea093a3 100644
--- 
a/kernel/transaction/type/base/seata-at/src/test/java/org/apache/shardingsphere/transaction/base/seata/at/SeataATShardingSphereTransactionManagerTest.java
+++ 
b/kernel/transaction/type/base/seata-at/src/test/java/org/apache/shardingsphere/transaction/base/seata/at/SeataATShardingSphereTransactionManagerTest.java
@@ -54,6 +54,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
 import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 
 public final class SeataATShardingSphereTransactionManagerTest {
@@ -136,10 +137,10 @@ public final class 
SeataATShardingSphereTransactionManagerTest {
         assertResult();
     }
     
-    @Test(expected = IllegalStateException.class)
+    @Test
     public void assertCommitWithoutBegin() {
         
SeataTransactionHolder.set(GlobalTransactionContext.getCurrentOrCreate());
-        seataTransactionManager.commit(false);
+        assertThrows(IllegalStateException.class, () -> 
seataTransactionManager.commit(false));
     }
     
     @Test
@@ -150,10 +151,10 @@ public final class 
SeataATShardingSphereTransactionManagerTest {
         assertResult();
     }
     
-    @Test(expected = IllegalStateException.class)
+    @Test
     public void assertRollbackWithoutBegin() {
         
SeataTransactionHolder.set(GlobalTransactionContext.getCurrentOrCreate());
-        seataTransactionManager.rollback();
+        assertThrows(IllegalStateException.class, 
seataTransactionManager::rollback);
     }
     
     private void assertResult() {
diff --git 
a/kernel/transaction/type/xa/provider/bitronix/src/test/java/org/apache/shardingsphere/transaction/xa/bitronix/manager/BitronixRecoveryResourceTest.java
 
b/kernel/transaction/type/xa/provider/bitronix/src/test/java/org/apache/shardingsphere/transaction/xa/bitronix/manager/BitronixRecoveryResourceTest.java
index 01f49d3d04b..0999ffc9f19 100644
--- 
a/kernel/transaction/type/xa/provider/bitronix/src/test/java/org/apache/shardingsphere/transaction/xa/bitronix/manager/BitronixRecoveryResourceTest.java
+++ 
b/kernel/transaction/type/xa/provider/bitronix/src/test/java/org/apache/shardingsphere/transaction/xa/bitronix/manager/BitronixRecoveryResourceTest.java
@@ -32,9 +32,10 @@ import javax.transaction.xa.XAResource;
 import java.sql.SQLException;
 
 import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertNotNull;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThrows;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
@@ -81,10 +82,10 @@ public final class BitronixRecoveryResourceTest {
         verify(xaConnection, times(0)).close();
     }
     
-    @Test(expected = SQLException.class)
+    @Test
     public void assertRecoveryWhenSQLExceptionIsThrown() throws SQLException {
         when(xaDataSource.getXAConnection()).thenThrow(new SQLException());
-        bitronixRecoveryResource.startRecovery();
+        assertThrows(SQLException.class, () -> 
bitronixRecoveryResource.startRecovery());
     }
     
     @Test

Reply via email to