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 4dda1e0 Revise #12914 (#12918)
4dda1e0 is described below
commit 4dda1e0800c15a0a891e2b85c6106a660a6030b7
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Oct 7 18:30:33 2021 +0800
Revise #12914 (#12918)
* Remove useless test case
* Refactor AbstractDataSourceAdapterTest
---
.../adapter/AbstractDataSourceAdapterTest.java | 34 +++++++++-------------
1 file changed, 14 insertions(+), 20 deletions(-)
diff --git
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/AbstractDataSourceAdapterTest.java
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/AbstractDataSourceAdapterTest.java
index 103a7be..1f6ef08 100644
---
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/AbstractDataSourceAdapterTest.java
+++
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/AbstractDataSourceAdapterTest.java
@@ -16,7 +16,7 @@
*/
package org.apache.shardingsphere.driver.jdbc.adapter;
-import
org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection;
+
import
org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
import org.apache.shardingsphere.infra.database.DefaultSchema;
@@ -24,16 +24,17 @@ import
org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import
org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
import org.junit.Before;
import org.junit.Test;
+
import javax.sql.DataSource;
import java.io.PrintWriter;
-import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
+import java.util.Collection;
import java.util.Collections;
-import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.logging.Logger;
+
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertNull;
@@ -43,44 +44,37 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public final class AbstractDataSourceAdapterTest {
-
+
private ShardingSphereDataSource shardingSphereDataSource;
-
+
@Before
public void setUp() throws SQLException {
shardingSphereDataSource = new
ShardingSphereDataSource(DefaultSchema.LOGIC_NAME, null, getDataSource(),
getRuleConfigurations(), new Properties());
}
-
+
private Map<String, DataSource> getDataSource() throws SQLException {
- DataSource dataSource = mock(DataSource.class);
- Connection connection = mock(Connection.class, RETURNS_DEEP_STUBS);
- when(dataSource.getConnection()).thenReturn(connection);
- when(connection.getMetaData()).thenReturn(mock(DatabaseMetaData.class,
RETURNS_DEEP_STUBS));
+ DataSource dataSource = mock(DataSource.class, RETURNS_DEEP_STUBS);
+
when(dataSource.getConnection().getMetaData()).thenReturn(mock(DatabaseMetaData.class,
RETURNS_DEEP_STUBS));
when(dataSource.getConnection().getMetaData().getURL()).thenReturn("jdbc:mysql://localhost:3306/test");
return Collections.singletonMap("ds", dataSource);
}
-
- private List<RuleConfiguration> getRuleConfigurations() {
+
+ private Collection<RuleConfiguration> getRuleConfigurations() {
ShardingRuleConfiguration shardingRuleConfig = new
ShardingRuleConfiguration();
ShardingTableRuleConfiguration shardingTableRuleConfig = new
ShardingTableRuleConfiguration("table", "ds" + "." + "table");
shardingRuleConfig.setTables(Collections.singletonList(shardingTableRuleConfig));
- return Collections.singletonList(shardingRuleConfig);
+ return Collections.singleton(shardingRuleConfig);
}
-
+
@Test
public void assertSetLogWriter() {
assertThat(shardingSphereDataSource.getLogWriter(),
instanceOf(PrintWriter.class));
shardingSphereDataSource.setLogWriter(null);
assertNull(shardingSphereDataSource.getLogWriter());
}
-
+
@Test
public void assertGetParentLogger() {
assertThat(shardingSphereDataSource.getParentLogger().getName(),
is(Logger.GLOBAL_LOGGER_NAME));
}
-
- @Test
- public void assertGetConnectionWithUsername() {
- assertThat(shardingSphereDataSource.getConnection("username",
"password"), instanceOf(ShardingSphereConnection.class));
- }
}