刘光辉
4 小时以前 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
package jnpf.dmsService;
import jnpf.dmsEntity.fenfa.DmsWenjianChongdaFasong;
import jnpf.dmsEntity.fenfa.form.DmsWenjianChongdaForm;
import jnpf.dmsEntity.preview.vo.DmsFilePageCountVO;
import jnpf.exception.DataException;
import org.junit.jupiter.api.Test;
import java.util.UUID;
import java.io.IOException;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
class DmsWenjianChongdaPlanServiceTest {
    final DmsWenjianChongdaService reprints=mock(DmsWenjianChongdaService.class);
    final DmsFilePageCountService pages=mock(DmsFilePageCountService.class);
    final DmsWenjianChongdaPlanService service=new DmsWenjianChongdaPlanService(reprints,pages);
    final DmsWenjianChongdaForm form=new DmsWenjianChongdaForm();
    DmsWenjianChongdaFasong open() throws Exception {
        var a=new DmsWenjianChongdaFasong();a.setState("OPEN");a.setFileVersionId(UUID.randomUUID().toString());
        when(reprints.status(form)).thenReturn(a);return a;
    }
    @Test void countsFrozenVersionBeforeLockedPlanValidation() throws Exception {
        var a=open();var result=new DmsFilePageCountVO();result.setFileVersionId(UUID.fromString(a.getFileVersionId()));result.setPageCount(12);
        when(pages.getPageCount(result.getFileVersionId())).thenReturn(result);when(reprints.plan(form,a.getFileVersionId(),12)).thenReturn(a);
        assertSame(a,service.plan(form));var order=inOrder(reprints,pages);
        order.verify(reprints).status(form);order.verify(pages).getPageCount(result.getFileVersionId());order.verify(reprints).plan(form,a.getFileVersionId(),12);
    }
    @Test void existingPlanAndTerminalStateDoNotRecount() throws Exception {
        var a=open();a.setPageCount(2);assertSame(a,service.plan(form));a.setPageCount(null);a.setState("CANCELLED");assertSame(a,service.plan(form));verifyNoInteractions(pages);
    }
    @Test void mismatchedVersionCannotPersistPlan() throws Exception {
        var a=open();var result=new DmsFilePageCountVO();result.setFileVersionId(UUID.randomUUID());result.setPageCount(2);
        when(pages.getPageCount(UUID.fromString(a.getFileVersionId()))).thenReturn(result);
        assertThrows(DataException.class,()->service.plan(form));verify(reprints,never()).plan(any(),anyString(),anyInt());
    }
    @Test void conversionFailurePreservesOriginalAttempt() throws Exception {
        var a=open();when(pages.getPageCount(UUID.fromString(a.getFileVersionId()))).thenThrow(new IOException("offline"));
        assertThrows(DataException.class,()->service.plan(form));verify(reprints,never()).plan(any(),anyString(),anyInt());
    }
}