From 8ddc528af6f863d499d176c2d8abf8ba8d357015 Mon Sep 17 00:00:00 2001 From: liulinfei121 <57127515+liulinfei121@users.noreply.github.com> Date: Fri, 16 Sep 2022 10:42:10 +0800 Subject: [PATCH] add SingletonTest test case(#642) (#702) Co-authored-by: liulinfei --- .../hippo4j/common/toolkit/SingletonTest.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/hippo4j-common/src/test/java/cn/hippo4j/common/toolkit/SingletonTest.java b/hippo4j-common/src/test/java/cn/hippo4j/common/toolkit/SingletonTest.java index d546b3cb..1f111e82 100644 --- a/hippo4j-common/src/test/java/cn/hippo4j/common/toolkit/SingletonTest.java +++ b/hippo4j-common/src/test/java/cn/hippo4j/common/toolkit/SingletonTest.java @@ -17,5 +17,30 @@ package cn.hippo4j.common.toolkit; +import cn.hippo4j.common.model.ThreadPoolParameterInfo; +import org.junit.Assert; +import org.junit.Test; + public class SingletonTest { + + @Test + public void assertSingletonGet() { + Assert.assertNull(Singleton.get("userName")); + Singleton.put("userName", "hippo4j"); + Assert.assertEquals("hippo4j", Singleton.get("userName")); + ThreadPoolParameterInfo threadPoolParameterInfo = ThreadPoolParameterInfo.builder().tenantId("prescription") + .itemId("dynamic-threadpool-example").tpId("message-consume").content("描述信息").corePoolSize(1) + .maximumPoolSize(2).queueType(1).capacity(4).keepAliveTime(513).executeTimeOut(null).rejectedType(4) + .isAlarm(1).capacityAlarm(80).livenessAlarm(80).allowCoreThreadTimeOut(1).build(); + Singleton.put(threadPoolParameterInfo); + Assert.assertEquals(threadPoolParameterInfo, Singleton.get(ThreadPoolParameterInfo.class.getName())); + } + + @Test + public void assertSingletonGet2() { + Assert.assertNull(Singleton.get("userName1", () -> null)); + Assert.assertEquals("hippo4j", Singleton.get("userName1", () -> "hippo4j")); + Assert.assertEquals("123456", Singleton.get("pw", () -> "123456") + ""); + Assert.assertNotEquals("135790", Singleton.get("pw", () -> "135790") + ""); + } }