自动化立体仓库 - WMS系统
zwl
2 天以前 8728a2be61d93b538599e634bba9eaad5ad1a969
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
package com.zy.asrs.service.impl;
 
import com.zy.asrs.entity.BasCrnp;
import com.zy.asrs.mapper.BasCrnpMapper;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.util.ReflectionTestUtils;
 
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.when;
 
@ExtendWith(MockitoExtension.class)
class BasCrnpServiceImplTest {
 
    @Mock
    private BasCrnpMapper basCrnpMapper;
 
    private BasCrnpServiceImpl service;
 
    @BeforeEach
    void setUp() {
        service = new BasCrnpServiceImpl();
        ReflectionTestUtils.setField(service, "baseMapper", basCrnpMapper);
    }
 
    @Test
    void checkSiteError_shouldRejectNullInboundFlag() {
        BasCrnp basCrnp = buildCrnp(null, "Y");
        when(basCrnpMapper.selectById(22)).thenReturn(basCrnp);
 
        assertFalse(service.checkSiteError(22, true));
    }
 
    @Test
    void checkSiteError_shouldAllowExplicitInboundFlagY() {
        BasCrnp basCrnp = buildCrnp("Y", "Y");
        when(basCrnpMapper.selectById(22)).thenReturn(basCrnp);
 
        assertTrue(service.checkSiteError(22, true));
    }
 
    @Test
    void checkSiteStatus_shouldRejectNullInboundFlag() {
        BasCrnp basCrnp = buildCrnp(null, "Y");
        when(basCrnpMapper.selectById(22)).thenReturn(basCrnp);
 
        assertThrows(RuntimeException.class, () -> service.checkSiteStatus(22));
    }
 
    private BasCrnp buildCrnp(String inEnable, String outEnable) {
        BasCrnp basCrnp = new BasCrnp();
        basCrnp.setCrnNo(22);
        basCrnp.setCrnSts(3);
        basCrnp.setCrnErr(0L);
        basCrnp.setInEnable(inEnable);
        basCrnp.setOutEnable(outEnable);
        return basCrnp;
    }
}