You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2023/03/02 00:10:58 UTC
[shardingsphere] branch master updated: Use assertThat isEmpty to instead of assertThat size is 0 (#24412)
This is an automated email from the ASF dual-hosted git repository.
zhaojinchao 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 1a1e5060f04 Use assertThat isEmpty to instead of assertThat size is 0 (#24412)
1a1e5060f04 is described below
commit 1a1e5060f04516c5d1e887aa32ac5b8b294246ab
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Thu Mar 2 08:10:42 2023 +0800
Use assertThat isEmpty to instead of assertThat size is 0 (#24412)
---
.../mysql/ingest/client/netty/MySQLBinlogEventPacketDecoderTest.java | 5 +++--
.../mode/manager/switcher/ResourceSwitchManagerTest.java | 2 +-
.../metadata/persist/service/DatabaseMetaDataPersistServiceTest.java | 4 ++--
.../queryable/ShowStatusFromReadwriteSplittingRulesExecutorTest.java | 5 ++---
.../rdl/storage/unit/RegisterStorageUnitBackendHandlerTest.java | 3 +--
.../pipeline/cases/migration/general/MySQLMigrationGeneralE2EIT.java | 2 +-
.../cases/migration/general/PostgreSQLMigrationGeneralE2EIT.java | 5 ++---
.../pipeline/cases/migration/primarykey/IndexesMigrationE2EIT.java | 3 ++-
.../pipeline/cases/migration/primarykey/MariaDBMigrationE2EIT.java | 3 ++-
.../cases/migration/primarykey/TextPrimaryKeyMigrationE2EIT.java | 5 ++---
10 files changed, 18 insertions(+), 19 deletions(-)
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 a3d5f3c7162..9664b695c4b 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
@@ -48,6 +48,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.assertTrue;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
@@ -89,7 +90,7 @@ public final class MySQLBinlogEventPacketDecoderTest {
byteBuf.writeBytes(StringUtil.decodeHexDump("000000000004010000002c0000000000000020001a9100000000000062696e6c6f672e3030303032394af65c24"));
List<Object> decodedEvents = new LinkedList<>();
binlogEventPacketDecoder.decode(channelHandlerContext, byteBuf, decodedEvents);
- assertThat(decodedEvents.size(), is(0));
+ assertTrue(decodedEvents.isEmpty());
assertThat(binlogContext.getFileName(), is("binlog.000029"));
}
@@ -100,7 +101,7 @@ public final class MySQLBinlogEventPacketDecoderTest {
+ "000000000013000d0008000000000400040000006100041a08000000080808020000000a0a0a2a2a001234000a280140081396"));
List<Object> decodedEvents = new LinkedList<>();
binlogEventPacketDecoder.decode(channelHandlerContext, byteBuf, decodedEvents);
- assertThat(decodedEvents.size(), is(0));
+ assertTrue(decodedEvents.isEmpty());
assertThat(binlogContext.getChecksumLength(), is(4));
}
diff --git a/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/switcher/ResourceSwitchManagerTest.java b/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/switcher/ResourceSwitchManagerTest.java
index 4371572b31c..64c3192d9e1 100644
--- a/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/switcher/ResourceSwitchManagerTest.java
+++ b/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/switcher/ResourceSwitchManagerTest.java
@@ -49,7 +49,7 @@ public final class ResourceSwitchManagerTest {
dataSourceMap.put("ds_0", new MockedDataSource());
dataSourceMap.put("ds_1", new MockedDataSource());
SwitchingResource actual = new ResourceSwitchManager().createByAlterDataSourceProps(new ShardingSphereResourceMetaData("sharding_db", dataSourceMap), Collections.emptyMap());
- assertThat(actual.getNewDataSources().size(), is(0));
+ assertTrue(actual.getNewDataSources().isEmpty());
assertThat(actual.getStaleDataSources().size(), is(2));
actual.closeStaleDataSources();
assertStaleDataSource((MockedDataSource) dataSourceMap.get("ds_0"));
diff --git a/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/service/DatabaseMetaDataPersistServiceTest.java b/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/service/DatabaseMetaDataPersistServiceTest.java
index 68199e349d8..9cd2104873e 100644
--- a/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/service/DatabaseMetaDataPersistServiceTest.java
+++ b/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/service/DatabaseMetaDataPersistServiceTest.java
@@ -42,6 +42,7 @@ import java.util.stream.Collectors;
import static org.hamcrest.CoreMatchers.hasItems;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;
@@ -123,8 +124,7 @@ public final class DatabaseMetaDataPersistServiceTest {
when(repository.getDirectly("/metadata/foo_db/schemas/foo_schema/tables/t_order")).thenReturn(readYAML());
Map<String, ShardingSphereSchema> schema = databaseMetaDataPersistService.loadSchemas("foo_db");
assertThat(schema.size(), is(1));
- Map<String, ShardingSphereSchema> empty = databaseMetaDataPersistService.loadSchemas("test");
- assertThat(empty.size(), is(0));
+ assertTrue(databaseMetaDataPersistService.loadSchemas("test").isEmpty());
assertThat(schema.get("foo_schema").getAllTableNames(), is(Collections.singleton("t_order")));
assertThat(schema.get("foo_schema").getTable("t_order").getIndexes().keySet(), is(Collections.singleton("primary")));
assertThat(schema.get("foo_schema").getAllColumnNames("t_order").size(), is(1));
diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowStatusFromReadwriteSplittingRulesExecutorTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowStatusFromReadwriteSplittingRulesExecutorTest.java
index a0f2c4078bb..d5c7d4213db 100644
--- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowStatusFromReadwriteSplittingRulesExecutorTest.java
+++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowStatusFromReadwriteSplittingRulesExecutorTest.java
@@ -51,7 +51,7 @@ import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -82,8 +82,7 @@ public final class ShowStatusFromReadwriteSplittingRulesExecutorTest {
when(ProxyContext.getInstance().databaseExists("readwrite_db")).thenReturn(true);
Collection<LocalDataQueryResultRow> actual = executor.getRows(mockMetaData(), connectionSession,
new ShowStatusFromReadwriteSplittingRulesStatement(new DatabaseSegment(1, 1, new IdentifierValue("readwrite_db")), null));
- assertThat(actual.size(), is(0));
- assertFalse(actual.iterator().hasNext());
+ assertTrue(actual.isEmpty());
}
private ContextManager mockContextManager() {
diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/storage/unit/RegisterStorageUnitBackendHandlerTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/storage/unit/RegisterStorageUnitBackendHandlerTest.java
index 29a2a92e2f7..b7bf3ed5d80 100644
--- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/storage/unit/RegisterStorageUnitBackendHandlerTest.java
+++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/storage/unit/RegisterStorageUnitBackendHandlerTest.java
@@ -72,8 +72,7 @@ public final class RegisterStorageUnitBackendHandlerTest {
when(connectionSession.getProtocolType()).thenReturn(new MySQLDatabaseType());
when(database.getRuleMetaData()).thenReturn(mock(ShardingSphereRuleMetaData.class));
handler = new RegisterStorageUnitBackendHandler(mock(RegisterStorageUnitStatement.class), connectionSession);
- Plugins.getMemberAccessor().set(
- handler.getClass().getDeclaredField("validateHandler"), handler, mock(DataSourcePropertiesValidateHandler.class));
+ Plugins.getMemberAccessor().set(handler.getClass().getDeclaredField("validateHandler"), handler, mock(DataSourcePropertiesValidateHandler.class));
}
@Test
diff --git a/test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/cases/migration/general/MySQLMigrationGeneralE2EIT.java b/test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/cases/migration/general/MySQLMigrationGeneralE2EIT.java
index ac8a106f501..4904d4c15d4 100644
--- a/test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/cases/migration/general/MySQLMigrationGeneralE2EIT.java
+++ b/test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/cases/migration/general/MySQLMigrationGeneralE2EIT.java
@@ -107,7 +107,7 @@ public final class MySQLMigrationGeneralE2EIT extends AbstractMigrationE2EIT {
commitMigrationByJobId(each);
}
List<String> lastJobIds = listJobId();
- assertThat(lastJobIds.size(), is(0));
+ assertTrue(lastJobIds.isEmpty());
proxyExecuteWithLog("REFRESH TABLE METADATA", 2);
assertGreaterThanOrderTableInitRows(PipelineBaseE2EIT.TABLE_INIT_ROW_COUNT, "");
log.info("{} E2E IT finished, database type={}, docker image={}", this.getClass().getName(), testParam.getDatabaseType(), testParam.getStorageContainerImage());
diff --git a/test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/cases/migration/general/PostgreSQLMigrationGeneralE2EIT.java b/test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/cases/migration/general/PostgreSQLMigrationGeneralE2EIT.java
index 0b953aad941..2a4893bd0a4 100644
--- a/test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/cases/migration/general/PostgreSQLMigrationGeneralE2EIT.java
+++ b/test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/cases/migration/general/PostgreSQLMigrationGeneralE2EIT.java
@@ -41,8 +41,7 @@ import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertTrue;
@RunWith(Parameterized.class)
@Slf4j
@@ -100,7 +99,7 @@ public final class PostgreSQLMigrationGeneralE2EIT extends AbstractMigrationE2EI
commitMigrationByJobId(each);
}
List<String> lastJobIds = listJobId();
- assertThat(lastJobIds.size(), is(0));
+ assertTrue(lastJobIds.isEmpty());
proxyExecuteWithLog("REFRESH TABLE METADATA", 2);
assertGreaterThanOrderTableInitRows(PipelineBaseE2EIT.TABLE_INIT_ROW_COUNT + 1, PipelineBaseE2EIT.SCHEMA_NAME);
log.info("{} E2E IT finished, database type={}, docker image={}", this.getClass().getName(), testParam.getDatabaseType(), testParam.getStorageContainerImage());
diff --git a/test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/cases/migration/primarykey/IndexesMigrationE2EIT.java b/test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/cases/migration/primarykey/IndexesMigrationE2EIT.java
index a2e11733595..aace00f413a 100644
--- a/test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/cases/migration/primarykey/IndexesMigrationE2EIT.java
+++ b/test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/cases/migration/primarykey/IndexesMigrationE2EIT.java
@@ -43,6 +43,7 @@ import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertTrue;
/**
* E2E IT for different types of indexes, includes:
@@ -174,6 +175,6 @@ public final class IndexesMigrationE2EIT extends AbstractMigrationE2EIT {
proxyExecuteWithLog("REFRESH TABLE METADATA", 1);
assertThat(getTargetTableRecordsCount(getSourceTableOrderName()), is(PipelineBaseE2EIT.TABLE_INIT_ROW_COUNT + 1));
List<String> lastJobIds = listJobId();
- assertThat(lastJobIds.size(), is(0));
+ assertTrue(lastJobIds.isEmpty());
}
}
diff --git a/test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/cases/migration/primarykey/MariaDBMigrationE2EIT.java b/test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/cases/migration/primarykey/MariaDBMigrationE2EIT.java
index 8de9e8d04cf..3317211d3fe 100644
--- a/test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/cases/migration/primarykey/MariaDBMigrationE2EIT.java
+++ b/test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/cases/migration/primarykey/MariaDBMigrationE2EIT.java
@@ -40,6 +40,7 @@ import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertTrue;
@RunWith(Parameterized.class)
@Slf4j
@@ -93,6 +94,6 @@ public final class MariaDBMigrationE2EIT extends AbstractMigrationE2EIT {
proxyExecuteWithLog("REFRESH TABLE METADATA", 1);
assertThat(getTargetTableRecordsCount(getSourceTableOrderName()), is(PipelineBaseE2EIT.TABLE_INIT_ROW_COUNT + 1));
List<String> lastJobIds = listJobId();
- assertThat(lastJobIds.size(), is(0));
+ assertTrue(lastJobIds.isEmpty());
}
}
diff --git a/test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/cases/migration/primarykey/TextPrimaryKeyMigrationE2EIT.java b/test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/cases/migration/primarykey/TextPrimaryKeyMigrationE2EIT.java
index 559053f34a8..09d0c883c75 100644
--- a/test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/cases/migration/primarykey/TextPrimaryKeyMigrationE2EIT.java
+++ b/test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/cases/migration/primarykey/TextPrimaryKeyMigrationE2EIT.java
@@ -40,8 +40,7 @@ import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertTrue;
@RunWith(Parameterized.class)
@Slf4j
@@ -100,7 +99,7 @@ public class TextPrimaryKeyMigrationE2EIT extends AbstractMigrationE2EIT {
assertCheckMigrationSuccess(jobId, "DATA_MATCH");
commitMigrationByJobId(jobId);
List<String> lastJobIds = listJobId();
- assertThat(lastJobIds.size(), is(0));
+ assertTrue(lastJobIds.isEmpty());
log.info("{} E2E IT finished, database type={}, docker image={}", this.getClass().getName(), testParam.getDatabaseType(), testParam.getStorageContainerImage());
}
}