From 86116715f4c6f6afcc49ab726831f3703253902a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=B6=E9=97=B4=E9=82=AE=E9=80=92=E5=91=98?= <78356082+barret-yzh@users.noreply.github.com> Date: Fri, 26 May 2023 10:09:25 +0800 Subject: [PATCH] Update ThreadFactoryBuilderTest Methods are covered by multiple unit test cases . Console printing in English --- .../common/executor/ThreadFactoryBuilderTest | 40 +++++++++++++++---- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/infra/common/src/test/java/cn/hippo4j/common/executor/ThreadFactoryBuilderTest b/infra/common/src/test/java/cn/hippo4j/common/executor/ThreadFactoryBuilderTest index ca83ff2f..35dba750 100644 --- a/infra/common/src/test/java/cn/hippo4j/common/executor/ThreadFactoryBuilderTest +++ b/infra/common/src/test/java/cn/hippo4j/common/executor/ThreadFactoryBuilderTest @@ -3,27 +3,52 @@ package cn.hippo4j.common.design.builder; import cn.hippo4j.common.design.builder.ThreadFactoryBuilder; import org.junit.Assert; import org.junit.Test; + import java.util.concurrent.ThreadFactory; import java.lang.Thread.UncaughtExceptionHandler; public class ThreadFactoryBuilderTest { - @Test - public void testBuild() { - ThreadFactoryBuilder builder = ThreadFactoryBuilder.builder(); - TestUncaughtExceptionHandler uncaughtExceptionHandler = new TestUncaughtExceptionHandler(); + ThreadFactoryBuilder builder; + TestUncaughtExceptionHandler uncaughtExceptionHandler; + Thread thread; + + public void buildThread() { + builder = ThreadFactoryBuilder.builder(); + uncaughtExceptionHandler = new TestUncaughtExceptionHandler(); builder.uncaughtExceptionHandler(uncaughtExceptionHandler); builder.prefix("my-thread-factory"); builder.daemon(true); builder.priority(Thread.MAX_PRIORITY); ThreadFactory threadFactory = builder.build(); - Thread thread = threadFactory.newThread(() -> { - System.out.println("创建新线程"); + thread = threadFactory.newThread(() -> { + System.out.println("Create a new thread."); }); thread.start(); + } + + @Test + public void testName() { + buildThread(); Assert.assertEquals("my-thread-factory_0", thread.getName()); + } + + @Test + public void testIsDaemon() { + buildThread(); Assert.assertTrue(thread.isDaemon()); - Assert.assertEquals(uncaughtExceptionHandler,thread.getUncaughtExceptionHandler()); + } + + @Test + public void testExceptionHandler() { + buildThread(); + Assert.assertEquals(uncaughtExceptionHandler, thread.getUncaughtExceptionHandler()); + + } + + @Test + public void testPriority() { + buildThread(); Assert.assertEquals(Thread.MAX_PRIORITY, thread.getPriority()); } @@ -43,3 +68,4 @@ class TestUncaughtExceptionHandler implements UncaughtExceptionHandler { return exceptionCaught; } } +