diff --git a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationCheckerTest.java b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationCheckerTest.java index b7bf0b0fe1c72..49333d4424b01 100644 --- a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationCheckerTest.java +++ b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationCheckerTest.java @@ -27,6 +27,7 @@ import org.apache.shardingsphere.readwritesplitting.exception.checker.DuplicateDataSourceException; import org.apache.shardingsphere.readwritesplitting.exception.checker.InvalidWeightLoadBalancerConfigurationException; import org.apache.shardingsphere.readwritesplitting.exception.checker.MissingRequiredWriteDataSourceNameException; +import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource; import org.apache.shardingsphere.test.util.PropertiesBuilder; import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.junit.jupiter.api.Test; @@ -127,10 +128,10 @@ private ReadwriteSplittingDataSourceRuleConfiguration createDataSourceRuleConfig private Map mockDataSources() { Map result = new LinkedHashMap<>(2, 1F); - result.put("read_ds_0", mock(DataSource.class)); - result.put("read_ds_1", mock(DataSource.class)); - result.put("write_ds_0", mock(DataSource.class)); - result.put("write_ds_1", mock(DataSource.class)); + result.put("read_ds_0", new MockedDataSource()); + result.put("read_ds_1", new MockedDataSource()); + result.put("write_ds_0", new MockedDataSource()); + result.put("write_ds_1", new MockedDataSource()); return result; } } diff --git a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationCheckerTest.java b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationCheckerTest.java index ae8b9b1933bdf..ff4985d973984 100644 --- a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationCheckerTest.java +++ b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationCheckerTest.java @@ -21,19 +21,17 @@ import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration; import org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration; import org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration; +import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource; import org.apache.shardingsphere.test.util.PropertiesBuilder; import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.junit.jupiter.api.Test; import javax.sql.DataSource; -import java.util.Collection; import java.util.Collections; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.Map; -import static org.mockito.Mockito.mock; - class ShadowRuleConfigurationCheckerTest { @Test @@ -43,22 +41,16 @@ void assertCheck() { private Map createDataSourceMap() { Map result = new LinkedHashMap<>(2, 1F); - result.put("ds", mock(DataSource.class)); - result.put("ds_shadow", mock(DataSource.class)); + result.put("ds", new MockedDataSource()); + result.put("ds_shadow", new MockedDataSource()); return result; } private ShadowRuleConfiguration createShadowRuleConfiguration() { ShadowRuleConfiguration result = new ShadowRuleConfiguration(); - result.setShadowAlgorithms(createShadowAlgorithmConfigurations()); - result.setDataSources(createDataSources()); - result.setTables(createTables()); - return result; - } - - private Map createShadowAlgorithmConfigurations() { - Map result = new LinkedHashMap<>(); - result.put("user-id-insert-match-algorithm", createAlgorithmConfiguration()); + result.setShadowAlgorithms(Collections.singletonMap("user-id-insert-match-algorithm", createAlgorithmConfiguration())); + result.setDataSources(Collections.singleton(new ShadowDataSourceConfiguration("shadow-data-source", "ds", "ds_shadow"))); + result.setTables(Collections.singletonMap("t_order", new ShadowTableConfiguration(new LinkedList<>(), new LinkedList<>(Collections.singleton("user-id-insert-match-algorithm"))))); return result; } @@ -66,19 +58,4 @@ private AlgorithmConfiguration createAlgorithmConfiguration() { return new AlgorithmConfiguration("user-id-insert-match-algorithm", PropertiesBuilder.build(new Property("column", "shadow"), new Property("operation", "insert"), new Property("regex", "[1]"))); } - - private Map createTables() { - Map result = new LinkedHashMap<>(); - Collection dataSourceNames = new LinkedList<>(); - Collection shadowAlgorithmNames = new LinkedList<>(); - shadowAlgorithmNames.add("user-id-insert-match-algorithm"); - result.put("t_order", new ShadowTableConfiguration(dataSourceNames, shadowAlgorithmNames)); - return result; - } - - private Collection createDataSources() { - Collection result = new LinkedList<>(); - result.add(new ShadowDataSourceConfiguration("shadow-data-source", "ds", "ds_shadow")); - return result; - } } diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/GenericSchemaBuilderTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/GenericSchemaBuilderTest.java index a2ba70da0bfd6..992856e755ca7 100644 --- a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/GenericSchemaBuilderTest.java +++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/GenericSchemaBuilderTest.java @@ -27,13 +27,13 @@ import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; +import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource; import org.apache.shardingsphere.test.mock.AutoMockExtension; import org.apache.shardingsphere.test.mock.StaticMockSettings; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import javax.sql.DataSource; import java.sql.SQLException; import java.util.Arrays; import java.util.Collection; @@ -47,7 +47,6 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @ExtendWith(AutoMockExtension.class) @@ -60,7 +59,7 @@ class GenericSchemaBuilderTest { void setUp() { DatabaseType databaseType = TypedSPILoader.getService(DatabaseType.class, "FIXTURE"); material = new GenericSchemaBuilderMaterial(databaseType, Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseType), - Collections.singletonMap(DefaultDatabase.LOGIC_NAME, mock(DataSource.class)), + Collections.singletonMap(DefaultDatabase.LOGIC_NAME, new MockedDataSource()), Collections.singleton(new TableContainedFixtureRule()), new ConfigurationProperties(new Properties()), DefaultDatabase.LOGIC_NAME); } diff --git a/infra/data-source-pool/core/src/test/java/org/apache/shardingsphere/infra/datasource/pool/destroyer/DataSourcePoolDestroyerTest.java b/infra/data-source-pool/core/src/test/java/org/apache/shardingsphere/infra/datasource/pool/destroyer/DataSourcePoolDestroyerTest.java index a2e324a9d1ed2..161c4c0a89aec 100644 --- a/infra/data-source-pool/core/src/test/java/org/apache/shardingsphere/infra/datasource/pool/destroyer/DataSourcePoolDestroyerTest.java +++ b/infra/data-source-pool/core/src/test/java/org/apache/shardingsphere/infra/datasource/pool/destroyer/DataSourcePoolDestroyerTest.java @@ -21,20 +21,18 @@ import org.awaitility.Awaitility; import org.junit.jupiter.api.Test; -import javax.sql.DataSource; import java.sql.Connection; import java.sql.SQLException; import java.util.concurrent.TimeUnit; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.Mockito.mock; class DataSourcePoolDestroyerTest { @Test void assertAsyncDestroyWithoutAutoCloseableDataSource() { - assertDoesNotThrow(() -> new DataSourcePoolDestroyer(mock(DataSource.class)).asyncDestroy()); + assertDoesNotThrow(() -> new DataSourcePoolDestroyer(new MockedDataSource()).asyncDestroy()); } @Test