You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by to...@apache.org on 2022/05/08 17:04:08 UTC

[shardingsphere] branch master updated: Refactor TypedSPIRegistryTest (#17457)

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

totalo 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 ad91b8b4ecd Refactor TypedSPIRegistryTest (#17457)
ad91b8b4ecd is described below

commit ad91b8b4ecde8867ce4bb093069aeb24635b8ee0
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Mon May 9 01:04:03 2022 +0800

    Refactor TypedSPIRegistryTest (#17457)
---
 .../spi/type/typed/TypedSPIRegistry.java           |  4 +-
 .../spi/type/typed/TypedSPIRegistryTest.java       | 44 ++++++++++++----------
 2 files changed, 26 insertions(+), 22 deletions(-)

diff --git a/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/type/typed/TypedSPIRegistry.java b/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/type/typed/TypedSPIRegistry.java
index 761d7c498d7..2bf68580cde 100644
--- a/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/type/typed/TypedSPIRegistry.java
+++ b/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/type/typed/TypedSPIRegistry.java
@@ -71,8 +71,8 @@ public final class TypedSPIRegistry {
         return Optional.empty();
     }
     
-    private static boolean matchesType(final String type, final TypedSPI typedSPI) {
-        return typedSPI.getType().equalsIgnoreCase(type) || typedSPI.getTypeAliases().contains(type);
+    private static boolean matchesType(final String type, final TypedSPI instance) {
+        return instance.getType().equalsIgnoreCase(type) || instance.getTypeAliases().contains(type);
     }
     
     private static Properties convertToStringTypedProperties(final Properties props) {
diff --git a/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/typed/TypedSPIRegistryTest.java b/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/typed/TypedSPIRegistryTest.java
index 316d972f33c..70ad3a9d1bb 100644
--- a/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/typed/TypedSPIRegistryTest.java
+++ b/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/typed/TypedSPIRegistryTest.java
@@ -20,60 +20,64 @@ package org.apache.shardingsphere.spi.type.typed;
 import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
 import org.apache.shardingsphere.spi.exception.ServiceProviderNotFoundException;
 import org.apache.shardingsphere.spi.type.typed.fixture.TypedSPIFixture;
-import org.junit.Before;
+import org.apache.shardingsphere.spi.type.typed.fixture.TypedSPIFixtureImpl;
 import org.junit.Test;
 
 import java.util.Properties;
 
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 
 public final class TypedSPIRegistryTest {
     
-    @Before
-    public void init() {
+    static {
         ShardingSphereServiceLoader.register(TypedSPIFixture.class);
     }
     
     @Test
-    public void assertFindRegisteredService() {
+    public void assertFindRegisteredServiceWithoutProperties() {
         assertTrue(TypedSPIRegistry.findRegisteredService(TypedSPIFixture.class, "TYPED.FIXTURE").isPresent());
     }
     
     @Test
-    public void assertGetStatelessRegisteredService() {
-        assertNotNull(TypedSPIRegistry.getRegisteredService(TypedSPIFixture.class, "TYPED.FIXTURE"));
+    public void assertFindRegisteredServiceWithProperties() {
+        assertTrue(TypedSPIRegistry.findRegisteredService(TypedSPIFixture.class, "TYPED.FIXTURE", new Properties()).isPresent());
     }
     
     @Test
-    public void assertFindRegisteredServiceWithProperties() {
-        assertTrue(TypedSPIRegistry.findRegisteredService(TypedSPIFixture.class, "TYPED.FIXTURE", createProperties()).isPresent());
+    public void assertGetRegisteredServiceWithoutProperties() {
+        assertThat(TypedSPIRegistry.getRegisteredService(TypedSPIFixture.class, "TYPED.FIXTURE"), instanceOf(TypedSPIFixtureImpl.class));
     }
     
     @Test
-    public void assertGetStatelessRegisteredServiceWithProperties() {
-        assertNotNull(TypedSPIRegistry.getRegisteredService(TypedSPIFixture.class, "TYPED.FIXTURE", createProperties()));
+    public void assertGetRegisteredServiceWithProperties() {
+        Properties props = new Properties();
+        props.put("key", 1);
+        TypedSPIFixture actual = TypedSPIRegistry.getRegisteredService(TypedSPIFixture.class, "TYPED.FIXTURE", props);
+        assertThat(actual.getProps().getProperty("key"), is("1"));
     }
     
-    private Properties createProperties() {
-        Properties result = new Properties();
-        result.put("key1", 1);
-        result.put("key2", 2L);
-        return result;
+    @Test
+    public void assertGetRegisteredServiceWithNullProperties() {
+        TypedSPIFixture actual = TypedSPIRegistry.getRegisteredService(TypedSPIFixture.class, "TYPED.FIXTURE", null);
+        assertTrue(actual.getProps().isEmpty());
     }
     
     @Test
-    public void assertGetStatefulRegisteredServiceWithAlias() {
+    public void assertGetRegisteredServiceWithAlias() {
         assertNotNull(TypedSPIRegistry.getRegisteredService(TypedSPIFixture.class, "TYPED.ALIAS", new Properties()));
     }
     
     @Test(expected = ServiceProviderNotFoundException.class)
-    public void assertGetStatefulRegisteredServiceWhenTypeIsNotExist() {
-        TypedSPIRegistry.getRegisteredService(TypedSPIFixture.class, "NOT_EXISTED", new Properties());
+    public void assertGetRegisteredServiceWithoutPropertiesWhenTypeIsNotExist() {
+        TypedSPIRegistry.getRegisteredService(TypedSPIFixture.class, "NOT_EXISTED");
     }
     
     @Test(expected = ServiceProviderNotFoundException.class)
-    public void assertGetStatelessRegisteredServiceWhenTypeIsNotExist() {
-        TypedSPIRegistry.getRegisteredService(TypedSPIFixture.class, "NOT_EXISTED");
+    public void assertGetRegisteredServiceWithPropertiesWhenTypeIsNotExist() {
+        TypedSPIRegistry.getRegisteredService(TypedSPIFixture.class, "NOT_EXISTED", new Properties());
     }
 }