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 4c7ab1c787e Refactor @Test(expected) to assert assertThrows on infra
modules (#24462)
4c7ab1c787e is described below
commit 4c7ab1c787e7f15749a824f6a0e298bc8944a43c
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Mar 5 13:30:25 2023 +0800
Refactor @Test(expected) to assert assertThrows on infra modules (#24462)
---
.../projection/engine/ProjectionEngineTest.java | 6 ++--
.../binder/segment/table/TablesContextTest.java | 11 +++---
.../dialect/MariaDBDataSourceMetaDataTest.java | 5 +--
.../dialect/MySQLDataSourceMetaDataTest.java | 7 ++--
.../dialect/OpenGaussDataSourceMetaDataTest.java | 7 ++--
.../dialect/OracleDataSourceMetaDataTest.java | 5 +--
.../dialect/PostgreSQLDataSourceMetaDataTest.java | 7 ++--
.../dialect/SQL92DataSourceMetaDataTest.java | 7 ++--
.../dialect/SQLServerDataSourceMetaDataTest.java | 5 +--
.../metadata/url/StandardJdbcUrlParserTest.java | 5 +--
.../database/type/DatabaseTypeEngineTest.java | 5 +--
.../type/dialect/PostgreSQLDatabaseTypeTest.java | 7 ++--
.../infra/datanode/DataNodeTest.java | 21 ++++++------
.../shardingsphere/infra/hint/HintManagerTest.java | 7 ++--
.../builder/SystemSchemaBuilderRuleTest.java | 7 ++--
.../user/yaml/swapper/YamlUserSwapperTest.java | 7 ++--
.../engine/ExecutorExceptionHandlerTest.java | 13 ++++----
.../engine/jdbc/JDBCExecutorCallbackTest.java | 7 ++--
.../type/memory/JDBCMemoryQueryResultTest.java | 7 ++--
.../type/stream/JDBCStreamQueryResultTest.java | 11 +++---
.../driver/jdbc/type/util/ResultSetUtilTest.java | 29 ++++++++--------
.../impl/local/LocalDataMergedResultTest.java | 10 +++---
.../result/impl/memory/MemoryMergedResultTest.java | 39 +++++++++++-----------
.../impl/memory/MemoryQueryResultRowTest.java | 17 +++++-----
.../result/impl/stream/StreamMergedResultTest.java | 9 ++---
.../infra/route/engine/SQLRouteEngineTest.java | 7 ++--
.../exception/ShardingSpherePreconditionsTest.java | 14 ++++----
.../infra/util/props/TypedPropertiesTest.java | 5 +--
.../infra/util/props/TypedPropertyValueTest.java | 19 ++++++-----
.../util/spi/ShardingSphereServiceLoaderTest.java | 11 +++---
.../util/spi/type/typed/TypedSPILoaderTest.java | 5 +--
.../infra/util/yaml/YamlEngineTest.java | 5 +--
.../ShardingSphereYamlConstructorTest.java | 7 ++--
33 files changed, 184 insertions(+), 150 deletions(-)
diff --git
a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/engine/ProjectionEngineTest.java
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/engine/ProjectionEngineTest.java
index 05599e75d83..9ebd7ee8814 100644
---
a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/engine/ProjectionEngineTest.java
+++
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/projection/engine/ProjectionEngineTest.java
@@ -68,6 +68,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;
@@ -202,14 +203,15 @@ public final class ProjectionEngineTest {
assertThat(iterator.next(), is(new ColumnProjection("t_customer",
"customer_id", null)));
}
- @Test(expected = SchemaNotFoundException.class)
+ @Test
public void assertCreateProjectionWithNotExistedSchema() {
SimpleTableSegment tableSegment = mock(SimpleTableSegment.class,
RETURNS_DEEP_STUBS);
OwnerSegment ownerSegment = mock(OwnerSegment.class,
RETURNS_DEEP_STUBS);
when(tableSegment.getOwner()).thenReturn(Optional.of(ownerSegment));
when(ownerSegment.getIdentifier().getValue()).thenReturn("public");
ShorthandProjectionSegment shorthandProjectionSegment = new
ShorthandProjectionSegment(0, 0);
- new ProjectionEngine(DefaultDatabase.LOGIC_NAME,
Collections.singletonMap(DefaultDatabase.LOGIC_NAME, schema),
databaseType).createProjection(tableSegment, shorthandProjectionSegment);
+ assertThrows(SchemaNotFoundException.class, () -> new ProjectionEngine(
+ DefaultDatabase.LOGIC_NAME,
Collections.singletonMap(DefaultDatabase.LOGIC_NAME, schema),
databaseType).createProjection(tableSegment, shorthandProjectionSegment));
}
@Test
diff --git
a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/table/TablesContextTest.java
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/table/TablesContextTest.java
index 0798fc2deec..a6c5b984a5c 100644
---
a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/table/TablesContextTest.java
+++
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/table/TablesContextTest.java
@@ -38,8 +38,9 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
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;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -214,22 +215,22 @@ public final class TablesContextTest {
assertThat(tablesContext.getDatabaseName().get(), is("sharding_db_1"));
}
- @Test(expected = IllegalStateException.class)
+ @Test
public void assertGetSchemaNameWithDifferentSchemaAndSameTable() {
SimpleTableSegment tableSegment1 = createTableSegment("table_1",
"tbl_1");
tableSegment1.setOwner(new OwnerSegment(0, 0, new
IdentifierValue("sharding_db_1")));
SimpleTableSegment tableSegment2 = createTableSegment("table_1",
"tbl_1");
tableSegment2.setOwner(new OwnerSegment(0, 0, new
IdentifierValue("sharding_db_2")));
- new TablesContext(Arrays.asList(tableSegment1, tableSegment2),
DatabaseTypeEngine.getDatabaseType("MySQL")).getDatabaseName();
+ assertThrows(IllegalStateException.class, () -> new
TablesContext(Arrays.asList(tableSegment1, tableSegment2),
DatabaseTypeEngine.getDatabaseType("MySQL")).getDatabaseName());
}
- @Test(expected = IllegalStateException.class)
+ @Test
public void assertGetSchemaNameWithDifferentSchemaAndDifferentTable() {
SimpleTableSegment tableSegment1 = createTableSegment("table_1",
"tbl_1");
tableSegment1.setOwner(new OwnerSegment(0, 0, new
IdentifierValue("sharding_db_1")));
SimpleTableSegment tableSegment2 = createTableSegment("table_2",
"tbl_2");
tableSegment2.setOwner(new OwnerSegment(0, 0, new
IdentifierValue("sharding_db_2")));
- new TablesContext(Arrays.asList(tableSegment1, tableSegment2),
DatabaseTypeEngine.getDatabaseType("MySQL")).getDatabaseName();
+ assertThrows(IllegalStateException.class, () -> new
TablesContext(Arrays.asList(tableSegment1, tableSegment2),
DatabaseTypeEngine.getDatabaseType("MySQL")).getDatabaseName());
}
@Test
diff --git
a/infra/common/src/test/java/org/apache/shardingsphere/infra/database/metadata/dialect/MariaDBDataSourceMetaDataTest.java
b/infra/common/src/test/java/org/apache/shardingsphere/infra/database/metadata/dialect/MariaDBDataSourceMetaDataTest.java
index 238cd37dc47..45b66dd81ae 100644
---
a/infra/common/src/test/java/org/apache/shardingsphere/infra/database/metadata/dialect/MariaDBDataSourceMetaDataTest.java
+++
b/infra/common/src/test/java/org/apache/shardingsphere/infra/database/metadata/dialect/MariaDBDataSourceMetaDataTest.java
@@ -23,6 +23,7 @@ import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertNull;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
public final class MariaDBDataSourceMetaDataTest {
@@ -49,8 +50,8 @@ public final class MariaDBDataSourceMetaDataTest {
assertThat(actual.getQueryProperties().getProperty("useSSL"),
is(Boolean.FALSE.toString()));
}
- @Test(expected = UnrecognizedDatabaseURLException.class)
+ @Test
public void assertNewConstructorFailure() {
- new MariaDBDataSourceMetaData("jdbc:mariadb:xxxxxxxx");
+ assertThrows(UnrecognizedDatabaseURLException.class, () -> new
MariaDBDataSourceMetaData("jdbc:mariadb:xxxxxxxx"));
}
}
diff --git
a/infra/common/src/test/java/org/apache/shardingsphere/infra/database/metadata/dialect/MySQLDataSourceMetaDataTest.java
b/infra/common/src/test/java/org/apache/shardingsphere/infra/database/metadata/dialect/MySQLDataSourceMetaDataTest.java
index adb153bd33d..ca191291090 100644
---
a/infra/common/src/test/java/org/apache/shardingsphere/infra/database/metadata/dialect/MySQLDataSourceMetaDataTest.java
+++
b/infra/common/src/test/java/org/apache/shardingsphere/infra/database/metadata/dialect/MySQLDataSourceMetaDataTest.java
@@ -21,8 +21,9 @@ import
org.apache.shardingsphere.infra.database.metadata.UnrecognizedDatabaseURL
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertNull;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
public final class MySQLDataSourceMetaDataTest {
@@ -49,8 +50,8 @@ public final class MySQLDataSourceMetaDataTest {
assertThat(actual.getQueryProperties().getProperty("useSSL"),
is(Boolean.FALSE.toString()));
}
- @Test(expected = UnrecognizedDatabaseURLException.class)
+ @Test
public void assertNewConstructorFailure() {
- new MySQLDataSourceMetaData("jdbc:mysql:xxxxxxxx");
+ assertThrows(UnrecognizedDatabaseURLException.class, () -> new
MySQLDataSourceMetaData("jdbc:mysql:xxxxxxxx"));
}
}
diff --git
a/infra/common/src/test/java/org/apache/shardingsphere/infra/database/metadata/dialect/OpenGaussDataSourceMetaDataTest.java
b/infra/common/src/test/java/org/apache/shardingsphere/infra/database/metadata/dialect/OpenGaussDataSourceMetaDataTest.java
index 5f49fcf67f5..82c4307cc5b 100644
---
a/infra/common/src/test/java/org/apache/shardingsphere/infra/database/metadata/dialect/OpenGaussDataSourceMetaDataTest.java
+++
b/infra/common/src/test/java/org/apache/shardingsphere/infra/database/metadata/dialect/OpenGaussDataSourceMetaDataTest.java
@@ -21,8 +21,9 @@ import
org.apache.shardingsphere.infra.database.metadata.UnrecognizedDatabaseURL
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertNull;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
public final class OpenGaussDataSourceMetaDataTest {
@@ -48,8 +49,8 @@ public final class OpenGaussDataSourceMetaDataTest {
assertThat(actual.getQueryProperties().getProperty("targetServerType"),
is("master"));
}
- @Test(expected = UnrecognizedDatabaseURLException.class)
+ @Test
public void assertNewConstructorFailure() {
- new PostgreSQLDataSourceMetaData("jdbc:openGauss:xxxxxxxx");
+ assertThrows(UnrecognizedDatabaseURLException.class, () -> new
PostgreSQLDataSourceMetaData("jdbc:openGauss:xxxxxxxx"));
}
}
diff --git
a/infra/common/src/test/java/org/apache/shardingsphere/infra/database/metadata/dialect/OracleDataSourceMetaDataTest.java
b/infra/common/src/test/java/org/apache/shardingsphere/infra/database/metadata/dialect/OracleDataSourceMetaDataTest.java
index a6526e60c7a..c248f39e903 100644
---
a/infra/common/src/test/java/org/apache/shardingsphere/infra/database/metadata/dialect/OracleDataSourceMetaDataTest.java
+++
b/infra/common/src/test/java/org/apache/shardingsphere/infra/database/metadata/dialect/OracleDataSourceMetaDataTest.java
@@ -22,6 +22,7 @@ import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertThrows;
public final class OracleDataSourceMetaDataTest {
@@ -109,9 +110,9 @@ public final class OracleDataSourceMetaDataTest {
assertThat(actual.getSchema(), is("test"));
}
- @Test(expected = UnrecognizedDatabaseURLException.class)
+ @Test
public void assertNewConstructorFailure() {
- new OracleDataSourceMetaData("jdbc:oracle:xxxxxxxx", "test");
+ assertThrows(UnrecognizedDatabaseURLException.class, () -> new
OracleDataSourceMetaData("jdbc:oracle:xxxxxxxx", "test"));
}
@Test
diff --git
a/infra/common/src/test/java/org/apache/shardingsphere/infra/database/metadata/dialect/PostgreSQLDataSourceMetaDataTest.java
b/infra/common/src/test/java/org/apache/shardingsphere/infra/database/metadata/dialect/PostgreSQLDataSourceMetaDataTest.java
index 45073dbf557..66936ad6978 100644
---
a/infra/common/src/test/java/org/apache/shardingsphere/infra/database/metadata/dialect/PostgreSQLDataSourceMetaDataTest.java
+++
b/infra/common/src/test/java/org/apache/shardingsphere/infra/database/metadata/dialect/PostgreSQLDataSourceMetaDataTest.java
@@ -21,8 +21,9 @@ import
org.apache.shardingsphere.infra.database.metadata.UnrecognizedDatabaseURL
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertNull;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
public final class PostgreSQLDataSourceMetaDataTest {
@@ -48,8 +49,8 @@ public final class PostgreSQLDataSourceMetaDataTest {
assertThat(actual.getQueryProperties().getProperty("targetServerType"),
is("master"));
}
- @Test(expected = UnrecognizedDatabaseURLException.class)
+ @Test
public void assertNewConstructorFailure() {
- new PostgreSQLDataSourceMetaData("jdbc:postgresql:xxxxxxxx");
+ assertThrows(UnrecognizedDatabaseURLException.class, () -> new
PostgreSQLDataSourceMetaData("jdbc:postgresql:xxxxxxxx"));
}
}
diff --git
a/infra/common/src/test/java/org/apache/shardingsphere/infra/database/metadata/dialect/SQL92DataSourceMetaDataTest.java
b/infra/common/src/test/java/org/apache/shardingsphere/infra/database/metadata/dialect/SQL92DataSourceMetaDataTest.java
index 6eb3cac5b3a..441f7a5ee22 100644
---
a/infra/common/src/test/java/org/apache/shardingsphere/infra/database/metadata/dialect/SQL92DataSourceMetaDataTest.java
+++
b/infra/common/src/test/java/org/apache/shardingsphere/infra/database/metadata/dialect/SQL92DataSourceMetaDataTest.java
@@ -21,8 +21,9 @@ import
org.apache.shardingsphere.infra.database.metadata.UnrecognizedDatabaseURL
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertNull;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThrows;
public final class SQL92DataSourceMetaDataTest {
@@ -35,8 +36,8 @@ public final class SQL92DataSourceMetaDataTest {
assertNull(actual.getSchema());
}
- @Test(expected = UnrecognizedDatabaseURLException.class)
+ @Test
public void assertNewConstructorFailure() {
- new SQL92DataSourceMetaData("xxx:xxxx:xxxxxxxx");
+ assertThrows(UnrecognizedDatabaseURLException.class, () -> new
SQL92DataSourceMetaData("xxx:xxxx:xxxxxxxx"));
}
}
diff --git
a/infra/common/src/test/java/org/apache/shardingsphere/infra/database/metadata/dialect/SQLServerDataSourceMetaDataTest.java
b/infra/common/src/test/java/org/apache/shardingsphere/infra/database/metadata/dialect/SQLServerDataSourceMetaDataTest.java
index fd8debb4a94..0a654dbdf47 100644
---
a/infra/common/src/test/java/org/apache/shardingsphere/infra/database/metadata/dialect/SQLServerDataSourceMetaDataTest.java
+++
b/infra/common/src/test/java/org/apache/shardingsphere/infra/database/metadata/dialect/SQLServerDataSourceMetaDataTest.java
@@ -23,6 +23,7 @@ import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertNull;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertThrows;
public final class SQLServerDataSourceMetaDataTest {
@@ -77,8 +78,8 @@ public final class SQLServerDataSourceMetaDataTest {
assertNull(actual.getSchema());
}
- @Test(expected = UnrecognizedDatabaseURLException.class)
+ @Test
public void assertNewConstructorFailure() {
- new SQLServerDataSourceMetaData("jdbc:sqlserver:xxxxxxxx");
+ assertThrows(UnrecognizedDatabaseURLException.class, () -> new
SQLServerDataSourceMetaData("jdbc:sqlserver:xxxxxxxx"));
}
}
diff --git
a/infra/common/src/test/java/org/apache/shardingsphere/infra/database/metadata/url/StandardJdbcUrlParserTest.java
b/infra/common/src/test/java/org/apache/shardingsphere/infra/database/metadata/url/StandardJdbcUrlParserTest.java
index 07e74a522ac..7e52acca999 100644
---
a/infra/common/src/test/java/org/apache/shardingsphere/infra/database/metadata/url/StandardJdbcUrlParserTest.java
+++
b/infra/common/src/test/java/org/apache/shardingsphere/infra/database/metadata/url/StandardJdbcUrlParserTest.java
@@ -22,6 +22,7 @@ import org.junit.Test;
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 StandardJdbcUrlParserTest {
@@ -77,9 +78,9 @@ public final class StandardJdbcUrlParserTest {
assertTrue(actual.getQueryProperties().isEmpty());
}
- @Test(expected = UnrecognizedDatabaseURLException.class)
+ @Test
public void assertParseIncorrectURL() {
- new
StandardJdbcUrlParser().parse("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL");
+ assertThrows(UnrecognizedDatabaseURLException.class, () -> new
StandardJdbcUrlParser().parse("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL"));
}
@Test
diff --git
a/infra/common/src/test/java/org/apache/shardingsphere/infra/database/type/DatabaseTypeEngineTest.java
b/infra/common/src/test/java/org/apache/shardingsphere/infra/database/type/DatabaseTypeEngineTest.java
index 3565cbfc471..d356f160b99 100644
---
a/infra/common/src/test/java/org/apache/shardingsphere/infra/database/type/DatabaseTypeEngineTest.java
+++
b/infra/common/src/test/java/org/apache/shardingsphere/infra/database/type/DatabaseTypeEngineTest.java
@@ -43,6 +43,7 @@ import java.util.Properties;
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.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
@@ -93,11 +94,11 @@ public final class DatabaseTypeEngineTest {
assertThat(DatabaseTypeEngine.getStorageType(dataSources).getType(),
is("H2"));
}
- @Test(expected = SQLWrapperException.class)
+ @Test
public void assertGetStorageTypeWhenGetConnectionError() throws
SQLException {
DataSource dataSource = mock(DataSource.class);
when(dataSource.getConnection()).thenThrow(SQLException.class);
- DatabaseTypeEngine.getStorageType(Collections.singleton(dataSource));
+ assertThrows(SQLWrapperException.class, () ->
DatabaseTypeEngine.getStorageType(Collections.singleton(dataSource)));
}
@Test
diff --git
a/infra/common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/PostgreSQLDatabaseTypeTest.java
b/infra/common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/PostgreSQLDatabaseTypeTest.java
index 1446f025954..f7b3195d252 100644
---
a/infra/common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/PostgreSQLDatabaseTypeTest.java
+++
b/infra/common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/PostgreSQLDatabaseTypeTest.java
@@ -33,6 +33,7 @@ import java.util.HashSet;
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;
@@ -68,9 +69,9 @@ public final class PostgreSQLDatabaseTypeTest {
new PostgreSQLDatabaseType().handleRollbackOnly(true,
mock(RollbackStatement.class));
}
- @Test(expected = SQLFeatureNotSupportedException.class)
- public void assertHandleRollbackOnlyForRollbackOnlyAndNotTCLStatement()
throws SQLException {
- new PostgreSQLDatabaseType().handleRollbackOnly(true,
mock(SelectStatement.class));
+ @Test
+ public void assertHandleRollbackOnlyForRollbackOnlyAndNotTCLStatement() {
+ assertThrows(SQLFeatureNotSupportedException.class, () -> new
PostgreSQLDatabaseType().handleRollbackOnly(true, mock(SelectStatement.class)));
}
@Test
diff --git
a/infra/common/src/test/java/org/apache/shardingsphere/infra/datanode/DataNodeTest.java
b/infra/common/src/test/java/org/apache/shardingsphere/infra/datanode/DataNodeTest.java
index f00069274bc..4cd0fd14775 100644
---
a/infra/common/src/test/java/org/apache/shardingsphere/infra/datanode/DataNodeTest.java
+++
b/infra/common/src/test/java/org/apache/shardingsphere/infra/datanode/DataNodeTest.java
@@ -24,6 +24,7 @@ import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertThrows;
public final class DataNodeTest {
@@ -34,19 +35,19 @@ public final class DataNodeTest {
assertThat(dataNode.getTableName(), is("tbl_0"));
}
- @Test(expected = InvalidDataNodesFormatException.class)
+ @Test
public void assertNewInValidDataNodeWithoutDelimiter() {
- new DataNode("ds_0tbl_0");
+ assertThrows(InvalidDataNodesFormatException.class, () -> new
DataNode("ds_0tbl_0"));
}
- @Test(expected = InvalidDataNodesFormatException.class)
+ @Test
public void assertNewInValidDataNodeWithTwoDelimiters() {
- new DataNode("ds_0.db_0.tbl_0.tbl_1");
+ assertThrows(InvalidDataNodesFormatException.class, () -> new
DataNode("ds_0.db_0.tbl_0.tbl_1"));
}
- @Test(expected = InvalidDataNodesFormatException.class)
+ @Test
public void assertNewValidDataNodeWithInvalidDelimiter() {
- new DataNode("ds_0,tbl_0");
+ assertThrows(InvalidDataNodesFormatException.class, () -> new
DataNode("ds_0,tbl_0"));
}
@Test
@@ -68,14 +69,14 @@ public final class DataNodeTest {
assertThat(new DataNode("ds_0.tbl_0").toString(),
is("DataNode(dataSourceName=ds_0, tableName=tbl_0, schemaName=null)"));
}
- @Test(expected = InvalidDataNodesFormatException.class)
+ @Test
public void assertEmptyDataSourceDataNode() {
- new DataNode(".tbl_0");
+ assertThrows(InvalidDataNodesFormatException.class, () -> new
DataNode(".tbl_0"));
}
- @Test(expected = InvalidDataNodesFormatException.class)
+ @Test
public void assertEmptyTableDataNode() {
- new DataNode("ds_0.");
+ assertThrows(InvalidDataNodesFormatException.class, () -> new
DataNode("ds_0."));
}
@Test
diff --git
a/infra/common/src/test/java/org/apache/shardingsphere/infra/hint/HintManagerTest.java
b/infra/common/src/test/java/org/apache/shardingsphere/infra/hint/HintManagerTest.java
index af1952b5db3..1f8d2400b91 100644
---
a/infra/common/src/test/java/org/apache/shardingsphere/infra/hint/HintManagerTest.java
+++
b/infra/common/src/test/java/org/apache/shardingsphere/infra/hint/HintManagerTest.java
@@ -23,17 +23,18 @@ import java.util.ArrayList;
import java.util.List;
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 HintManagerTest {
- @Test(expected = IllegalStateException.class)
+ @Test
public void assertGetInstanceTwice() {
try {
HintManager.getInstance();
- HintManager.getInstance();
+ assertThrows(IllegalStateException.class,
HintManager::getInstance);
} finally {
HintManager.clear();
}
diff --git
a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/SystemSchemaBuilderRuleTest.java
b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/SystemSchemaBuilderRuleTest.java
index 7d919dce301..78d8e93c196 100644
---
a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/SystemSchemaBuilderRuleTest.java
+++
b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/SystemSchemaBuilderRuleTest.java
@@ -24,8 +24,9 @@ import java.util.Arrays;
import java.util.HashSet;
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 SystemSchemaBuilderRuleTest {
@@ -37,9 +38,9 @@ public final class SystemSchemaBuilderRuleTest {
assertThat(actual.getTables(), is(new
HashSet<>(Arrays.asList("columns", "engines", "parameters", "routines",
"schemata", "tables", "views"))));
}
- @Test(expected = NullPointerException.class)
+ @Test
public void assertValueOfSchemaPathFailure() {
- SystemSchemaBuilderRule.valueOf(new MySQLDatabaseType().getType(),
"test");
+ assertThrows(NullPointerException.class, () ->
SystemSchemaBuilderRule.valueOf(new MySQLDatabaseType().getType(), "test"));
}
@Test
diff --git
a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/user/yaml/swapper/YamlUserSwapperTest.java
b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/user/yaml/swapper/YamlUserSwapperTest.java
index e2711172d16..f7a61ed29f0 100644
---
a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/user/yaml/swapper/YamlUserSwapperTest.java
+++
b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/user/yaml/swapper/YamlUserSwapperTest.java
@@ -22,9 +22,10 @@ import
org.apache.shardingsphere.infra.metadata.user.yaml.config.YamlUserConfigu
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertThrows;
public final class YamlUserSwapperTest {
@@ -65,11 +66,11 @@ public final class YamlUserSwapperTest {
assertThat(actual.getPassword(), is("foo_pwd"));
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void assertSwapToObjectWithEmptyUsername() {
YamlUserConfiguration user = new YamlUserConfiguration();
user.setUser("@127.0.0.1");
- new YamlUserSwapper().swapToObject(user);
+ assertThrows(IllegalArgumentException.class, () -> new
YamlUserSwapper().swapToObject(user));
}
@Test
diff --git
a/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/ExecutorExceptionHandlerTest.java
b/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/ExecutorExceptionHandlerTest.java
index d3545b9c27e..1ede7accf7f 100644
---
a/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/ExecutorExceptionHandlerTest.java
+++
b/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/ExecutorExceptionHandlerTest.java
@@ -24,6 +24,7 @@ import org.mockito.internal.configuration.plugins.Plugins;
import java.sql.SQLException;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
public final class ExecutorExceptionHandlerTest {
@@ -33,17 +34,17 @@ public final class ExecutorExceptionHandlerTest {
((ThreadLocal<?>)
Plugins.getMemberAccessor().get(SQLExecutorExceptionHandler.class.getDeclaredField("IS_EXCEPTION_THROWN"),
SQLExecutorExceptionHandler.class)).remove();
}
- @Test(expected = SQLException.class)
- public void assertHandleExceptionWithoutSet() throws SQLException {
+ @Test
+ public void assertHandleExceptionWithoutSet() {
assertTrue(SQLExecutorExceptionHandler.isExceptionThrown());
- SQLExecutorExceptionHandler.handleException(new SQLException(""));
+ assertThrows(SQLException.class, () ->
SQLExecutorExceptionHandler.handleException(new SQLException("")));
}
- @Test(expected = SQLException.class)
- public void assertHandleExceptionWhenExceptionThrownIsTrue() throws
SQLException {
+ @Test
+ public void assertHandleExceptionWhenExceptionThrownIsTrue() {
SQLExecutorExceptionHandler.setExceptionThrown(true);
assertTrue(SQLExecutorExceptionHandler.isExceptionThrown());
- SQLExecutorExceptionHandler.handleException(new SQLException(""));
+ assertThrows(SQLException.class, () ->
SQLExecutorExceptionHandler.handleException(new SQLException("")));
}
@Test
diff --git
a/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/jdbc/JDBCExecutorCallbackTest.java
b/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/jdbc/JDBCExecutorCallbackTest.java
index b6e91a8731f..3a929f7a89b 100644
---
a/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/jdbc/JDBCExecutorCallbackTest.java
+++
b/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/jdbc/JDBCExecutorCallbackTest.java
@@ -47,6 +47,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.mock;
import static org.mockito.Mockito.when;
@@ -119,8 +120,8 @@ public final class JDBCExecutorCallbackTest {
assertThat(callback.execute(units, false),
is(Collections.emptyList()));
}
- @Test(expected = SQLException.class)
- public void
assertExecuteSQLExceptionOccurredAndProtocolTypeSameAsDatabaseType() throws
SQLException {
+ @Test
+ public void
assertExecuteSQLExceptionOccurredAndProtocolTypeSameAsDatabaseType() {
JDBCExecutorCallback<Object> callback =
new
JDBCExecutorCallback<Object>(TypedSPILoader.getService(DatabaseType.class,
"MySQL"),
Collections.singletonMap("ds",
TypedSPILoader.getService(DatabaseType.class, "PostgreSQL")),
mock(SelectStatement.class), true) {
@@ -135,6 +136,6 @@ public final class JDBCExecutorCallbackTest {
return Optional.empty();
}
};
- callback.execute(units, true);
+ assertThrows(SQLException.class, () -> callback.execute(units, true));
}
}
diff --git
a/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/memory/JDBCMemoryQueryResultTest.java
b/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/memory/JDBCMemoryQueryResultTest.java
index 0cc248233d9..d88f6dc37ea 100644
---
a/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/memory/JDBCMemoryQueryResultTest.java
+++
b/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/memory/JDBCMemoryQueryResultTest.java
@@ -41,9 +41,10 @@ import java.sql.Types;
import java.util.Calendar;
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.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
@@ -53,11 +54,11 @@ public final class JDBCMemoryQueryResultTest {
private final DatabaseType databaseType = new MySQLDatabaseType();
- @Test(expected = SQLException.class)
+ @Test
public void assertConstructorWithSqlException() throws SQLException {
ResultSet resultSet = mockResultSet();
when(resultSet.next()).thenThrow(new SQLException(""));
- new JDBCMemoryQueryResult(resultSet, databaseType);
+ assertThrows(SQLException.class, () -> new
JDBCMemoryQueryResult(resultSet, databaseType));
}
@Test
diff --git
a/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/stream/JDBCStreamQueryResultTest.java
b/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/stream/JDBCStreamQueryResultTest.java
index f52a1dce769..4dcd22a4a64 100644
---
a/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/stream/JDBCStreamQueryResultTest.java
+++
b/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/stream/JDBCStreamQueryResultTest.java
@@ -31,9 +31,10 @@ import java.sql.Timestamp;
import java.util.Calendar;
import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
-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.verify;
@@ -194,11 +195,11 @@ public final class JDBCStreamQueryResultTest {
verify(resultSet).getTimestamp(1, calendar);
}
- @Test(expected = SQLException.class)
+ @Test
public void assertGetCalendarValueWithUnsupportedType() throws
SQLException {
JDBCStreamQueryResult queryResult = new
JDBCStreamQueryResult(getResultSet());
queryResult.next();
- queryResult.getCalendarValue(1, Object.class, Calendar.getInstance());
+ assertThrows(SQLException.class, () -> queryResult.getCalendarValue(1,
Object.class, Calendar.getInstance()));
}
@Test
@@ -229,11 +230,11 @@ public final class JDBCStreamQueryResultTest {
verify(resultSet).getBinaryStream(1);
}
- @Test(expected = SQLException.class)
+ @Test
public void assertGetInputStreamWithUnsupportedType() throws SQLException {
JDBCStreamQueryResult queryResult = new
JDBCStreamQueryResult(getResultSet());
queryResult.next();
- queryResult.getInputStream(1, "Unsupported Type");
+ assertThrows(SQLException.class, () -> queryResult.getInputStream(1,
"Unsupported Type"));
}
@Test
diff --git
a/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/util/ResultSetUtilTest.java
b/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/util/ResultSetUtilTest.java
index 53ab3bb17b7..379dafc1191 100644
---
a/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/util/ResultSetUtilTest.java
+++
b/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/util/ResultSetUtilTest.java
@@ -40,6 +40,7 @@ import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
public final class ResultSetUtilTest {
@@ -93,9 +94,9 @@ public final class ResultSetUtilTest {
assertThat(ResultSetUtil.convertValue(1, Float.class),
is(Float.valueOf("1")));
}
- @Test(expected = UnsupportedDataTypeConversionException.class)
- public void assertConvertNumberValueError() throws SQLException {
- ResultSetUtil.convertValue(1, Date.class);
+ @Test
+ public void assertConvertNumberValueError() {
+ assertThrows(UnsupportedDataTypeConversionException.class, () ->
ResultSetUtil.convertValue(1, Date.class));
}
@Test
@@ -113,9 +114,9 @@ public final class ResultSetUtilTest {
assertThat(ResultSetUtil.convertValue(null, Date.class), is((Object)
null));
}
- @Test(expected = SQLException.class)
- public void assertConvertNullType() throws SQLException {
- ResultSetUtil.convertValue(null, null);
+ @Test
+ public void assertConvertNullType() {
+ assertThrows(SQLException.class, () ->
ResultSetUtil.convertValue(null, null));
}
@Test
@@ -149,10 +150,10 @@ public final class ResultSetUtilTest {
assertThat(url, is(new URL(urlString)));
}
- @Test(expected = UnsupportedDataTypeConversionException.class)
- public void assertConvertURLValueError() throws SQLException {
+ @Test
+ public void assertConvertURLValueError() {
String urlString = "no-exist:shardingsphere.apache.org/";
- ResultSetUtil.convertValue(urlString, URL.class);
+ assertThrows(UnsupportedDataTypeConversionException.class, () ->
ResultSetUtil.convertValue(urlString, URL.class));
}
@Test
@@ -173,13 +174,13 @@ public final class ResultSetUtilTest {
assertThat(bigDecimal, is(BigDecimal.valueOf(12.24)));
}
- @Test(expected = UnsupportedDataTypeConversionException.class)
+ @Test
public void assertConvertBigDecimalValueError() {
- ResultSetUtil.convertBigDecimalValue(new Date(), true, 2);
+ assertThrows(UnsupportedDataTypeConversionException.class, () ->
ResultSetUtil.convertBigDecimalValue(new Date(), true, 2));
}
- @Test(expected = UnsupportedDataTypeConversionException.class)
- public void assertConvertDateValueError() throws SQLException {
- ResultSetUtil.convertValue(new Date(), int.class);
+ @Test
+ public void assertConvertDateValueError() {
+ assertThrows(UnsupportedDataTypeConversionException.class, () ->
ResultSetUtil.convertValue(new Date(), int.class));
}
}
diff --git
a/infra/merge/src/test/java/org/apache/shardingsphere/infra/merge/result/impl/local/LocalDataMergedResultTest.java
b/infra/merge/src/test/java/org/apache/shardingsphere/infra/merge/result/impl/local/LocalDataMergedResultTest.java
index 8e73e427338..35752fe2c59 100644
---
a/infra/merge/src/test/java/org/apache/shardingsphere/infra/merge/result/impl/local/LocalDataMergedResultTest.java
+++
b/infra/merge/src/test/java/org/apache/shardingsphere/infra/merge/result/impl/local/LocalDataMergedResultTest.java
@@ -19,7 +19,6 @@ package
org.apache.shardingsphere.infra.merge.result.impl.local;
import org.junit.Test;
-import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.Calendar;
import java.util.Collections;
@@ -27,8 +26,9 @@ import java.util.Date;
import java.util.List;
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 LocalDataMergedResultTest {
@@ -57,11 +57,11 @@ public final class LocalDataMergedResultTest {
assertThat(actual.getCalendarValue(1, Object.class,
Calendar.getInstance()), is(new Date(0L)));
}
- @Test(expected = SQLFeatureNotSupportedException.class)
- public void assertGetInputStream() throws SQLException {
+ @Test
+ public void assertGetInputStream() {
List<Object> row = Collections.singletonList("value");
LocalDataMergedResult actual = new
LocalDataMergedResult(Collections.singletonList(new
LocalDataQueryResultRow(row)));
- actual.getInputStream(1, "Ascii");
+ assertThrows(SQLFeatureNotSupportedException.class, () ->
actual.getInputStream(1, "Ascii"));
}
@Test
diff --git
a/infra/merge/src/test/java/org/apache/shardingsphere/infra/merge/result/impl/memory/MemoryMergedResultTest.java
b/infra/merge/src/test/java/org/apache/shardingsphere/infra/merge/result/impl/memory/MemoryMergedResultTest.java
index 845f2a3ec3d..b546acc8aea 100644
---
a/infra/merge/src/test/java/org/apache/shardingsphere/infra/merge/result/impl/memory/MemoryMergedResultTest.java
+++
b/infra/merge/src/test/java/org/apache/shardingsphere/infra/merge/result/impl/memory/MemoryMergedResultTest.java
@@ -32,8 +32,9 @@ import java.util.Calendar;
import java.util.Date;
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;
import static org.mockito.Mockito.when;
@@ -61,29 +62,29 @@ public final class MemoryMergedResultTest {
assertThat(memoryMergedResult.getValue(1, Object.class).toString(),
is("1"));
}
- @Test(expected = SQLFeatureNotSupportedException.class)
- public void assertGetValueForBlob() throws SQLException {
- memoryMergedResult.getValue(1, Blob.class);
+ @Test
+ public void assertGetValueForBlob() {
+ assertThrows(SQLFeatureNotSupportedException.class, () ->
memoryMergedResult.getValue(1, Blob.class));
}
- @Test(expected = SQLFeatureNotSupportedException.class)
- public void assertGetValueForClob() throws SQLException {
- memoryMergedResult.getValue(1, Clob.class);
+ @Test
+ public void assertGetValueForClob() {
+ assertThrows(SQLFeatureNotSupportedException.class, () ->
memoryMergedResult.getValue(1, Clob.class));
}
- @Test(expected = SQLFeatureNotSupportedException.class)
- public void assertGetValueForReader() throws SQLException {
- memoryMergedResult.getValue(1, Reader.class);
+ @Test
+ public void assertGetValueForReader() {
+ assertThrows(SQLFeatureNotSupportedException.class, () ->
memoryMergedResult.getValue(1, Reader.class));
}
- @Test(expected = SQLFeatureNotSupportedException.class)
- public void assertGetValueForInputStream() throws SQLException {
- memoryMergedResult.getValue(1, InputStream.class);
+ @Test
+ public void assertGetValueForInputStream() {
+ assertThrows(SQLFeatureNotSupportedException.class, () ->
memoryMergedResult.getValue(1, InputStream.class));
}
- @Test(expected = SQLFeatureNotSupportedException.class)
- public void assertGetValueForSQLXML() throws SQLException {
- memoryMergedResult.getValue(1, SQLXML.class);
+ @Test
+ public void assertGetValueForSQLXML() {
+ assertThrows(SQLFeatureNotSupportedException.class, () ->
memoryMergedResult.getValue(1, SQLXML.class));
}
@Test
@@ -92,9 +93,9 @@ public final class MemoryMergedResultTest {
assertThat(memoryMergedResult.getCalendarValue(1, Object.class,
Calendar.getInstance()), is(new Date(0L)));
}
- @Test(expected = SQLFeatureNotSupportedException.class)
- public void assertGetInputStream() throws SQLException {
- memoryMergedResult.getInputStream(1, "ascii");
+ @Test
+ public void assertGetInputStream() {
+ assertThrows(SQLFeatureNotSupportedException.class, () ->
memoryMergedResult.getInputStream(1, "ascii"));
}
@Test
diff --git
a/infra/merge/src/test/java/org/apache/shardingsphere/infra/merge/result/impl/memory/MemoryQueryResultRowTest.java
b/infra/merge/src/test/java/org/apache/shardingsphere/infra/merge/result/impl/memory/MemoryQueryResultRowTest.java
index b8315aa7cb0..0ab4ceb212d 100644
---
a/infra/merge/src/test/java/org/apache/shardingsphere/infra/merge/result/impl/memory/MemoryQueryResultRowTest.java
+++
b/infra/merge/src/test/java/org/apache/shardingsphere/infra/merge/result/impl/memory/MemoryQueryResultRowTest.java
@@ -25,6 +25,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.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -46,14 +47,14 @@ public final class MemoryQueryResultRowTest {
assertThat(memoryResultSetRow.getCell(1).toString(), is("value"));
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void assertGetCellWithNegativeColumnIndex() {
- memoryResultSetRow.getCell(-1);
+ assertThrows(IllegalArgumentException.class, () ->
memoryResultSetRow.getCell(-1));
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void assertGetCellWithColumnIndexOutOfRange() {
- memoryResultSetRow.getCell(2);
+ assertThrows(IllegalArgumentException.class, () ->
memoryResultSetRow.getCell(2));
}
@Test
@@ -62,13 +63,13 @@ public final class MemoryQueryResultRowTest {
assertThat(memoryResultSetRow.getCell(1).toString(), is("new"));
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void assertSetCellWithNegativeColumnIndex() {
- memoryResultSetRow.setCell(-1, "new");
+ assertThrows(IllegalArgumentException.class, () ->
memoryResultSetRow.setCell(-1, "new"));
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void assertSetCellWithColumnIndexOutOfRange() {
- memoryResultSetRow.setCell(2, "new");
+ assertThrows(IllegalArgumentException.class, () ->
memoryResultSetRow.setCell(2, "new"));
}
}
diff --git
a/infra/merge/src/test/java/org/apache/shardingsphere/infra/merge/result/impl/stream/StreamMergedResultTest.java
b/infra/merge/src/test/java/org/apache/shardingsphere/infra/merge/result/impl/stream/StreamMergedResultTest.java
index d4e537af6d3..56599121051 100644
---
a/infra/merge/src/test/java/org/apache/shardingsphere/infra/merge/result/impl/stream/StreamMergedResultTest.java
+++
b/infra/merge/src/test/java/org/apache/shardingsphere/infra/merge/result/impl/stream/StreamMergedResultTest.java
@@ -27,8 +27,9 @@ import java.sql.SQLException;
import java.util.Calendar;
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.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -36,9 +37,9 @@ public final class StreamMergedResultTest {
private final TestStreamMergedResult streamMergedResult = new
TestStreamMergedResult();
- @Test(expected = SQLException.class)
- public void assertGetCurrentQueryResultIfNull() throws SQLException {
- streamMergedResult.getCurrentQueryResult();
+ @Test
+ public void assertGetCurrentQueryResultIfNull() {
+ assertThrows(SQLException.class,
streamMergedResult::getCurrentQueryResult);
}
@Test
diff --git
a/infra/route/src/test/java/org/apache/shardingsphere/infra/route/engine/SQLRouteEngineTest.java
b/infra/route/src/test/java/org/apache/shardingsphere/infra/route/engine/SQLRouteEngineTest.java
index 175eddc9ffe..fd6ae73313d 100644
---
a/infra/route/src/test/java/org/apache/shardingsphere/infra/route/engine/SQLRouteEngineTest.java
+++
b/infra/route/src/test/java/org/apache/shardingsphere/infra/route/engine/SQLRouteEngineTest.java
@@ -36,6 +36,7 @@ import java.util.Properties;
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.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
@@ -57,13 +58,13 @@ public final class SQLRouteEngineTest {
assertTrue(routeUnit.getTableMappers().isEmpty());
}
- @Test(expected = UnsupportedOperationException.class)
+ @Test
public void assertRouteFailure() {
QueryContext queryContext = new
QueryContext(mock(CommonSQLStatementContext.class), "SELECT 1",
Collections.emptyList());
ShardingSphereRuleMetaData ruleMetaData = new
ShardingSphereRuleMetaData(Collections.singleton(new RouteRuleFixture()));
ShardingSphereDatabase database = new
ShardingSphereDatabase("logic_schema",
mock(DatabaseType.class),
mock(ShardingSphereResourceMetaData.class, RETURNS_DEEP_STUBS), ruleMetaData,
Collections.emptyMap());
- new SQLRouteEngine(Collections.singleton(new
RouteFailureRuleFixture()),
- new ConfigurationProperties(new Properties())).route(new
ConnectionContext(), queryContext, mock(ShardingSphereRuleMetaData.class),
database);
+ assertThrows(UnsupportedOperationException.class, () -> new
SQLRouteEngine(Collections.singleton(new RouteFailureRuleFixture()),
+ new ConfigurationProperties(new Properties())).route(new
ConnectionContext(), queryContext, mock(ShardingSphereRuleMetaData.class),
database));
}
}
diff --git
a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/exception/ShardingSpherePreconditionsTest.java
b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/exception/ShardingSpherePreconditionsTest.java
index d506a1ad268..8117eeaba9c 100644
---
a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/exception/ShardingSpherePreconditionsTest.java
+++
b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/exception/ShardingSpherePreconditionsTest.java
@@ -21,11 +21,13 @@ import org.junit.Test;
import java.sql.SQLException;
+import static org.junit.Assert.assertThrows;
+
public final class ShardingSpherePreconditionsTest {
- @Test(expected = SQLException.class)
- public void assertCheckStateToThrowsException() throws SQLException {
- ShardingSpherePreconditions.checkState(false, SQLException::new);
+ @Test
+ public void assertCheckStateToThrowsException() {
+ assertThrows(SQLException.class, () ->
ShardingSpherePreconditions.checkState(false, SQLException::new));
}
@Test
@@ -33,9 +35,9 @@ public final class ShardingSpherePreconditionsTest {
ShardingSpherePreconditions.checkState(true, SQLException::new);
}
- @Test(expected = SQLException.class)
- public void assertCheckNotNullToThrowsException() throws SQLException {
- ShardingSpherePreconditions.checkNotNull(null, SQLException::new);
+ @Test
+ public void assertCheckNotNullToThrowsException() {
+ assertThrows(SQLException.class, () ->
ShardingSpherePreconditions.checkNotNull(null, SQLException::new));
}
@Test
diff --git
a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/props/TypedPropertiesTest.java
b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/props/TypedPropertiesTest.java
index 7068ca5a652..7073c7b0a6b 100644
---
a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/props/TypedPropertiesTest.java
+++
b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/props/TypedPropertiesTest.java
@@ -29,6 +29,7 @@ import java.util.Properties;
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;
public final class TypedPropertiesTest {
@@ -70,7 +71,7 @@ public final class TypedPropertiesTest {
assertThat(actual.getValue(TypedPropertyKeyFixture.STRING_VALUE),
is("value"));
}
- @Test(expected = TypedPropertiesServerException.class)
+ @Test
public void assertGetInvalidValue() {
Properties props = PropertiesBuilder.build(
new Property(TypedPropertyKeyFixture.BOOLEAN_VALUE.getKey(),
"test"),
@@ -78,6 +79,6 @@ public final class TypedPropertiesTest {
new Property(TypedPropertyKeyFixture.INT_VALUE.getKey(),
"test"),
new
Property(TypedPropertyKeyFixture.INT_OBJECT_VALUE.getKey(), "test"),
new Property(TypedPropertyKeyFixture.LONG_VALUE.getKey(),
"test"));
- new TypedPropertiesFixture(props);
+ assertThrows(TypedPropertiesServerException.class, () -> new
TypedPropertiesFixture(props));
}
}
diff --git
a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/props/TypedPropertyValueTest.java
b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/props/TypedPropertyValueTest.java
index e2173ed8a94..96b2a756e39 100644
---
a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/props/TypedPropertyValueTest.java
+++
b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/props/TypedPropertyValueTest.java
@@ -25,6 +25,7 @@ import org.junit.Test;
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;
public final class TypedPropertyValueTest {
@@ -46,9 +47,9 @@ public final class TypedPropertyValueTest {
assertThat(new
TypedPropertyValue(TypedPropertyKeyFixture.INT_OBJECT_VALUE,
"1000").getValue(), is(1000));
}
- @Test(expected = TypedPropertyValueException.class)
- public void assertGetInvalidIntValue() throws TypedPropertyValueException {
- new TypedPropertyValue(TypedPropertyKeyFixture.INT_VALUE, "test");
+ @Test
+ public void assertGetInvalidIntValue() {
+ assertThrows(TypedPropertyValueException.class, () -> new
TypedPropertyValue(TypedPropertyKeyFixture.INT_VALUE, "test"));
}
@Test
@@ -57,9 +58,9 @@ public final class TypedPropertyValueTest {
assertThat(new
TypedPropertyValue(TypedPropertyKeyFixture.LONG_OBJECT_VALUE,
"10000").getValue(), is(10000L));
}
- @Test(expected = TypedPropertyValueException.class)
- public void assertGetInvalidLongValue() throws TypedPropertyValueException
{
- new TypedPropertyValue(TypedPropertyKeyFixture.LONG_VALUE, "test");
+ @Test
+ public void assertGetInvalidLongValue() {
+ assertThrows(TypedPropertyValueException.class, () -> new
TypedPropertyValue(TypedPropertyKeyFixture.LONG_VALUE, "test"));
}
@Test
@@ -72,8 +73,8 @@ public final class TypedPropertyValueTest {
assertThat(new TypedPropertyValue(TypedPropertyKeyFixture.ENUM_VALUE,
TypedPropertyEnumFixture.FOO.name()).getValue(),
is(TypedPropertyEnumFixture.FOO));
}
- @Test(expected = TypedPropertyValueException.class)
- public void assertGetInvalidEnumValue() throws TypedPropertyValueException
{
- new TypedPropertyValue(TypedPropertyKeyFixture.ENUM_VALUE, "BAR");
+ @Test
+ public void assertGetInvalidEnumValue() {
+ assertThrows(TypedPropertyValueException.class, () -> new
TypedPropertyValue(TypedPropertyKeyFixture.ENUM_VALUE, "BAR"));
}
}
diff --git
a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/spi/ShardingSphereServiceLoaderTest.java
b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/spi/ShardingSphereServiceLoaderTest.java
index ae2def20565..071e0f17d2b 100644
---
a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/spi/ShardingSphereServiceLoaderTest.java
+++
b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/spi/ShardingSphereServiceLoaderTest.java
@@ -19,8 +19,8 @@ package org.apache.shardingsphere.infra.util.spi;
import org.apache.shardingsphere.infra.util.spi.fixture.empty.EmptySPIFixture;
import
org.apache.shardingsphere.infra.util.spi.fixture.multiton.MultitonSPIFixture;
-import
org.apache.shardingsphere.infra.util.spi.fixture.singleton.SingletonSPIFixture;
import
org.apache.shardingsphere.infra.util.spi.fixture.multiton.impl.MultitonSPIFixtureImpl;
+import
org.apache.shardingsphere.infra.util.spi.fixture.singleton.SingletonSPIFixture;
import
org.apache.shardingsphere.infra.util.spi.fixture.singleton.impl.SingletonSPIFixtureImpl;
import org.junit.Test;
@@ -30,18 +30,19 @@ import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
public final class ShardingSphereServiceLoaderTest {
- @Test(expected = NullPointerException.class)
+ @Test
public void assertGetServiceInstancesWithNullValue() {
- ShardingSphereServiceLoader.getServiceInstances(null);
+ assertThrows(NullPointerException.class, () ->
ShardingSphereServiceLoader.getServiceInstances(null));
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void assertGetServiceInstancesWithNoInterface() {
- ShardingSphereServiceLoader.getServiceInstances(Object.class);
+ assertThrows(IllegalArgumentException.class, () ->
ShardingSphereServiceLoader.getServiceInstances(Object.class));
}
@Test
diff --git
a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/spi/type/typed/TypedSPILoaderTest.java
b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/spi/type/typed/TypedSPILoaderTest.java
index 040345ba377..3ebb4a6fe87 100644
---
a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/spi/type/typed/TypedSPILoaderTest.java
+++
b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/spi/type/typed/TypedSPILoaderTest.java
@@ -31,6 +31,7 @@ import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
public final class TypedSPILoaderTest {
@@ -66,8 +67,8 @@ public final class TypedSPILoaderTest {
assertNotNull(TypedSPILoader.getService(TypedSPIFixture.class,
"TYPED.ALIAS"));
}
- @Test(expected = ServiceProviderNotFoundServerException.class)
+ @Test
public void assertGetServiceWhenTypeIsNotExist() {
- TypedSPILoader.getService(TypedSPIFixture.class, "NOT_EXISTED");
+ assertThrows(ServiceProviderNotFoundServerException.class, () ->
TypedSPILoader.getService(TypedSPIFixture.class, "NOT_EXISTED"));
}
}
diff --git
a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/yaml/YamlEngineTest.java
b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/yaml/YamlEngineTest.java
index e3c1743ccf8..58387386df7 100644
---
a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/yaml/YamlEngineTest.java
+++
b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/yaml/YamlEngineTest.java
@@ -32,6 +32,7 @@ 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 YamlEngineTest {
@@ -87,7 +88,7 @@ public final class YamlEngineTest {
assertThat(YamlEngine.marshal(actual), is("name: test" +
System.lineSeparator()));
}
- @Test(expected = ConstructorException.class)
+ @Test
public void assertUnmarshalInvalidYaml() throws IOException {
URL url =
getClass().getClassLoader().getResource("yaml/accepted-class.yaml");
assertNotNull(url);
@@ -100,7 +101,7 @@ public final class YamlEngineTest {
yamlContent.append(line).append(System.lineSeparator());
}
}
- YamlEngine.unmarshal(yamlContent.toString(), Object.class);
+ assertThrows(ConstructorException.class, () ->
YamlEngine.unmarshal(yamlContent.toString(), Object.class));
}
@Test
diff --git
a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/yaml/constructor/ShardingSphereYamlConstructorTest.java
b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/yaml/constructor/ShardingSphereYamlConstructorTest.java
index 945a82971e4..0ad1bfa339b 100644
---
a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/yaml/constructor/ShardingSphereYamlConstructorTest.java
+++
b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/yaml/constructor/ShardingSphereYamlConstructorTest.java
@@ -27,8 +27,9 @@ import java.io.InputStream;
import java.util.Arrays;
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.assertThrows;
public final class ShardingSphereYamlConstructorTest {
@@ -49,10 +50,10 @@ public final class ShardingSphereYamlConstructorTest {
assertNotNull(actual.getCustomizedClass());
}
- @Test(expected = ConstructorException.class)
+ @Test
public void assertToObjectWithNotAcceptClass() throws IOException {
try (InputStream inputStream =
ShardingSphereYamlConstructorTest.class.getClassLoader().getResourceAsStream("yaml/accepted-class.yaml"))
{
- new Yaml(new
ShardingSphereYamlConstructor(Object.class)).loadAs(inputStream, Object.class);
+ assertThrows(ConstructorException.class, () -> new Yaml(new
ShardingSphereYamlConstructor(Object.class)).loadAs(inputStream, Object.class));
}
}
}