From be40c22741458f0e60275293d60aa177cffd0398 Mon Sep 17 00:00:00 2001 From: zhaojinchao Date: Thu, 21 Sep 2023 22:10:39 +0800 Subject: [PATCH] Refactor MaskAlgorithmMetaData --- .../mask/merge/MaskResultDecoratorEngine.java | 2 +- .../mask/merge/dql/MaskAlgorithmMetaData.java | 3 --- .../mask/merge/dql/MaskAlgorithmMetaDataTest.java | 6 +----- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/merge/MaskResultDecoratorEngine.java b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/merge/MaskResultDecoratorEngine.java index 48244e006fe0a..a49a623652005 100644 --- a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/merge/MaskResultDecoratorEngine.java +++ b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/merge/MaskResultDecoratorEngine.java @@ -39,7 +39,7 @@ public final class MaskResultDecoratorEngine implements ResultDecoratorEngine> newInstance(final ShardingSphereDatabase database, final MaskRule maskRule, final ConfigurationProperties props, final SQLStatementContext sqlStatementContext) { return sqlStatementContext instanceof SelectStatementContext - ? Optional.of(new MaskDQLResultDecorator(new MaskAlgorithmMetaData(database, maskRule, (SelectStatementContext) sqlStatementContext))) + ? Optional.of(new MaskDQLResultDecorator(new MaskAlgorithmMetaData(maskRule, (SelectStatementContext) sqlStatementContext))) : Optional.empty(); } diff --git a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/merge/dql/MaskAlgorithmMetaData.java b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/merge/dql/MaskAlgorithmMetaData.java index 70b85687899b0..bdac706adbd00 100644 --- a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/merge/dql/MaskAlgorithmMetaData.java +++ b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/merge/dql/MaskAlgorithmMetaData.java @@ -21,7 +21,6 @@ import org.apache.shardingsphere.infra.binder.context.segment.select.projection.Projection; import org.apache.shardingsphere.infra.binder.context.segment.select.projection.impl.ColumnProjection; import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext; -import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.mask.rule.MaskRule; import org.apache.shardingsphere.mask.spi.MaskAlgorithm; @@ -35,8 +34,6 @@ @RequiredArgsConstructor public final class MaskAlgorithmMetaData { - private final ShardingSphereDatabase database; - private final MaskRule maskRule; private final SelectStatementContext selectStatementContext; diff --git a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/merge/dql/MaskAlgorithmMetaDataTest.java b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/merge/dql/MaskAlgorithmMetaDataTest.java index df4475a287dc4..8ad95a122c45f 100644 --- a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/merge/dql/MaskAlgorithmMetaDataTest.java +++ b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/merge/dql/MaskAlgorithmMetaDataTest.java @@ -20,7 +20,6 @@ import org.apache.shardingsphere.infra.binder.context.segment.select.projection.impl.ColumnProjection; import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext; import org.apache.shardingsphere.infra.database.core.type.DatabaseType; -import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.mask.rule.MaskRule; import org.apache.shardingsphere.mask.spi.MaskAlgorithm; @@ -43,9 +42,6 @@ @ExtendWith(MockitoExtension.class) class MaskAlgorithmMetaDataTest { - @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private ShardingSphereDatabase database; - @Mock private MaskRule maskRule; @@ -61,7 +57,7 @@ void assertFindMaskAlgorithmByColumnIndex() { columnProjection.setOriginalTable(new IdentifierValue("t_order")); when(selectStatementContext.getProjectionsContext().getExpandProjections()).thenReturn(Collections.singletonList(columnProjection)); when(selectStatementContext.getTablesContext().getTableNames()).thenReturn(Collections.singleton("t_order")); - Optional actual = new MaskAlgorithmMetaData(database, maskRule, selectStatementContext).findMaskAlgorithmByColumnIndex(1); + Optional actual = new MaskAlgorithmMetaData(maskRule, selectStatementContext).findMaskAlgorithmByColumnIndex(1); assertTrue(actual.isPresent()); assertThat(actual.get().getType(), is("MD5")); }