From a6bc09bc3391ce07547e6caa37b1b9fc95293a85 Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Tue, 12 Nov 2024 01:11:55 +0800 Subject: [PATCH] Refactor ShardingParameterRewritersRegistryTest and EncryptParameterRewritersRegistryTest (#33618) --- .../parameter/EncryptParameterRewritersRegistryTest.java | 9 +-------- .../ShardingParameterRewritersRegistryTest.java | 5 ----- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/parameter/EncryptParameterRewritersRegistryTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/parameter/EncryptParameterRewritersRegistryTest.java index 9854425abd331..3fd62697982d7 100644 --- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/parameter/EncryptParameterRewritersRegistryTest.java +++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/parameter/EncryptParameterRewritersRegistryTest.java @@ -23,7 +23,6 @@ import org.apache.shardingsphere.encrypt.rewrite.parameter.rewriter.EncryptInsertValueParameterRewriter; import org.apache.shardingsphere.encrypt.rewrite.parameter.rewriter.EncryptPredicateParameterRewriter; import org.apache.shardingsphere.encrypt.rule.EncryptRule; -import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext; import org.apache.shardingsphere.infra.database.core.DefaultDatabase; import org.apache.shardingsphere.infra.rewrite.parameter.rewriter.ParameterRewriter; import org.junit.jupiter.api.Test; @@ -35,19 +34,13 @@ import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -import static org.mockito.Mockito.RETURNS_DEEP_STUBS; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; class EncryptParameterRewritersRegistryTest { @Test void assertGetParameterRewriters() { - EncryptRule rule = mock(EncryptRule.class, RETURNS_DEEP_STUBS); - when(rule.findEncryptTable("foo_tbl").isPresent()).thenReturn(true); - SelectStatementContext sqlStatementContext = mock(SelectStatementContext.class, RETURNS_DEEP_STUBS); - when(sqlStatementContext.getTablesContext().getTableNames()).thenReturn(Collections.singleton("foo_tbl")); - List actual = new ArrayList<>(new EncryptParameterRewritersRegistry(rule, DefaultDatabase.LOGIC_NAME, Collections.emptyList()).getParameterRewriters()); + List actual = new ArrayList<>(new EncryptParameterRewritersRegistry(mock(EncryptRule.class), DefaultDatabase.LOGIC_NAME, Collections.emptyList()).getParameterRewriters()); assertThat(actual.size(), is(5)); assertThat(actual.get(0), instanceOf(EncryptAssignmentParameterRewriter.class)); assertThat(actual.get(1), instanceOf(EncryptPredicateParameterRewriter.class)); diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameter/ShardingParameterRewritersRegistryTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameter/ShardingParameterRewritersRegistryTest.java index 2805707be233f..210fb968c1e2c 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameter/ShardingParameterRewritersRegistryTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameter/ShardingParameterRewritersRegistryTest.java @@ -17,7 +17,6 @@ package org.apache.shardingsphere.sharding.rewrite.parameter; -import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext; import org.apache.shardingsphere.infra.rewrite.parameter.rewriter.ParameterRewriter; import org.apache.shardingsphere.infra.rewrite.parameter.rewriter.keygen.GeneratedKeyInsertValueParameterRewriter; import org.apache.shardingsphere.infra.route.context.RouteContext; @@ -30,16 +29,12 @@ import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -import static org.mockito.Mockito.RETURNS_DEEP_STUBS; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; class ShardingParameterRewritersRegistryTest { @Test void assertGetParameterRewriters() { - SelectStatementContext statementContext = mock(SelectStatementContext.class, RETURNS_DEEP_STUBS); - when(statementContext.getPaginationContext().isHasPagination()).thenReturn(true); List actual = new ArrayList<>(new ShardingParameterRewritersRegistry(mock(RouteContext.class)).getParameterRewriters()); assertThat(actual.size(), is(2)); assertThat(actual.get(0), instanceOf(GeneratedKeyInsertValueParameterRewriter.class));