#
Junjie
12 小时以前 cbb00d4729243e4949b3c921fc2f94cb03ca8aaa
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
package com.zy.core.thread.impl;
 
import com.zy.asrs.entity.DeviceConfig;
import com.zy.common.utils.RedisUtil;
import com.zy.core.model.protocol.StationProtocol;
import com.zy.core.model.protocol.StationTaskBufferItem;
import com.zy.core.network.ZyStationConnectDriver;
import org.junit.jupiter.api.Test;
import org.springframework.test.util.ReflectionTestUtils;
 
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
 
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
 
class ZyStationV5ThreadTest {
 
    @Test
    void clearPath_delegatesPureSlotClearingToDriver() {
        DeviceConfig deviceConfig = new DeviceConfig();
        deviceConfig.setDeviceNo(1);
        RedisUtil redisUtil = mock(RedisUtil.class);
        ZyStationConnectDriver connectDriver = mock(ZyStationConnectDriver.class);
        when(connectDriver.clearTaskBufferSlot(10, 2)).thenReturn(true);
 
        ZyStationV5Thread thread = new ZyStationV5Thread(deviceConfig, redisUtil);
        ReflectionTestUtils.setField(thread, "zyStationConnectDriver", connectDriver);
 
        StationTaskBufferItem hitItem = new StationTaskBufferItem();
        hitItem.setSlotIdx(2);
        hitItem.setTaskNo(100);
        hitItem.setTargetStaNo(88);
 
        StationProtocol station20 = new StationProtocol();
        station20.setStationId(20);
        station20.setTaskBufferItems(Collections.emptyList());
 
        StationProtocol station10 = new StationProtocol();
        station10.setStationId(10);
        station10.setTaskBufferItems(List.of(hitItem));
 
        ReflectionTestUtils.setField(thread, "statusList", Arrays.asList(station20, station10));
 
        boolean result = thread.clearPath(100);
 
        assertTrue(result);
        verify(connectDriver).clearTaskBufferSlot(eq(10), eq(2));
        verify(redisUtil, never()).set(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.any(), org.mockito.ArgumentMatchers.anyLong());
        verify(redisUtil, never()).del(org.mockito.ArgumentMatchers.any(String[].class));
        assertEquals(0, hitItem.getTaskNo());
        assertEquals(0, hitItem.getTargetStaNo());
    }
}