This is an automated email from the ASF dual-hosted git repository.

duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new f3ddacc  Refactor DefaultDataSourceCreatorTest (#14055)
f3ddacc is described below

commit f3ddaccaf23041d46dc35305b7c5cb1bbb539789
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Dec 11 21:22:34 2021 +0800

    Refactor DefaultDataSourceCreatorTest (#14055)
---
 .../destroyer/impl/HikariDataSourceDestroyer.java  |  1 +
 .../creator/DefaultDataSourceCreatorTest.java      | 51 ++++++++++------------
 2 files changed, 23 insertions(+), 29 deletions(-)

diff --git 
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/destroyer/impl/HikariDataSourceDestroyer.java
 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/destroyer/impl/HikariDataSourceDestroyer.java
index f82e87c..5ad69de 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/destroyer/impl/HikariDataSourceDestroyer.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/destroyer/impl/HikariDataSourceDestroyer.java
@@ -19,6 +19,7 @@ package 
org.apache.shardingsphere.infra.config.datasource.destroyer.impl;
 
 import com.zaxxer.hikari.HikariDataSource;
 import 
org.apache.shardingsphere.infra.config.datasource.destroyer.DataSourceDestroyer;
+
 import javax.sql.DataSource;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
diff --git 
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/creator/DefaultDataSourceCreatorTest.java
 
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/creator/DefaultDataSourceCreatorTest.java
index 116abd6..c56d86a 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/creator/DefaultDataSourceCreatorTest.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/datasource/creator/DefaultDataSourceCreatorTest.java
@@ -24,47 +24,40 @@ import org.junit.Test;
 
 import javax.sql.DataSource;
 
-import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
 
 public final class DefaultDataSourceCreatorTest {
     
     @Test
-    public void assertDataSourceConfigurationEquals() {
-        DefaultDataSourceCreator defaultDataSourceCreator = new 
DefaultDataSourceCreator();
-        DataSourceConfiguration generateDataSourceConfiguration = 
defaultDataSourceCreator.createDataSourceConfiguration(createDataSource());
-        DataSourceConfiguration targetDataSourceConfiguration = 
createDataSourceConfiguration();
-        assertThat(generateDataSourceConfiguration, 
is(targetDataSourceConfiguration));
+    public void assertCreateDataSourceConfiguration() {
+        assertThat(new 
DefaultDataSourceCreator().createDataSourceConfiguration(createDataSource()), 
is(createDataSourceConfiguration()));
     }
     
-    @Test
-    public void assertCreateDataSource() {
-        DefaultDataSourceCreator defaultDataSourceCreator = new 
DefaultDataSourceCreator();
-        DataSource generateDataSource = 
defaultDataSourceCreator.createDataSource(createDataSourceConfiguration());
-        assertThat(generateDataSource, instanceOf(HikariDataSource.class));
-        HikariDataSource targetDataSource = (HikariDataSource) 
generateDataSource;
-        assertThat(targetDataSource.getUsername(), is("root"));
-        assertThat(targetDataSource.getPassword(), is("root"));
-        assertThat(targetDataSource.getDriverClassName(), is("org.h2.Driver"));
-        assertThat(targetDataSource.getJdbcUrl(), 
is("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL"));
+    private DataSource createDataSource() {
+        HikariDataSource result = new HikariDataSource();
+        result.setDriverClassName("org.h2.Driver");
+        
result.setJdbcUrl("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL");
+        result.setUsername("root");
+        result.setPassword("root");
+        return result;
     }
     
-    private DataSource createDataSource() {
-        HikariDataSource dataSource = new HikariDataSource();
-        dataSource.setDriverClassName("org.h2.Driver");
-        
dataSource.setJdbcUrl("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL");
-        dataSource.setUsername("root");
-        dataSource.setPassword("root");
-        return dataSource;
+    @Test
+    public void assertCreateDataSource() {
+        HikariDataSource actual = (HikariDataSource) new 
DefaultDataSourceCreator().createDataSource(createDataSourceConfiguration());
+        assertThat(actual.getUsername(), is("root"));
+        assertThat(actual.getPassword(), is("root"));
+        assertThat(actual.getDriverClassName(), is("org.h2.Driver"));
+        assertThat(actual.getJdbcUrl(), 
is("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL"));
     }
     
     private DataSourceConfiguration createDataSourceConfiguration() {
-        DataSourceConfiguration dataSourceConfiguration = new 
DataSourceConfiguration(HikariDataSource.class.getName());
-        dataSourceConfiguration.getProps().put("jdbcUrl", 
"jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL");
-        dataSourceConfiguration.getProps().put("driverClassName", 
"org.h2.Driver");
-        dataSourceConfiguration.getProps().put("username", "root");
-        dataSourceConfiguration.getProps().put("password", "root");
-        return dataSourceConfiguration;
+        DataSourceConfiguration result = new 
DataSourceConfiguration(HikariDataSource.class.getName());
+        result.getProps().put("jdbcUrl", 
"jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL");
+        result.getProps().put("driverClassName", "org.h2.Driver");
+        result.getProps().put("username", "root");
+        result.getProps().put("password", "root");
+        return result;
     }
 }

Reply via email to