2026-06-24 f4bd1f3c89d906131495a0aca5aaf82966378510
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.strategy.other;
 
import cn.hutool.core.collection.ListUtil;
import cn.iocoder.yudao.framework.common.util.collection.SetUtils;
import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest;
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmProcessDefinitionInfoDO;
import cn.iocoder.yudao.module.bpm.enums.definition.BpmUserTaskAssignEmptyHandlerTypeEnum;
import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils;
import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils;
import cn.iocoder.yudao.module.bpm.service.definition.BpmProcessDefinitionService;
import org.flowable.bpmn.model.BpmnModel;
import org.flowable.bpmn.model.FlowElement;
import org.flowable.engine.delegate.DelegateExecution;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockedStatic;
 
import java.util.Set;
 
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomString;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.*;
 
public class BpmTaskCandidateAssignEmptyStrategyTest extends BaseMockitoUnitTest {
 
    @InjectMocks
    private BpmTaskCandidateAssignEmptyStrategy strategy;
 
    @Mock
    private BpmProcessDefinitionService processDefinitionService;
 
    @Test
    public void testCalculateUsersByTask() {
        try (MockedStatic<FlowableUtils> flowableUtilMockedStatic = mockStatic(FlowableUtils.class);
             MockedStatic<BpmnModelUtils> bpmnModelUtilsMockedStatic = mockStatic(BpmnModelUtils.class)) {
            // 准备参数
            DelegateExecution execution = mock(DelegateExecution.class);
            String param = randomString();
            // mock 方法(execution)
            String processDefinitionId = randomString();
            when(execution.getProcessDefinitionId()).thenReturn(processDefinitionId);
            FlowElement flowElement = mock(FlowElement.class);
            when(execution.getCurrentFlowElement()).thenReturn(flowElement);
            // mock 方法(parseAssignEmptyHandlerType)
            bpmnModelUtilsMockedStatic.when(() -> BpmnModelUtils.parseAssignEmptyHandlerType(same(flowElement)))
                    .thenReturn(BpmUserTaskAssignEmptyHandlerTypeEnum.ASSIGN_USER.getType());
            bpmnModelUtilsMockedStatic.when(() -> BpmnModelUtils.parseAssignEmptyHandlerUserIds(same(flowElement)))
                    .thenReturn(ListUtil.of(1L, 2L));
 
            // 调用
            Set<Long> userIds = strategy.calculateUsersByTask(execution, param);
            // 断言
            assertEquals(SetUtils.asSet(1L, 2L), userIds);
        }
 
    }
 
    @Test
    public void testCalculateUsersByActivity() {
        try (MockedStatic<BpmnModelUtils> bpmnModelUtilsMockedStatic = mockStatic(BpmnModelUtils.class)) {
            // 准备参数
            String processDefinitionId = randomString();
            String activityId = randomString();
            String param = randomString();
            // mock 方法(getFlowElementById)
            FlowElement flowElement = mock(FlowElement.class);
            BpmnModel bpmnModel = mock(BpmnModel.class);
            bpmnModelUtilsMockedStatic.when(() -> BpmnModelUtils.getFlowElementById(same(bpmnModel), eq(activityId)))
                    .thenReturn(flowElement);
            // mock 方法(parseAssignEmptyHandlerType)
            bpmnModelUtilsMockedStatic.when(() -> BpmnModelUtils.parseAssignEmptyHandlerType(same(flowElement)))
                 .thenReturn(BpmUserTaskAssignEmptyHandlerTypeEnum.ASSIGN_ADMIN.getType());
            // mock 方法(getProcessDefinitionInfo)
            BpmProcessDefinitionInfoDO processDefinition = randomPojo(BpmProcessDefinitionInfoDO.class,
                    o -> o.setManagerUserIds(ListUtil.of(1L, 2L)));
            when(processDefinitionService.getProcessDefinitionInfo(eq(processDefinitionId))).thenReturn(processDefinition);
 
            // 调用
            Set<Long> userIds = strategy.calculateUsersByActivity(bpmnModel, activityId, param,
                    null, processDefinitionId, null);
            // 断言
            assertEquals(SetUtils.asSet(1L, 2L), userIds);
        }
    }
 
}