刘光辉
3 小时以前 06f314545ac3514d7ce28939920866ae8188d31c
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
package jnpf.dmsService;
 
import jnpf.dmsEntity.fenfa.DmsWenjianDayinRenwuEntity;
import jnpf.dmsEntity.fenfa.vo.DmsWenjianHuishouMingxiVO;
import jnpf.dmsMapper.DmsWenjianFenfaMapper;
import jnpf.exception.DataException;
import org.junit.jupiter.api.Test;
import org.mockito.InOrder;
import java.util.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
 
class DmsWenjianHuishouPolicyTest {
    @Test void unsignedCopiesNeedEvidenceAndProcessedCopiesCannotReenter() throws Exception {
        DmsWenjianHuishouMingxiVO copy = new DmsWenjianHuishouMingxiVO();
        for (String status : Arrays.asList("daifafang", "daiqianshou")) {
            copy.setBizStatus(status);
            copy.setEarlyRecycleEligible(false);
            assertThrows(DataException.class, () -> DmsWenjianHuishouPolicy.requireEligible(copy));
            copy.setEarlyRecycleEligible(true);
            DmsWenjianHuishouPolicy.requireEligible(copy);
        }
        for (String status : Arrays.asList("yizuofei", "daiguidang", "daixiaohui", "yixiaohui", "yiguidang")) {
            copy.setBizStatus(status);
            assertThrows(DataException.class, () -> DmsWenjianHuishouPolicy.requireEligible(copy));
        }
        copy.setBizStatus("daihuishou");
        copy.setEarlyRecycleEligible(false);
        DmsWenjianHuishouPolicy.requireEligible(copy);
    }
    @Test void completionLocksDistinctTasksInStableOrder() throws Exception {
        DmsWenjianFenfaMapper mapper = mock(DmsWenjianFenfaMapper.class);
        List<DmsWenjianHuishouMingxiVO> copies = new ArrayList<>();
        for (String task : Arrays.asList("b", "a", "b")) {
            DmsWenjianHuishouMingxiVO copy = new DmsWenjianHuishouMingxiVO();
            copy.setDayinRenwuId(task);
            copy.setEarlyRecycleEligible(true);
            copies.add(copy);
        }
        when(mapper.selectPrintTaskForUpdate("tenant", "a")).thenReturn(new DmsWenjianDayinRenwuEntity());
        when(mapper.selectPrintTaskForUpdate("tenant", "b")).thenReturn(new DmsWenjianDayinRenwuEntity());
        Date now = new Date();
        DmsWenjianHuishouPolicy.completeDistributions(mapper, "tenant", copies, "user", now);
        InOrder order = inOrder(mapper);
        order.verify(mapper).selectPrintTaskForUpdate("tenant", "a");
        order.verify(mapper).completeDistributionAfterRecycle("tenant", "a", "user", now);
        order.verify(mapper).selectPrintTaskForUpdate("tenant", "b");
        order.verify(mapper).completeDistributionAfterRecycle("tenant", "b", "user", now);
        order.verifyNoMoreInteractions();
    }
}