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

panjuan 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 124b39314fe Refactor @Test(expected) to assert assertThrows on test 
modules (#24465)
124b39314fe is described below

commit 124b39314fecf4bcd5375eeb31e778460ddcf834
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Mar 5 14:34:43 2023 +0800

    Refactor @Test(expected) to assert assertThrows on test modules (#24465)
---
 .../proxy/backend/context/ProxyContextTest.java    | 13 ++++-----
 ...iscoveryRuleConfigurationImportCheckerTest.java | 31 +++++++++++-----------
 ...plittingRuleConfigurationImportCheckerTest.java | 27 ++++++++++---------
 ...ShardingRuleConfigurationImportCheckerTest.java | 17 ++++++------
 .../queryable/ShowDistVariableExecutorTest.java    |  5 ++--
 ...DistVariableUpdatableRALBackendHandlerTest.java | 13 ++++-----
 ...etDefaultSingleTableStorageUnitUpdaterTest.java |  5 ++--
 .../handler/admin/PostgreSQLCharacterSetsTest.java |  5 ++--
 .../proxy/arguments/BootstrapArgumentsTest.java    |  7 ++---
 .../proxy/database/DatabaseServerInfoTest.java     |  5 ++--
 .../frontend/state/impl/LockProxyStateTest.java    |  6 +++--
 .../postgresql/command/PortalContextTest.java      |  5 ++--
 12 files changed, 76 insertions(+), 63 deletions(-)

diff --git 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/context/ProxyContextTest.java
 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/context/ProxyContextTest.java
index ee9e90f118c..f7d90f16d29 100644
--- 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/context/ProxyContextTest.java
+++ 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/context/ProxyContextTest.java
@@ -41,6 +41,7 @@ import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNull;
+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;
@@ -83,17 +84,17 @@ public final class ProxyContextTest {
         assertFalse(ProxyContext.getInstance().databaseExists("db_1"));
     }
     
-    @Test(expected = NoDatabaseSelectedException.class)
+    @Test
     public void assertGetDatabaseWithNull() {
-        assertNull(ProxyContext.getInstance().getDatabase(null));
+        assertThrows(NoDatabaseSelectedException.class, () -> 
assertNull(ProxyContext.getInstance().getDatabase(null)));
     }
     
-    @Test(expected = NoDatabaseSelectedException.class)
+    @Test
     public void assertGetDatabaseWithEmptyString() {
-        assertNull(ProxyContext.getInstance().getDatabase(""));
+        assertThrows(NoDatabaseSelectedException.class, () -> 
assertNull(ProxyContext.getInstance().getDatabase("")));
     }
     
-    @Test(expected = NoDatabaseSelectedException.class)
+    @Test
     public void assertGetDatabaseWhenNotExisted() {
         Map<String, ShardingSphereDatabase> databases = mockDatabases();
         ContextManager contextManager = mock(ContextManager.class, 
RETURNS_DEEP_STUBS);
@@ -101,7 +102,7 @@ public final class ProxyContextTest {
                 new ShardingSphereMetaData(databases, 
mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new 
Properties())));
         
when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts);
         ProxyContext.init(contextManager);
-        ProxyContext.getInstance().getDatabase("db1");
+        assertThrows(NoDatabaseSelectedException.class, () -> 
ProxyContext.getInstance().getDatabase("db1"));
     }
     
     @Test
diff --git 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/DBDiscoveryRuleConfigurationImportCheckerTest.java
 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/DBDiscoveryRuleConfigurationImportCheckerTest.java
index 655889283ab..6780d6806a5 100644
--- 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/DBDiscoveryRuleConfigurationImportCheckerTest.java
+++ 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/DBDiscoveryRuleConfigurationImportCheckerTest.java
@@ -34,6 +34,7 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 
+import static org.junit.Assert.assertThrows;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
 import static org.mockito.Mockito.mock;
@@ -41,36 +42,36 @@ import static org.mockito.Mockito.when;
 
 public final class DBDiscoveryRuleConfigurationImportCheckerTest {
     
-    private final DatabaseDiscoveryRuleConfigurationImportChecker 
databaseDiscoveryRuleConfigurationImportChecker = new 
DatabaseDiscoveryRuleConfigurationImportChecker();
+    private final DatabaseDiscoveryRuleConfigurationImportChecker 
importChecker = new DatabaseDiscoveryRuleConfigurationImportChecker();
     
-    @Test(expected = MissingRequiredStorageUnitsException.class)
+    @Test
     public void assertCheckDataSources() {
         ShardingSphereDatabase database = mockDatabaseWithDataSource();
         DatabaseDiscoveryRuleConfiguration currentRuleConfig = 
getRuleConfigWithNotExistedDataSources();
-        databaseDiscoveryRuleConfigurationImportChecker.check(database, 
currentRuleConfig);
+        assertThrows(MissingRequiredStorageUnitsException.class, () -> 
importChecker.check(database, currentRuleConfig));
     }
     
-    @Test(expected = InvalidAlgorithmConfigurationException.class)
+    @Test
     public void assertCheckDiscoveryTypes() {
         ShardingSphereDatabase database = mockDatabase();
         DatabaseDiscoveryRuleConfiguration currentRuleConfig = 
createRuleConfigWithInvalidDiscoveryType();
-        databaseDiscoveryRuleConfigurationImportChecker.check(database, 
currentRuleConfig);
+        assertThrows(InvalidAlgorithmConfigurationException.class, () -> 
importChecker.check(database, currentRuleConfig));
     }
     
-    @Test(expected = MissingRequiredAlgorithmException.class)
+    @Test
     public void assertCheckDiscoveryHeartBeats() {
         ShardingSphereDatabase database = mockDatabase();
         DatabaseDiscoveryRuleConfiguration currentRuleConfig = 
createRuleConfigWithNotExistsHeartBeats();
-        databaseDiscoveryRuleConfigurationImportChecker.check(database, 
currentRuleConfig);
+        assertThrows(MissingRequiredAlgorithmException.class, () -> 
importChecker.check(database, currentRuleConfig));
     }
     
     private ShardingSphereDatabase mockDatabaseWithDataSource() {
-        ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, 
RETURNS_DEEP_STUBS);
+        ShardingSphereDatabase result = mock(ShardingSphereDatabase.class, 
RETURNS_DEEP_STUBS);
         Collection<String> dataSources = new LinkedList<>();
         dataSources.add("su_1");
-        
when(database.getResourceMetaData().getNotExistedDataSources(any())).thenReturn(dataSources);
-        
when(database.getRuleMetaData().getRules()).thenReturn(Collections.emptyList());
-        return database;
+        
when(result.getResourceMetaData().getNotExistedDataSources(any())).thenReturn(dataSources);
+        
when(result.getRuleMetaData().getRules()).thenReturn(Collections.emptyList());
+        return result;
     }
     
     private DatabaseDiscoveryRuleConfiguration 
getRuleConfigWithNotExistedDataSources() {
@@ -84,10 +85,10 @@ public final class 
DBDiscoveryRuleConfigurationImportCheckerTest {
     }
     
     private ShardingSphereDatabase mockDatabase() {
-        ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, 
RETURNS_DEEP_STUBS);
-        
when(database.getResourceMetaData().getNotExistedDataSources(any())).thenReturn(Collections.emptyList());
-        
when(database.getRuleMetaData().getRules()).thenReturn(Collections.emptyList());
-        return database;
+        ShardingSphereDatabase result = mock(ShardingSphereDatabase.class, 
RETURNS_DEEP_STUBS);
+        
when(result.getResourceMetaData().getNotExistedDataSources(any())).thenReturn(Collections.emptyList());
+        
when(result.getRuleMetaData().getRules()).thenReturn(Collections.emptyList());
+        return result;
     }
     
     private DatabaseDiscoveryRuleConfiguration 
createRuleConfigWithInvalidDiscoveryType() {
diff --git 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/ReadwriteSplittingRuleConfigurationImportCheckerTest.java
 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/ReadwriteSplittingRuleConfigurationImportCheckerTest.java
index 70c80e15f0c..155f6027cd1 100644
--- 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/ReadwriteSplittingRuleConfigurationImportCheckerTest.java
+++ 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/ReadwriteSplittingRuleConfigurationImportCheckerTest.java
@@ -33,6 +33,7 @@ import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.Map;
 
+import static org.junit.Assert.assertThrows;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
 import static org.mockito.Mockito.mock;
@@ -40,29 +41,29 @@ import static org.mockito.Mockito.when;
 
 public final class ReadwriteSplittingRuleConfigurationImportCheckerTest {
     
-    private final ReadwriteSplittingRuleConfigurationImportChecker 
readwriteRuleConfigurationImportChecker = new 
ReadwriteSplittingRuleConfigurationImportChecker();
+    private final ReadwriteSplittingRuleConfigurationImportChecker 
importChecker = new ReadwriteSplittingRuleConfigurationImportChecker();
     
-    @Test(expected = MissingRequiredStorageUnitsException.class)
+    @Test
     public void assertCheckDataSources() {
         ShardingSphereDatabase database = mockDatabaseWithDataSource();
         ReadwriteSplittingRuleConfiguration currentRuleConfig = 
getRuleConfigWithNotExistedDataSources();
-        readwriteRuleConfigurationImportChecker.check(database, 
currentRuleConfig);
+        assertThrows(MissingRequiredStorageUnitsException.class, () -> 
importChecker.check(database, currentRuleConfig));
     }
     
-    @Test(expected = InvalidAlgorithmConfigurationException.class)
+    @Test
     public void assertCheckLoadBalancers() {
         ShardingSphereDatabase database = mockDatabase();
         ReadwriteSplittingRuleConfiguration currentRuleConfig = 
createInvalidLoadBalancerRuleConfig();
-        readwriteRuleConfigurationImportChecker.check(database, 
currentRuleConfig);
+        assertThrows(InvalidAlgorithmConfigurationException.class, () -> 
importChecker.check(database, currentRuleConfig));
     }
     
     private ShardingSphereDatabase mockDatabaseWithDataSource() {
-        ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, 
RETURNS_DEEP_STUBS);
+        ShardingSphereDatabase result = mock(ShardingSphereDatabase.class, 
RETURNS_DEEP_STUBS);
         Collection<String> dataSources = new LinkedList<>();
         dataSources.add("su_1");
-        
when(database.getResourceMetaData().getNotExistedDataSources(any())).thenReturn(dataSources);
-        
when(database.getRuleMetaData().getRules()).thenReturn(Collections.emptyList());
-        return database;
+        
when(result.getResourceMetaData().getNotExistedDataSources(any())).thenReturn(dataSources);
+        
when(result.getRuleMetaData().getRules()).thenReturn(Collections.emptyList());
+        return result;
     }
     
     private ReadwriteSplittingRuleConfiguration 
getRuleConfigWithNotExistedDataSources() {
@@ -75,10 +76,10 @@ public final class 
ReadwriteSplittingRuleConfigurationImportCheckerTest {
     }
     
     private ShardingSphereDatabase mockDatabase() {
-        ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, 
RETURNS_DEEP_STUBS);
-        
when(database.getResourceMetaData().getNotExistedDataSources(any())).thenReturn(Collections.emptyList());
-        
when(database.getRuleMetaData().getRules()).thenReturn(Collections.emptyList());
-        return database;
+        ShardingSphereDatabase result = mock(ShardingSphereDatabase.class, 
RETURNS_DEEP_STUBS);
+        
when(result.getResourceMetaData().getNotExistedDataSources(any())).thenReturn(Collections.emptyList());
+        
when(result.getRuleMetaData().getRules()).thenReturn(Collections.emptyList());
+        return result;
     }
     
     private ReadwriteSplittingRuleConfiguration 
createInvalidLoadBalancerRuleConfig() {
diff --git 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/ShardingRuleConfigurationImportCheckerTest.java
 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/ShardingRuleConfigurationImportCheckerTest.java
index 221f159f493..222ee71bd7f 100644
--- 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/ShardingRuleConfigurationImportCheckerTest.java
+++ 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/ShardingRuleConfigurationImportCheckerTest.java
@@ -31,6 +31,7 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.LinkedList;
 
+import static org.junit.Assert.assertThrows;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
 import static org.mockito.Mockito.mock;
@@ -38,26 +39,26 @@ import static org.mockito.Mockito.when;
 
 public final class ShardingRuleConfigurationImportCheckerTest {
     
-    @Test(expected = DuplicateRuleException.class)
+    @Test
     public void assertCheckLogicTables() {
-        new 
ShardingRuleConfigurationImportChecker().check(mock(ShardingSphereDatabase.class),
 createDuplicatedTablesRuleConfiguration());
+        assertThrows(DuplicateRuleException.class, () -> new 
ShardingRuleConfigurationImportChecker().check(mock(ShardingSphereDatabase.class),
 createDuplicatedTablesRuleConfiguration()));
     }
     
-    @Test(expected = MissingRequiredStorageUnitsException.class)
+    @Test
     public void assertCheckDataSources() {
         ShardingRuleConfiguration currentRuleConfig = new 
ShardingRuleConfiguration();
         currentRuleConfig.getTables().add(new 
ShardingTableRuleConfiguration("t_order", "ds_${0..2}.t_order_${0..2}"));
-        new 
ShardingRuleConfigurationImportChecker().check(mockDatabaseWithDataSource(), 
currentRuleConfig);
+        assertThrows(MissingRequiredStorageUnitsException.class, () -> new 
ShardingRuleConfigurationImportChecker().check(mockDatabaseWithDataSource(), 
currentRuleConfig));
     }
     
-    @Test(expected = InvalidAlgorithmConfigurationException.class)
+    @Test
     public void assertCheckKeyGenerators() {
-        new ShardingRuleConfigurationImportChecker().check(mockDatabase(), 
createInvalidKeyGeneratorRuleConfiguration());
+        assertThrows(InvalidAlgorithmConfigurationException.class, () -> new 
ShardingRuleConfigurationImportChecker().check(mockDatabase(), 
createInvalidKeyGeneratorRuleConfiguration()));
     }
     
-    @Test(expected = InvalidAlgorithmConfigurationException.class)
+    @Test
     public void assertCheckShardingAlgorithms() {
-        new ShardingRuleConfigurationImportChecker().check(mockDatabase(), 
createInvalidShardingAlgorithmRuleConfiguration());
+        assertThrows(InvalidAlgorithmConfigurationException.class, () -> new 
ShardingRuleConfigurationImportChecker().check(mockDatabase(), 
createInvalidShardingAlgorithmRuleConfiguration()));
     }
     
     private ShardingRuleConfiguration 
createDuplicatedTablesRuleConfiguration() {
diff --git 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableExecutorTest.java
 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableExecutorTest.java
index 6e8041a5eac..31d41590edb 100644
--- 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableExecutorTest.java
+++ 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableExecutorTest.java
@@ -40,6 +40,7 @@ import java.util.Iterator;
 
 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;
@@ -116,8 +117,8 @@ public final class ShowDistVariableExecutorTest {
         assertThat(row.getCell(2), is("false"));
     }
     
-    @Test(expected = UnsupportedVariableException.class)
+    @Test
     public void assertExecuteWithInvalidVariableName() {
-        new ShowDistVariableExecutor().getRows(metaData, connectionSession, 
new ShowDistVariableStatement("wrong_name"));
+        assertThrows(UnsupportedVariableException.class, () -> new 
ShowDistVariableExecutor().getRows(metaData, connectionSession, new 
ShowDistVariableStatement("wrong_name")));
     }
 }
diff --git 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetDistVariableUpdatableRALBackendHandlerTest.java
 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetDistVariableUpdatableRALBackendHandlerTest.java
index 12f4177a763..fc67b20f789 100644
--- 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetDistVariableUpdatableRALBackendHandlerTest.java
+++ 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetDistVariableUpdatableRALBackendHandlerTest.java
@@ -36,6 +36,7 @@ import java.sql.SQLException;
 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.mock;
 
 public final class SetDistVariableUpdatableRALBackendHandlerTest {
@@ -76,17 +77,17 @@ public final class 
SetDistVariableUpdatableRALBackendHandlerTest {
         
assertThat(connectionSession.getTransactionStatus().getTransactionType(), 
is(TransactionType.LOCAL));
     }
     
-    @Test(expected = UnsupportedVariableException.class)
-    public void assertSwitchTransactionTypeFailed() throws SQLException {
+    @Test
+    public void assertSwitchTransactionTypeFailed() {
         connectionSession.setCurrentDatabase(String.format(DATABASE_PATTERN, 
0));
         UpdatableRALBackendHandler<?> handler = new 
UpdatableRALBackendHandler<>(new SetDistVariableStatement("transaction_type", 
"XXX"), connectionSession);
-        handler.execute();
+        assertThrows(UnsupportedVariableException.class, handler::execute);
     }
     
-    @Test(expected = UnsupportedVariableException.class)
-    public void assertNotSupportedVariable() throws SQLException {
+    @Test
+    public void assertNotSupportedVariable() {
         UpdatableRALBackendHandler<?> handler = new 
UpdatableRALBackendHandler<>(new SetDistVariableStatement("@@session", "XXX"), 
connectionSession);
-        handler.execute();
+        assertThrows(UnsupportedVariableException.class, handler::execute);
     }
     
     @Test
diff --git 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/rule/SetDefaultSingleTableStorageUnitUpdaterTest.java
 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/rule/SetDefaultSingleTableStorageUnitUpdaterTest.java
index 0a848deceaf..127aae67b48 100644
--- 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/rule/SetDefaultSingleTableStorageUnitUpdaterTest.java
+++ 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/rule/SetDefaultSingleTableStorageUnitUpdaterTest.java
@@ -34,6 +34,7 @@ import java.util.Collections;
 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.when;
 
@@ -54,9 +55,9 @@ public final class 
SetDefaultSingleTableStorageUnitUpdaterTest {
         
when(database.getResourceMetaData().getDataSources()).thenReturn(Collections.singletonMap("ds_0",
 new MockedDataSource()));
     }
     
-    @Test(expected = MissingRequiredStorageUnitsException.class)
+    @Test
     public void assertCheckWithInvalidResource() {
-        updater.checkSQLStatement(database, new 
SetDefaultSingleTableStorageUnitStatement("ds_1"), currentConfig);
+        assertThrows(MissingRequiredStorageUnitsException.class, () -> 
updater.checkSQLStatement(database, new 
SetDefaultSingleTableStorageUnitStatement("ds_1"), currentConfig));
     }
     
     @Test
diff --git 
a/proxy/backend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLCharacterSetsTest.java
 
b/proxy/backend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLCharacterSetsTest.java
index 44240a820a5..8054dc3065e 100644
--- 
a/proxy/backend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLCharacterSetsTest.java
+++ 
b/proxy/backend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLCharacterSetsTest.java
@@ -24,6 +24,7 @@ import java.nio.charset.UnsupportedCharsetException;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertThrows;
 
 public final class PostgreSQLCharacterSetsTest {
     
@@ -42,8 +43,8 @@ public final class PostgreSQLCharacterSetsTest {
         assertThat(PostgreSQLCharacterSets.findCharacterSet("'utf-8'"), 
is(StandardCharsets.UTF_8));
     }
     
-    @Test(expected = UnsupportedCharsetException.class)
+    @Test
     public void assertFindUnsupportedCharset() {
-        PostgreSQLCharacterSets.findCharacterSet("unknown_charset");
+        assertThrows(UnsupportedCharsetException.class, () -> 
PostgreSQLCharacterSets.findCharacterSet("unknown_charset"));
     }
 }
diff --git 
a/proxy/bootstrap/src/test/java/org/apache/shardingsphere/proxy/arguments/BootstrapArgumentsTest.java
 
b/proxy/bootstrap/src/test/java/org/apache/shardingsphere/proxy/arguments/BootstrapArgumentsTest.java
index 42ef462702b..f092b57c663 100644
--- 
a/proxy/bootstrap/src/test/java/org/apache/shardingsphere/proxy/arguments/BootstrapArgumentsTest.java
+++ 
b/proxy/bootstrap/src/test/java/org/apache/shardingsphere/proxy/arguments/BootstrapArgumentsTest.java
@@ -24,8 +24,9 @@ import java.util.Collections;
 import java.util.Optional;
 
 import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertFalse;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 
 public final class BootstrapArgumentsTest {
@@ -35,9 +36,9 @@ public final class BootstrapArgumentsTest {
         assertFalse(new BootstrapArguments(new 
String[]{}).getPort().isPresent());
     }
     
-    @Test(expected = IllegalArgumentException.class)
+    @Test
     public void assertGetPortWithWrongArgument() {
-        new BootstrapArguments(new String[]{"WrongArgument"}).getPort();
+        assertThrows(IllegalArgumentException.class, () -> new 
BootstrapArguments(new String[]{"WrongArgument"}).getPort());
     }
     
     @Test
diff --git 
a/proxy/bootstrap/src/test/java/org/apache/shardingsphere/proxy/database/DatabaseServerInfoTest.java
 
b/proxy/bootstrap/src/test/java/org/apache/shardingsphere/proxy/database/DatabaseServerInfoTest.java
index 66736a3e8b5..3424eb9b179 100644
--- 
a/proxy/bootstrap/src/test/java/org/apache/shardingsphere/proxy/database/DatabaseServerInfoTest.java
+++ 
b/proxy/bootstrap/src/test/java/org/apache/shardingsphere/proxy/database/DatabaseServerInfoTest.java
@@ -30,6 +30,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.when;
 
@@ -39,10 +40,10 @@ public final class DatabaseServerInfoTest {
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
     private DataSource dataSource;
     
-    @Test(expected = DatabaseServerLoadingServerException.class)
+    @Test
     public void assertNewInstanceFailure() throws SQLException {
         when(dataSource.getConnection()).thenThrow(SQLException.class);
-        new DatabaseServerInfo(dataSource);
+        assertThrows(DatabaseServerLoadingServerException.class, () -> new 
DatabaseServerInfo(dataSource));
     }
     
     @Test
diff --git 
a/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/state/impl/LockProxyStateTest.java
 
b/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/state/impl/LockProxyStateTest.java
index fab030cb335..bf53c4ed66b 100644
--- 
a/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/state/impl/LockProxyStateTest.java
+++ 
b/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/state/impl/LockProxyStateTest.java
@@ -20,10 +20,12 @@ package org.apache.shardingsphere.proxy.frontend.state.impl;
 import 
org.apache.shardingsphere.infra.util.exception.external.sql.type.generic.UnsupportedSQLOperationException;
 import org.junit.Test;
 
+import static org.junit.Assert.assertThrows;
+
 public final class LockProxyStateTest {
     
-    @Test(expected = UnsupportedSQLOperationException.class)
+    @Test
     public void assertExecute() {
-        new LockProxyState().execute(null, null, null, null);
+        assertThrows(UnsupportedSQLOperationException.class, () -> new 
LockProxyState().execute(null, null, null, null));
     }
 }
diff --git 
a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PortalContextTest.java
 
b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PortalContextTest.java
index 20097f129c5..45c0da8b55f 100644
--- 
a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PortalContextTest.java
+++ 
b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PortalContextTest.java
@@ -24,6 +24,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;
@@ -49,12 +50,12 @@ public final class PortalContextTest {
         assertThat(portalContext.get(portalName), is(portal));
     }
     
-    @Test(expected = IllegalStateException.class)
+    @Test
     public void assertAddDuplicateNamedPortal() throws SQLException {
         Portal portal = mock(Portal.class);
         when(portal.getName()).thenReturn("P_1");
         portalContext.add(portal);
-        portalContext.add(portal);
+        assertThrows(IllegalStateException.class, () -> 
portalContext.add(portal));
     }
     
     @Test

Reply via email to