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 de8fab9e2a2 Add test case for SQLDialectExceptionMapperFactory (#20271)
de8fab9e2a2 is described below

commit de8fab9e2a249b9c642be8dd45b4b0cc23498a58
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Aug 18 18:48:16 2022 +0800

    Add test case for SQLDialectExceptionMapperFactory (#20271)
---
 .../mapper/SQLDialectExceptionMapperFactory.java   |  2 +-
 .../SQLDialectExceptionMapperFactoryTest.java}     | 30 ++++++------------
 .../fixture/FixtureSQLDialectExceptionMapper.java  | 36 ++++++++++++++++++++++
 ...sphere.dialect.mapper.SQLDialectExceptionMapper | 18 +++++++++++
 4 files changed, 64 insertions(+), 22 deletions(-)

diff --git 
a/shardingsphere-dialect-exception/shardingsphere-dialect-exception-core/src/main/java/org/apache/shardingsphere/dialect/mapper/SQLDialectExceptionMapperFactory.java
 
b/shardingsphere-dialect-exception/shardingsphere-dialect-exception-core/src/main/java/org/apache/shardingsphere/dialect/mapper/SQLDialectExceptionMapperFactory.java
index 103a6bf1121..5103dacb701 100644
--- 
a/shardingsphere-dialect-exception/shardingsphere-dialect-exception-core/src/main/java/org/apache/shardingsphere/dialect/mapper/SQLDialectExceptionMapperFactory.java
+++ 
b/shardingsphere-dialect-exception/shardingsphere-dialect-exception-core/src/main/java/org/apache/shardingsphere/dialect/mapper/SQLDialectExceptionMapperFactory.java
@@ -36,7 +36,7 @@ public final class SQLDialectExceptionMapperFactory {
      * Get instance of SQL dialect exception mapper.
      * 
      * @param databaseType database type
-     * @return SQL dialect exception mapper
+     * @return got instance
      */
     public static SQLDialectExceptionMapper getInstance(final String 
databaseType) {
         return 
TypedSPIRegistry.getRegisteredService(SQLDialectExceptionMapper.class, 
databaseType);
diff --git 
a/shardingsphere-dialect-exception/shardingsphere-dialect-exception-core/src/main/java/org/apache/shardingsphere/dialect/mapper/SQLDialectExceptionMapperFactory.java
 
b/shardingsphere-dialect-exception/shardingsphere-dialect-exception-core/src/test/java/org/apache/shardingsphere/dialect/mapper/SQLDialectExceptionMapperFactoryTest.java
similarity index 51%
copy from 
shardingsphere-dialect-exception/shardingsphere-dialect-exception-core/src/main/java/org/apache/shardingsphere/dialect/mapper/SQLDialectExceptionMapperFactory.java
copy to 
shardingsphere-dialect-exception/shardingsphere-dialect-exception-core/src/test/java/org/apache/shardingsphere/dialect/mapper/SQLDialectExceptionMapperFactoryTest.java
index 103a6bf1121..7af91f27f62 100644
--- 
a/shardingsphere-dialect-exception/shardingsphere-dialect-exception-core/src/main/java/org/apache/shardingsphere/dialect/mapper/SQLDialectExceptionMapperFactory.java
+++ 
b/shardingsphere-dialect-exception/shardingsphere-dialect-exception-core/src/test/java/org/apache/shardingsphere/dialect/mapper/SQLDialectExceptionMapperFactoryTest.java
@@ -17,28 +17,16 @@
 
 package org.apache.shardingsphere.dialect.mapper;
 
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry;
+import 
org.apache.shardingsphere.dialect.mapper.fixture.FixtureSQLDialectExceptionMapper;
+import org.junit.Test;
 
-/**
- * SQL dialect exception mapper factory.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class SQLDialectExceptionMapperFactory {
-    
-    static {
-        ShardingSphereServiceLoader.register(SQLDialectExceptionMapper.class);
-    }
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.assertThat;
+
+public final class SQLDialectExceptionMapperFactoryTest {
     
-    /**
-     * Get instance of SQL dialect exception mapper.
-     * 
-     * @param databaseType database type
-     * @return SQL dialect exception mapper
-     */
-    public static SQLDialectExceptionMapper getInstance(final String 
databaseType) {
-        return 
TypedSPIRegistry.getRegisteredService(SQLDialectExceptionMapper.class, 
databaseType);
+    @Test
+    public void assertGetInstance() {
+        assertThat(SQLDialectExceptionMapperFactory.getInstance("FIXTURE"), 
instanceOf(FixtureSQLDialectExceptionMapper.class));
     }
 }
diff --git 
a/shardingsphere-dialect-exception/shardingsphere-dialect-exception-core/src/test/java/org/apache/shardingsphere/dialect/mapper/fixture/FixtureSQLDialectExceptionMapper.java
 
b/shardingsphere-dialect-exception/shardingsphere-dialect-exception-core/src/test/java/org/apache/shardingsphere/dialect/mapper/fixture/FixtureSQLDialectExceptionMapper.java
new file mode 100644
index 00000000000..8f4adb3eb90
--- /dev/null
+++ 
b/shardingsphere-dialect-exception/shardingsphere-dialect-exception-core/src/test/java/org/apache/shardingsphere/dialect/mapper/fixture/FixtureSQLDialectExceptionMapper.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.dialect.mapper.fixture;
+
+import org.apache.shardingsphere.dialect.exception.SQLDialectException;
+import org.apache.shardingsphere.dialect.mapper.SQLDialectExceptionMapper;
+
+import java.sql.SQLException;
+
+public final class FixtureSQLDialectExceptionMapper implements 
SQLDialectExceptionMapper {
+    
+    @Override
+    public SQLException convert(final SQLDialectException sqlDialectException) 
{
+        return new SQLException();
+    }
+    
+    @Override
+    public String getType() {
+        return "FIXTURE";
+    }
+}
diff --git 
a/shardingsphere-dialect-exception/shardingsphere-dialect-exception-core/src/test/resources/META-INF/services/org.apache.shardingsphere.dialect.mapper.SQLDialectExceptionMapper
 
b/shardingsphere-dialect-exception/shardingsphere-dialect-exception-core/src/test/resources/META-INF/services/org.apache.shardingsphere.dialect.mapper.SQLDialectExceptionMapper
new file mode 100644
index 00000000000..c0efc2fbbd2
--- /dev/null
+++ 
b/shardingsphere-dialect-exception/shardingsphere-dialect-exception-core/src/test/resources/META-INF/services/org.apache.shardingsphere.dialect.mapper.SQLDialectExceptionMapper
@@ -0,0 +1,18 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+org.apache.shardingsphere.dialect.mapper.fixture.FixtureSQLDialectExceptionMapper

Reply via email to