Skip to content

Commit

Permalink
Refactor usage of IndexMetaData's constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed Nov 14, 2024
1 parent d1a9f62 commit 2bb796a
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ void assertRevise() {
ShardingTable shardingTable = mock(ShardingTable.class);
when(shardingTable.getActualDataNodes()).thenReturn(Arrays.asList(new DataNode("SCHEMA_NAME", "TABLE_NAME_0"), new DataNode("SCHEMA_NAME", "TABLE_NAME_1")));
shardingIndexReviser = new ShardingIndexReviser(shardingTable);
IndexMetaData originalMetaData = new IndexMetaData("TEST_INDEX");
originalMetaData.getColumns().add("TEST_COLUMN");
IndexMetaData originalMetaData = new IndexMetaData("TEST_INDEX", Collections.singletonList("TEST_COLUMN"));
originalMetaData.setUnique(false);
Optional<IndexMetaData> revisedMetaData = shardingIndexReviser.revise("TABLE_NAME_0", originalMetaData, shardingRule);
assertTrue(revisedMetaData.isPresent());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ void assertReviseIsPresentIsTrue() {
IndexMetaData indexMetaData = new IndexMetaData("index");
doReturn(Optional.of(reviser)).when(metaDataReviseEntry).getIndexReviser(any(), anyString());
when(reviser.revise(anyString(), any(), any())).thenReturn(Optional.of(indexMetaData));
Collection<IndexMetaData> indexMetaDataCollection = Arrays.asList(new IndexMetaData("index1"), new IndexMetaData("index2"));
Collection<IndexMetaData> actual = indexReviseEngine.revise("tableName", indexMetaDataCollection);
Collection<IndexMetaData> indexMetaDataList = Arrays.asList(new IndexMetaData("index1"), new IndexMetaData("index2"));
Collection<IndexMetaData> actual = indexReviseEngine.revise("tableName", indexMetaDataList);
assertThat(actual.size(), equalTo(1));
assertTrue(actual.contains(indexMetaData));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ private void assertTableMetaDataMap(final Collection<SchemaMetaData> schemaMetaD
assertThat(columnsIterator.next(), is(new ColumnMetaData("mpt", Types.BINARY, false, false, false, true, false, true)));
assertThat(actualTableMetaData.getIndexes().size(), is(1));
Iterator<IndexMetaData> indexesIterator = actualTableMetaData.getIndexes().iterator();
IndexMetaData expected = new IndexMetaData("id");
expected.getColumns().add("id");
IndexMetaData expected = new IndexMetaData("id", Collections.singletonList("id"));
expected.setUnique(true);
assertThat(indexesIterator.next(), is(expected));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,8 @@ private void assertTableMetaDataMap(final Collection<SchemaMetaData> schemaMetaD
assertThat(columnsIterator.next(), is(new ColumnMetaData("name", Types.VARCHAR, false, false, true, true, false, true)));
assertThat(actualTableMetaData.getIndexes().size(), is(1));
Iterator<IndexMetaData> indexesIterator = actualTableMetaData.getIndexes().iterator();
IndexMetaData indexMetaData = new IndexMetaData("id");
IndexMetaData indexMetaData = new IndexMetaData("id", Collections.singletonList("id"));
indexMetaData.setUnique(true);
indexMetaData.getColumns().add("id");
assertThat(indexesIterator.next(), is(indexMetaData));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,11 @@ private void assertTableMetaDataMap(final Collection<SchemaMetaData> schemaMetaD
assertThat(columnsIterator.next(), is(new ColumnMetaData("name", Types.VARCHAR, false, false, true, true, false, true)));
assertThat(actualTableMetaData.getIndexes().size(), is(1));
Iterator<IndexMetaData> indexesIterator = actualTableMetaData.getIndexes().iterator();
IndexMetaData indexMetaData = new IndexMetaData("id");
IndexMetaData indexMetaData = new IndexMetaData("id", Collections.singletonList("id"));
indexMetaData.setUnique(true);
indexMetaData.getColumns().add("id");
assertThat(indexesIterator.next(), is(indexMetaData));
assertThat(actualTableMetaData.getConstraints().size(), is(1));
Iterator<ConstraintMetaData> constrainsIterator = actualTableMetaData.getConstraints().iterator();
assertThat(constrainsIterator.next(), is(new ConstraintMetaData("tbl_con", "refer_tbl")));
Iterator<ConstraintMetaData> constrainsMetaDataList = actualTableMetaData.getConstraints().iterator();
assertThat(constrainsMetaDataList.next(), is(new ConstraintMetaData("tbl_con", "refer_tbl")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,7 @@ private void assertTableMetaDataMap(final Collection<SchemaMetaData> schemaMetaD
assertThat(actualTableMetaData.getColumns().size(), is(2));
assertThat(actualTableMetaData.getIndexes().size(), is(1));
Iterator<IndexMetaData> indexesIterator = actualTableMetaData.getIndexes().iterator();
IndexMetaData expected = new IndexMetaData("id");
expected.getColumns().add("id");
IndexMetaData expected = new IndexMetaData("id", Collections.singletonList("id"));
expected.setUnique(true);
assertThat(indexesIterator.next(), is(expected));
}
Expand Down

0 comments on commit 2bb796a

Please sign in to comment.