From 1f304334cd56c552dc8fd0f6298e34ef038cc7fc Mon Sep 17 00:00:00 2001 From: mabofu Date: Wed, 27 Aug 2025 19:01:39 +0800 Subject: [PATCH] Fixed Task coverage 1.fixed code coverage: Task Signed-off-by: Ma, Wenhao --- .../common/taskmanager/model/TaskTest.java | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 dsms-engine-application/src/test/java/com/dsms/common/taskmanager/model/TaskTest.java diff --git a/dsms-engine-application/src/test/java/com/dsms/common/taskmanager/model/TaskTest.java b/dsms-engine-application/src/test/java/com/dsms/common/taskmanager/model/TaskTest.java new file mode 100644 index 0000000..7a0b857 --- /dev/null +++ b/dsms-engine-application/src/test/java/com/dsms/common/taskmanager/model/TaskTest.java @@ -0,0 +1,86 @@ +package com.dsms.common.taskmanager.model; + +import com.dsms.common.constant.TaskExclusiveEnum; +import org.junit.jupiter.api.Test; + +import java.time.LocalDateTime; +import java.util.Objects; + +import static org.junit.jupiter.api.Assertions.*; +import com.dsms.common.taskmanager.model.Task; + + +public class TaskTest { + private static final String TASK_NAME = "test-task"; + private static final String TASK_TYPE = "test-type"; + private static final Integer TASK_STATUS = 1; + private static final String TASK_MESSAGE = "Task is in queue"; + private static final String TASK_PARAM = "{\"key\": \"value\"}"; + private static final int NON_EXCLUSIVE = 0; + private static final int EXCLUSIVE = 1; + + @Test + public void testDefaultConstructor() { + Task task = new Task(); + + assertNull(task.getId()); + assertNull(task.getTaskName()); + assertNull(task.getTaskType()); + assertNull(task.getTaskStatus()); + assertNull(task.getTaskMessage()); + assertNull(task.getTaskParam()); + assertNull(task.getTaskStartTime()); + assertNull(task.getTaskEndTime()); + assertNull(task.getTaskErrorMessage()); + assertEquals(0, task.getIsExclusive()); + } + + @Test + public void testTaskConstructorWithNonExclusive() { + Task task = new Task(TASK_NAME, TASK_TYPE, TASK_STATUS, TASK_MESSAGE, TASK_PARAM); + + assertEquals(null, task.getId()); + assertEquals(TASK_NAME, task.getTaskName()); + assertEquals(TASK_TYPE, task.getTaskType()); + assertEquals(TASK_STATUS, task.getTaskStatus()); + assertEquals(TASK_MESSAGE, task.getTaskMessage()); + assertEquals(TASK_PARAM, task.getTaskParam()); + assertNull(task.getTaskStartTime()); + assertNull(task.getTaskEndTime()); + assertNull(task.getTaskErrorMessage()); + assertEquals(NON_EXCLUSIVE, task.getIsExclusive()); + } + + @Test + public void testTaskConstructorWithExclusive() { + Task task = new Task(TASK_NAME, TASK_TYPE, TASK_STATUS, TASK_MESSAGE, TASK_PARAM, EXCLUSIVE); + + assertEquals(null, task.getId()); + assertEquals(TASK_NAME, task.getTaskName()); + assertEquals(TASK_TYPE, task.getTaskType()); + assertEquals(TASK_STATUS, task.getTaskStatus()); + assertEquals(TASK_MESSAGE, task.getTaskMessage()); + assertEquals(TASK_PARAM, task.getTaskParam()); + assertNull(task.getTaskStartTime()); + assertNull(task.getTaskEndTime()); + assertNull(task.getTaskErrorMessage()); + assertEquals(EXCLUSIVE, task.getIsExclusive()); + } + + @Test + public void testToString() { + Task task = new Task(TASK_NAME, TASK_TYPE, TASK_STATUS, TASK_MESSAGE, TASK_PARAM); + task.setId(123); + task.setTaskStartTime(LocalDateTime.of(2025, 8, 25, 13, 30)); + + String toString = task.toString(); + + assertTrue(toString.contains("id=123")); + assertTrue(toString.contains("taskName=test-task")); + assertTrue(toString.contains("taskType=test-type")); + assertTrue(toString.contains("taskStatus=1")); + assertTrue(toString.contains("taskMessage=Task is in queue")); + assertTrue(toString.contains("taskParam={\"key\": \"value\"}")); + assertTrue(toString.contains("taskStartTime=2025-08-25T13:30")); + } +} -- Gitee