Skip to content

Commit 9f4a9b3

Browse files
authored
Fixes code inspections on feature module (#38762)
* Fixes code inspections on feature module * Fixes code inspections on feature module
1 parent 0152e13 commit 9f4a9b3

23 files changed

Lines changed: 83 additions & 59 deletions

File tree

features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/config/EncryptRuleConfigurationCheckerTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
import static org.hamcrest.Matchers.is;
3939
import static org.hamcrest.MatcherAssert.assertThat;
40+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
4041
import static org.junit.jupiter.api.Assertions.assertThrows;
4142

4243
class EncryptRuleConfigurationCheckerTest {
@@ -53,7 +54,7 @@ void setUp() {
5354
@Test
5455
void assertCheckSuccess() {
5556
EncryptRuleConfiguration ruleConfig = createValidRuleConfiguration();
56-
checker.check("foo_db", ruleConfig, Collections.emptyMap(), Collections.emptyList());
57+
assertDoesNotThrow(() -> checker.check("foo_db", ruleConfig, Collections.emptyMap(), Collections.emptyList()));
5758
}
5859

5960
private EncryptRuleConfiguration createValidRuleConfiguration() {

features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/context/EncryptSQLRewriteContextDecoratorTest.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,10 @@ void assertDecorateWithoutEncryptTable() {
8585
decorator.decorate(rule, mock(ConfigurationProperties.class), sqlRewriteContext, mock(RouteContext.class));
8686
assertTrue(sqlRewriteContext.getSqlTokens().isEmpty());
8787
}
88-
// CHECKSTYLE:OFF
88+
8989
@Test
9090
void assertDecorateWithoutDroppedEncryptTable() {
91-
// CHECKSTYLE:ON
92-
EncryptColumnRuleConfiguration columnConfig = new EncryptColumnRuleConfiguration("pwd", new EncryptColumnItemRuleConfiguration("pwd_cipher", "standard_encryptor"));
93-
EncryptTableRuleConfiguration tableConfig = new EncryptTableRuleConfiguration("t_encrypt", Collections.singleton(columnConfig));
94-
EncryptRuleConfiguration ruleConfig = new EncryptRuleConfiguration(new LinkedList<>(Collections.singleton(tableConfig)),
95-
Collections.singletonMap("standard_encryptor", new AlgorithmConfiguration("CORE.FIXTURE", new Properties())));
96-
new EncryptTableChangedProcessor().dropRuleItemConfiguration("t_encrypt", ruleConfig);
91+
EncryptRuleConfiguration ruleConfig = getEncryptRuleConfiguration();
9792
SQLRewriteContext sqlRewriteContext = mock(SQLRewriteContext.class);
9893
InsertStatementContext insertStatementContext = mock(InsertStatementContext.class, RETURNS_DEEP_STUBS);
9994
when(insertStatementContext.getTablesContext().getSimpleTables()).thenReturn(Collections.singleton(
@@ -102,4 +97,13 @@ void assertDecorateWithoutDroppedEncryptTable() {
10297
decorator.decorate(new EncryptRule("foo_db", ruleConfig), mock(ConfigurationProperties.class), sqlRewriteContext, mock(RouteContext.class));
10398
verify(sqlRewriteContext, never()).addSQLTokenGenerators(any());
10499
}
100+
101+
private EncryptRuleConfiguration getEncryptRuleConfiguration() {
102+
EncryptColumnRuleConfiguration columnConfig = new EncryptColumnRuleConfiguration("pwd", new EncryptColumnItemRuleConfiguration("pwd_cipher", "standard_encryptor"));
103+
EncryptTableRuleConfiguration tableConfig = new EncryptTableRuleConfiguration("t_encrypt", Collections.singleton(columnConfig));
104+
EncryptRuleConfiguration result = new EncryptRuleConfiguration(new LinkedList<>(Collections.singleton(tableConfig)),
105+
Collections.singletonMap("standard_encryptor", new AlgorithmConfiguration("CORE.FIXTURE", new Properties())));
106+
new EncryptTableChangedProcessor().dropRuleItemConfiguration("t_encrypt", result);
107+
return result;
108+
}
105109
}

features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleExecutorTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545

4646
import static org.hamcrest.Matchers.is;
4747
import static org.hamcrest.MatcherAssert.assertThat;
48+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
4849
import static org.junit.jupiter.api.Assertions.assertThrows;
4950
import static org.junit.jupiter.api.Assertions.assertTrue;
5051
import static org.mockito.ArgumentMatchers.any;
@@ -95,7 +96,7 @@ void assertExecuteUpdateWithAssistQueryAndLikeColumns() throws SQLException {
9596
MetaDataManagerPersistService metaDataManagerPersistService = contextManager.getPersistServiceFacade().getModeFacade().getMetaDataManagerService();
9697
new DistSQLUpdateExecuteEngine(createSQLStatementWithAssistQueryAndLikeColumns(), "foo_db", contextManager, null).executeUpdate();
9798
metaDataManagerPersistService.removeRuleConfigurationItem(any(), ArgumentMatchers.argThat(this::assertToBeDroppedRuleConfiguration));
98-
metaDataManagerPersistService.alterRuleConfiguration(any(), ArgumentMatchers.argThat(this::assertToBeAlteredRuleConfiguration));
99+
assertDoesNotThrow(() -> metaDataManagerPersistService.alterRuleConfiguration(any(), ArgumentMatchers.argThat(this::assertToBeAlteredRuleConfiguration)));
99100
}
100101

101102
@Test
@@ -107,7 +108,7 @@ void assertExecuteUpdateWithoutAssistQueryAndLikeColumns() throws SQLException {
107108
new DistSQLUpdateExecuteEngine(createSQLStatementWithoutAssistQueryAndLikeColumns(), "foo_db", contextManager, null).executeUpdate();
108109
MetaDataManagerPersistService metaDataManagerPersistService = contextManager.getPersistServiceFacade().getModeFacade().getMetaDataManagerService();
109110
metaDataManagerPersistService.removeRuleConfigurationItem(any(), ArgumentMatchers.argThat(this::assertToBeDroppedRuleConfiguration));
110-
metaDataManagerPersistService.alterRuleConfiguration(any(), ArgumentMatchers.argThat(this::assertToBeAlteredRuleConfiguration));
111+
assertDoesNotThrow(() -> metaDataManagerPersistService.alterRuleConfiguration(any(), ArgumentMatchers.argThat(this::assertToBeAlteredRuleConfiguration)));
111112
}
112113

113114
private ContextManager mockContextManager(final EncryptRule rule) {

features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleExecutorTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import java.util.LinkedList;
4545
import java.util.Properties;
4646

47+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
4748
import static org.junit.jupiter.api.Assertions.assertFalse;
4849
import static org.junit.jupiter.api.Assertions.assertThrows;
4950
import static org.mockito.ArgumentMatchers.any;
@@ -101,7 +102,7 @@ void assertExecuteUpdateWithIfNotExists() throws SQLException {
101102
ContextManager contextManager = mockContextManager(rule);
102103
new DistSQLUpdateExecuteEngine(sqlStatement, "foo_db", contextManager, null).executeUpdate();
103104
MetaDataManagerPersistService metaDataManagerPersistService = contextManager.getPersistServiceFacade().getModeFacade().getMetaDataManagerService();
104-
metaDataManagerPersistService.alterRuleConfiguration(any(), ArgumentMatchers.argThat(this::assertIfNotExistsRuleConfiguration));
105+
assertDoesNotThrow(() -> metaDataManagerPersistService.alterRuleConfiguration(any(), ArgumentMatchers.argThat(this::assertIfNotExistsRuleConfiguration)));
105106
}
106107

107108
private CreateEncryptRuleStatement createAESEncryptRuleSQLStatement() {

features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleExecutorTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545

4646
import static org.hamcrest.Matchers.is;
4747
import static org.hamcrest.MatcherAssert.assertThat;
48+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
4849
import static org.junit.jupiter.api.Assertions.assertThrows;
4950
import static org.junit.jupiter.api.Assertions.assertTrue;
5051
import static org.mockito.ArgumentMatchers.any;
@@ -71,7 +72,7 @@ void assertExecuteUpdate() throws SQLException {
7172
ContextManager contextManager = mockContextManager(rule);
7273
new DistSQLUpdateExecuteEngine(createSQLStatement("T_ENCRYPT"), "foo_db", contextManager, null).executeUpdate();
7374
MetaDataManagerPersistService metaDataManagerPersistService = contextManager.getPersistServiceFacade().getModeFacade().getMetaDataManagerService();
74-
metaDataManagerPersistService.alterRuleConfiguration(any(), ArgumentMatchers.argThat(this::assertRuleConfiguration));
75+
assertDoesNotThrow(() -> metaDataManagerPersistService.alterRuleConfiguration(any(), ArgumentMatchers.argThat(this::assertRuleConfiguration)));
7576
}
7677

7778
@Test
@@ -101,7 +102,7 @@ void assertExecuteUpdateWithInUsedEncryptor() throws SQLException {
101102
ContextManager contextManager = mockContextManager(rule);
102103
new DistSQLUpdateExecuteEngine(createSQLStatement("T_ENCRYPT"), "foo_db", contextManager, null).executeUpdate();
103104
MetaDataManagerPersistService metaDataManagerPersistService = contextManager.getPersistServiceFacade().getModeFacade().getMetaDataManagerService();
104-
metaDataManagerPersistService.alterRuleConfiguration(any(), ArgumentMatchers.argThat(this::assertRuleConfigurationWithoutEncryptors));
105+
assertDoesNotThrow(() -> metaDataManagerPersistService.alterRuleConfiguration(any(), ArgumentMatchers.argThat(this::assertRuleConfigurationWithoutEncryptors)));
105106
}
106107

107108
private boolean assertRuleConfigurationWithoutEncryptors(final EncryptRuleConfiguration actual) {
@@ -119,7 +120,7 @@ void assertExecuteUpdateWithIfExists() throws SQLException {
119120
ContextManager contextManager = mockContextManager(rule);
120121
new DistSQLUpdateExecuteEngine(statement, "foo_db", contextManager, null).executeUpdate();
121122
MetaDataManagerPersistService metaDataManagerPersistService = contextManager.getPersistServiceFacade().getModeFacade().getMetaDataManagerService();
122-
metaDataManagerPersistService.alterRuleConfiguration(any(), ArgumentMatchers.argThat(this::assertRuleConfigurationWithoutEncryptors));
123+
assertDoesNotThrow(() -> metaDataManagerPersistService.alterRuleConfiguration(any(), ArgumentMatchers.argThat(this::assertRuleConfigurationWithoutEncryptors)));
123124
}
124125

125126
private DropEncryptRuleStatement createSQLStatement(final String tableName) {

features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/MaskAlgorithmPropertiesCheckerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void assertCheckAtLeastOneCharFailedWithEmptyChar() {
7070
@Test
7171
void assertCheckPositiveIntegerSuccess() {
7272
Properties props = PropertiesBuilder.build(new Property("key", "123"));
73-
MaskAlgorithmPropertiesChecker.checkPositiveInteger(props, "key", mock(MaskAlgorithm.class));
73+
assertDoesNotThrow(() -> MaskAlgorithmPropertiesChecker.checkPositiveInteger(props, "key", mock(MaskAlgorithm.class)));
7474
}
7575

7676
@Test

features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/update/CreateMaskRuleExecutorTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
import static org.hamcrest.Matchers.is;
4343
import static org.hamcrest.MatcherAssert.assertThat;
44+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
4445
import static org.junit.jupiter.api.Assertions.assertThrows;
4546
import static org.junit.jupiter.api.Assertions.assertTrue;
4647
import static org.mockito.ArgumentMatchers.any;
@@ -66,7 +67,7 @@ void assertExecuteUpdateWithoutIfNotExists() throws SQLException {
6667
ContextManager contextManager = mockContextManager(rule);
6768
new DistSQLUpdateExecuteEngine(sqlStatement, "foo_db", contextManager, null).executeUpdate();
6869
MetaDataManagerPersistService metaDataManagerPersistService = contextManager.getPersistServiceFacade().getModeFacade().getMetaDataManagerService();
69-
metaDataManagerPersistService.alterRuleConfiguration(any(), ArgumentMatchers.argThat(this::assertRuleConfiguration));
70+
assertDoesNotThrow(() -> metaDataManagerPersistService.alterRuleConfiguration(any(), ArgumentMatchers.argThat(this::assertRuleConfiguration)));
7071
}
7172

7273
@Test
@@ -78,7 +79,7 @@ void assertExecuteUpdateWithIfNotExists() throws SQLException {
7879
ContextManager contextManager = mockContextManager(rule);
7980
new DistSQLUpdateExecuteEngine(sqlStatement, "foo_db", contextManager, null).executeUpdate();
8081
MetaDataManagerPersistService metaDataManagerPersistService = contextManager.getPersistServiceFacade().getModeFacade().getMetaDataManagerService();
81-
metaDataManagerPersistService.alterRuleConfiguration(any(), ArgumentMatchers.argThat(this::assertRuleConfiguration));
82+
assertDoesNotThrow(() -> metaDataManagerPersistService.alterRuleConfiguration(any(), ArgumentMatchers.argThat(this::assertRuleConfiguration)));
8283
}
8384

8485
private CreateMaskRuleStatement createSQLStatement(final boolean ifNotExists, final String algorithmType) {

features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/update/DropMaskRuleExecutorTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
import static org.hamcrest.Matchers.is;
4242
import static org.hamcrest.MatcherAssert.assertThat;
43+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
4344
import static org.junit.jupiter.api.Assertions.assertThrows;
4445
import static org.junit.jupiter.api.Assertions.assertTrue;
4546
import static org.mockito.ArgumentMatchers.any;
@@ -64,7 +65,7 @@ void assertExecuteUpdateWithoutIfExists() throws SQLException {
6465
ContextManager contextManager = mockContextManager(rule);
6566
new DistSQLUpdateExecuteEngine(createSQLStatement(false, "T_MASK"), "foo_db", contextManager, null).executeUpdate();
6667
MetaDataManagerPersistService metaDataManagerPersistService = contextManager.getPersistServiceFacade().getModeFacade().getMetaDataManagerService();
67-
metaDataManagerPersistService.alterRuleConfiguration(any(), ArgumentMatchers.argThat(this::assertRuleConfigurationWithoutIfExists));
68+
assertDoesNotThrow(() -> metaDataManagerPersistService.alterRuleConfiguration(any(), ArgumentMatchers.argThat(this::assertRuleConfigurationWithoutIfExists)));
6869
}
6970

7071
private boolean assertRuleConfigurationWithoutIfExists(final MaskRuleConfiguration actual) {
@@ -83,7 +84,7 @@ void assertExecuteUpdateWithIfExists() throws SQLException {
8384
new DistSQLUpdateExecuteEngine(createSQLStatement(true, "T_USER"), "foo_db", contextManager, null).executeUpdate();
8485
MetaDataManagerPersistService metaDataManagerPersistService = contextManager.getPersistServiceFacade().getModeFacade().getMetaDataManagerService();
8586
metaDataManagerPersistService.alterRuleConfiguration(any(), ArgumentMatchers.argThat(this::assertRuleConfigurationWithoutIfExists));
86-
metaDataManagerPersistService.alterRuleConfiguration(any(), ArgumentMatchers.argThat(this::assertRuleConfigurationWithIfExists));
87+
assertDoesNotThrow(() -> metaDataManagerPersistService.alterRuleConfiguration(any(), ArgumentMatchers.argThat(this::assertRuleConfigurationWithIfExists)));
8788
}
8889

8990
private DropMaskRuleStatement createSQLStatement(final boolean ifExists, final String tableName) {

features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationCheckerTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545

4646
import static org.hamcrest.Matchers.is;
4747
import static org.hamcrest.MatcherAssert.assertThat;
48+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
4849
import static org.junit.jupiter.api.Assertions.assertThrows;
4950
import static org.junit.jupiter.api.Assertions.assertTrue;
5051
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
@@ -108,7 +109,7 @@ void assertCheckWhenConfigOtherRulesDatasource() {
108109
DataSourceMapperRuleAttribute ruleAttribute = mock(DataSourceMapperRuleAttribute.class, RETURNS_DEEP_STUBS);
109110
when(ruleAttribute.getDataSourceMapper().containsKey("otherDatasourceName")).thenReturn(true);
110111
when(rule.getAttributes()).thenReturn(new RuleAttributes(ruleAttribute));
111-
checker.check("test", ruleConfig, mockDataSources(), Collections.singleton(rule));
112+
assertDoesNotThrow(() -> checker.check("test", ruleConfig, mockDataSources(), Collections.singleton(rule)));
112113
}
113114

114115
private ReadwriteSplittingRuleConfiguration createContainsOtherRulesDatasourceConfiguration() {

features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/ColumnShadowValueValidatorTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import java.util.Date;
2424

25+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
2526
import static org.junit.jupiter.api.Assertions.assertThrows;
2627
import static org.mockito.Mockito.mock;
2728

@@ -39,6 +40,6 @@ void assertValidateEnumType() {
3940

4041
@Test
4142
void assertValidateAcceptedType() {
42-
ColumnShadowValueValidator.validate("foo_tbl", "foo_col", "");
43+
assertDoesNotThrow(() -> ColumnShadowValueValidator.validate("foo_tbl", "foo_col", ""));
4344
}
4445
}

0 commit comments

Comments
 (0)