houzhongyi
2024-07-11 e7c1260db32209a078a962aaa0ad5492c35774fb
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
package com.iailab.module.bpm.framework.flowable.core.candidate.strategy;
 
import com.iailab.framework.test.core.ut.BaseMockitoUnitTest;
import com.iailab.module.bpm.dal.dataobject.definition.BpmUserGroupDO;
import com.iailab.module.bpm.service.definition.BpmUserGroupService;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
 
import java.util.Arrays;
import java.util.Set;
 
import static com.iailab.framework.common.util.collection.SetUtils.asSet;
import static com.iailab.framework.test.core.util.RandomUtils.randomPojo;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;
 
public class BpmTaskCandidateGroupStrategyTest extends BaseMockitoUnitTest {
 
    @InjectMocks
    private BpmTaskCandidateGroupStrategy strategy;
 
    @Mock
    private BpmUserGroupService userGroupService;
 
    @Test
    public void testCalculateUsers() {
        // 准备参数
        String param = "1,2";
        // mock 方法
        BpmUserGroupDO userGroup1 = randomPojo(BpmUserGroupDO.class, o -> o.setUserIds(asSet(11L, 12L)));
        BpmUserGroupDO userGroup2 = randomPojo(BpmUserGroupDO.class, o -> o.setUserIds(asSet(21L, 22L)));
        when(userGroupService.getUserGroupList(eq(asSet(1L, 2L)))).thenReturn(Arrays.asList(userGroup1, userGroup2));
 
        // 调用
        Set<Long> results = strategy.calculateUsers(null, param);
        // 断言
        assertEquals(asSet(11L, 12L, 21L, 22L), results);
    }
 
}