You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by to...@apache.org on 2022/04/09 15:27:25 UTC
[shardingsphere] branch master updated: Revise pr 16693 code style (#16702)
This is an automated email from the ASF dual-hosted git repository.
totalo 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 a47cec3916c Revise pr 16693 code style (#16702)
a47cec3916c is described below
commit a47cec3916c8fd2d4e2902b7bd440899f9f06c65
Author: Zhengqiang Duan <du...@apache.org>
AuthorDate: Sat Apr 9 23:27:19 2022 +0800
Revise pr 16693 code style (#16702)
* Revise pr 16693
* fix unit test
---
.../schema/util/IndexMetaDataUtilTest.java | 54 ++++++++--------------
1 file changed, 20 insertions(+), 34 deletions(-)
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/util/IndexMetaDataUtilTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/util/IndexMetaDataUtilTest.java
index e2560c521d4..7297c5a1404 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/util/IndexMetaDataUtilTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/util/IndexMetaDataUtilTest.java
@@ -17,9 +17,7 @@
package org.apache.shardingsphere.infra.metadata.schema.util;
-import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
-import lombok.SneakyThrows;
import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
import org.apache.shardingsphere.infra.metadata.schema.model.IndexMetaData;
import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData;
@@ -27,30 +25,21 @@ import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexSe
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Answers;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-import javax.sql.DataSource;
-import java.sql.Connection;
-import java.sql.SQLException;
+import java.util.Arrays;
import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-@RunWith(MockitoJUnitRunner.class)
public final class IndexMetaDataUtilTest {
-
- private static final String TABLE = "table";
-
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private DataSource dataSource;
-
+
+ private static final String TABLE_NAME = "t_order";
+
+ private static final String INDEX_NAME = "user_id_idx";
+
@Test
public void assertGetLogicIndexNameWithIndexNameSuffix() {
assertThat(IndexMetaDataUtil.getLogicIndexName("order_index_t_order", "t_order"), is("order_index"));
@@ -75,27 +64,24 @@ public final class IndexMetaDataUtilTest {
public void assertGetActualIndexNameWithoutActualTableName() {
assertThat(IndexMetaDataUtil.getActualIndexName("order_index", null), is("order_index"));
}
-
+
@Test
public void assertGetGeneratedLogicIndexName() {
- ColumnSegment columnSegment = new ColumnSegment(0, 0, new IdentifierValue("user_id"));
- ColumnSegment columnSegment1 = new ColumnSegment(0, 0, new IdentifierValue("user_name"));
- assertThat(IndexMetaDataUtil.getGeneratedLogicIndexName(Lists.newArrayList(columnSegment, columnSegment1)), is("user_id_user_name_idx"));
+ ColumnSegment userIdColumnSegment = new ColumnSegment(0, 0, new IdentifierValue("user_id"));
+ ColumnSegment userNameColumnSegment = new ColumnSegment(0, 0, new IdentifierValue("user_name"));
+ assertThat(IndexMetaDataUtil.getGeneratedLogicIndexName(Arrays.asList(userIdColumnSegment, userNameColumnSegment)), is("user_id_user_name_idx"));
}
-
+
@Test
- @SneakyThrows(SQLException.class)
public void assertGetTableNamesFromMetaData() {
- Connection connection = mock(Connection.class, RETURNS_DEEP_STUBS);
- when(dataSource.getConnection()).thenReturn(connection);
- ShardingSphereSchema schema = buildSchema();
- IndexSegment indexSegment1 = new IndexSegment(0, 0, new IdentifierValue(TABLE));
- assertThat(IndexMetaDataUtil.getTableNamesFromMetaData(schema, Lists.newArrayList(indexSegment1)), is(Collections.singletonList(TABLE)));
+ IndexSegment indexSegment = new IndexSegment(0, 0, new IdentifierValue(INDEX_NAME));
+ assertThat(IndexMetaDataUtil.getTableNamesFromMetaData(buildSchema(), Lists.newArrayList(indexSegment)), is(Collections.singletonList(TABLE_NAME)));
}
-
+
private ShardingSphereSchema buildSchema() {
- IndexMetaData indexMetaData = new IndexMetaData(TABLE);
- TableMetaData tableMetaData = new TableMetaData(TABLE, Collections.emptyList(), Collections.singletonList(indexMetaData), Collections.emptyList());
- return new ShardingSphereSchema(ImmutableMap.of(TABLE, tableMetaData));
+ TableMetaData tableMetaData = new TableMetaData(TABLE_NAME, Collections.emptyList(), Collections.singletonList(new IndexMetaData(INDEX_NAME)), Collections.emptyList());
+ Map<String, TableMetaData> tables = new HashMap<>(1, 1);
+ tables.put(TABLE_NAME, tableMetaData);
+ return new ShardingSphereSchema(tables);
}
}