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

zhangliang 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 dbcda94  test cases for issues#6753 (#6739)
dbcda94 is described below

commit dbcda9462111a638ba0f5e476af72d50a9730409
Author: harvies <[email protected]>
AuthorDate: Sun Aug 9 23:36:04 2020 +0800

    test cases for issues#6753 (#6739)
    
    * test cases for issues#6753
    
    * code format
---
 .../spi/singleton/SingletonServiceLoaderTest.java  | 24 +++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git 
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/singleton/SingletonServiceLoaderTest.java
 
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/singleton/SingletonServiceLoaderTest.java
index 7b5a786..b57ec04 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/singleton/SingletonServiceLoaderTest.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/singleton/SingletonServiceLoaderTest.java
@@ -18,6 +18,7 @@
 package org.apache.shardingsphere.infra.spi.singleton;
 
 import org.apache.shardingsphere.infra.spi.fixture.TypedSPIFixture;
+import org.apache.shardingsphere.infra.spi.type.TypedSPI;
 import org.junit.Test;
 
 import java.util.Optional;
@@ -26,6 +27,7 @@ import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
 
 public final class SingletonServiceLoaderTest {
     
@@ -37,10 +39,30 @@ public final class SingletonServiceLoaderTest {
         assertNotNull(actualSecondServiceLoader);
         assertThat(actualFirstServiceLoader, is(actualSecondServiceLoader));
     }
-    
+
+    @Test(expected = NullPointerException.class)
+    public void assertGetSingletonServiceLoaderWhenServiceIsNull() {
+        SingletonServiceLoader.getServiceLoader(null);
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void assertGetSingletonServiceLoaderWhenServiceIsNotAnInterface() {
+        SingletonServiceLoader.getServiceLoader(String.class);
+    }
+
     @Test
     public void assertNewServiceInstanceWhenIsNotExist() {
         Optional<TypedSPIFixture> actual = 
SingletonServiceLoader.getServiceLoader(TypedSPIFixture.class).newServiceInstances();
         assertTrue(actual.isPresent());
     }
+
+    @Test
+    public void assertNewServiceInstanceWhenServiceDoesNotFind() {
+        Optional<NoImplTypedSPI> actual = 
SingletonServiceLoader.getServiceLoader(NoImplTypedSPI.class).newServiceInstances();
+        assertFalse(actual.isPresent());
+    }
+
+    interface NoImplTypedSPI extends TypedSPI {
+
+    }
 }

Reply via email to