From 1f22f560a44995340daa3039b29eee72a3ea504f Mon Sep 17 00:00:00 2001 From: "ken.lj" Date: Fri, 9 Mar 2018 16:06:13 +0800 Subject: [PATCH] Add unit test for ExtensionLoader --- .../common/extensionloader/ExtensionLoaderTest.java | 12 ++++++++++++ .../common/extensionloader/ext9_empty/Ext9Empty.java | 8 ++++++++ .../ext9_empty/impl/Ext9EmptyImpl.java | 10 ++++++++++ ...dubbo.common.extensionloader.ext9_empty.Ext9Empty | 0 4 files changed, 30 insertions(+) create mode 100644 dubbo-common/src/test/java/com/alibaba/dubbo/common/extensionloader/ext9_empty/Ext9Empty.java create mode 100644 dubbo-common/src/test/java/com/alibaba/dubbo/common/extensionloader/ext9_empty/impl/Ext9EmptyImpl.java create mode 100644 dubbo-common/src/test/resources/META-INF/dubbo/internal/com.alibaba.dubbo.common.extensionloader.ext9_empty.Ext9Empty diff --git a/dubbo-common/src/test/java/com/alibaba/dubbo/common/extensionloader/ExtensionLoaderTest.java b/dubbo-common/src/test/java/com/alibaba/dubbo/common/extensionloader/ExtensionLoaderTest.java index 1a56fad77b8..3f7900c38b6 100644 --- a/dubbo-common/src/test/java/com/alibaba/dubbo/common/extensionloader/ExtensionLoaderTest.java +++ b/dubbo-common/src/test/java/com/alibaba/dubbo/common/extensionloader/ExtensionLoaderTest.java @@ -44,6 +44,8 @@ import com.alibaba.dubbo.common.extensionloader.ext8_add.impl.AddExt2_ManualAdaptive; import com.alibaba.dubbo.common.extensionloader.ext8_add.impl.AddExt3_ManualAdaptive; import com.alibaba.dubbo.common.extensionloader.ext8_add.impl.AddExt4_ManualAdaptive; +import com.alibaba.dubbo.common.extensionloader.ext9_empty.Ext9Empty; +import com.alibaba.dubbo.common.extensionloader.ext9_empty.impl.Ext9EmptyImpl; import junit.framework.Assert; import org.junit.Test; @@ -240,6 +242,16 @@ public void test_AddExtension() throws Exception { assertEquals("Manual1", ExtensionLoader.getExtensionLoader(AddExt1.class).getExtensionName(AddExt1_ManualAdd1.class)); } + @Test + public void test_AddExtension_NoExtend() throws Exception { +// ExtensionLoader.getExtensionLoader(Ext9Empty.class).getSupportedExtensions(); + ExtensionLoader.getExtensionLoader(Ext9Empty.class).addExtension("ext9", Ext9EmptyImpl.class); + Ext9Empty ext = ExtensionLoader.getExtensionLoader(Ext9Empty.class).getExtension("ext9"); + + assertThat(ext, instanceOf(Ext9Empty.class)); + assertEquals("ext9", ExtensionLoader.getExtensionLoader(Ext9Empty.class).getExtensionName(Ext9EmptyImpl.class)); + } + @Test public void test_AddExtension_ExceptionWhenExistedExtension() throws Exception { SimpleExt ext = ExtensionLoader.getExtensionLoader(SimpleExt.class).getExtension("impl1"); diff --git a/dubbo-common/src/test/java/com/alibaba/dubbo/common/extensionloader/ext9_empty/Ext9Empty.java b/dubbo-common/src/test/java/com/alibaba/dubbo/common/extensionloader/ext9_empty/Ext9Empty.java new file mode 100644 index 00000000000..b13bea62449 --- /dev/null +++ b/dubbo-common/src/test/java/com/alibaba/dubbo/common/extensionloader/ext9_empty/Ext9Empty.java @@ -0,0 +1,8 @@ +package com.alibaba.dubbo.common.extensionloader.ext9_empty; + +import com.alibaba.dubbo.common.extension.SPI; + +@SPI +public interface Ext9Empty { + void empty(); +} diff --git a/dubbo-common/src/test/java/com/alibaba/dubbo/common/extensionloader/ext9_empty/impl/Ext9EmptyImpl.java b/dubbo-common/src/test/java/com/alibaba/dubbo/common/extensionloader/ext9_empty/impl/Ext9EmptyImpl.java new file mode 100644 index 00000000000..68430c595f9 --- /dev/null +++ b/dubbo-common/src/test/java/com/alibaba/dubbo/common/extensionloader/ext9_empty/impl/Ext9EmptyImpl.java @@ -0,0 +1,10 @@ +package com.alibaba.dubbo.common.extensionloader.ext9_empty.impl; + +import com.alibaba.dubbo.common.extensionloader.ext9_empty.Ext9Empty; + +public class Ext9EmptyImpl implements Ext9Empty { + @Override + public void empty() { + + } +} diff --git a/dubbo-common/src/test/resources/META-INF/dubbo/internal/com.alibaba.dubbo.common.extensionloader.ext9_empty.Ext9Empty b/dubbo-common/src/test/resources/META-INF/dubbo/internal/com.alibaba.dubbo.common.extensionloader.ext9_empty.Ext9Empty new file mode 100644 index 00000000000..e69de29bb2d